华为鸿蒙操作系统学习(2):在Linux上面使用Docker构建鸿蒙code代码,搭建Dockerfile环境,并跑通构建代码Hi3516,但是使用同样的镜像构建Hi3581,构建失败。

目录

  • 前言
  • 1,关于鸿蒙系统
  • 2,根据文档编写Dockerfile
  • 3,使用镜像构建第一个程序Hi3516
  • 4,构建另外一个程序Hi3861
  • 5,总结

前言


本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/108621002

【鸿蒙系统分类】:
http://blog.csdn.net/freewebsys/article/category/10390587

【gitee项目地址】:
https://gitee.com/studyharmony/linux-build

未经博主允许不得转载。
博主地址是:http://blog.csdn.net/freewebsys

1,关于鸿蒙系统


OpenHarmony是开放原子开源基金会(OpenAtom Foundation)旗下开源项目,定位是一款面向全场景的开源分布式操作系统。
OpenHarmony在传统的单设备系统能力的基础上,创造性地提出了基于同一套系统能力、适配多种终端形态的理念,支持多种终端设备上运行,第一个版本支持128K-128M设备上运行,欢迎参加开源社区一起持续演进。
针对设备开发者,OpenHarmony采用了组件化的设计方案,可以根据设备的资源能力和业务特征进行灵活裁剪,满足不同形态的终端设备对于操作系统的要求。可运行在百K级别的资源受限设备和穿戴类设备,也可运行在百M级别的智能家用摄像头/行车记录仪等相对资源丰富的设备。

2,根据文档编写Dockerfile


环境搭建是第一步。
我觉得应该给个官方的Dockerfile,这样直接下载镜像得了。

https://gitee.com/studyharmony/linux-build/blob/master/Dockerfile

# 构建命令:
# docker build -t openharmony:dev . 

#使用 ubuntu:18.04 做基础镜像减少大小。
# 然后安装构建鸿蒙系统需要的软件
 
FROM docker.io/ubuntu:18.04

# https://developer.aliyun.com/mirror/
# https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b115c0SRA

# 使用阿里云镜像地址。修改debian apt 更新地址,pip 地址,设置时区。
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse\n\
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse\n\
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse\n\
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse\n\
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse\n\
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse\n" > /etc/apt/sources.list && \
echo "[global]\n\
trusted-host=mirrors.aliyun.com\n\
index-url=http://mirrors.aliyun.com/pypi/simple" > /etc/pip.conf && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone

# 按照官方的方法继续软件安装:
# https://openharmony.gitee.com/openharmony/docs/blob/master/quick-start/%E6%90%AD%E5%BB%BA%E7%8E%AF%E5%A2%83-0.md

# 将Linux shell改为bash 
RUN apt update &&  apt-get install -y curl && rm -rf /bin/sh && ln -s /bin/bash /bin/sh

# 这个是很少变的,放到前面
# 安装gn && 安装ninja && 安装LLVM编译工具链 && 安装hc-gen

RUN cd /opt && curl -O https://repo.huaweicloud.com/harmonyos/compiler/gn/1523/linux/gn.1523.tar && \
    tar -xf gn.1523.tar -C /opt/ && rm -f gn.1523.tar

RUN cd /opt && curl -O https://repo.huaweicloud.com/harmonyos/compiler/ninja/1.9.0/linux/ninja.1.9.0.tar && \
    tar -xf ninja.1.9.0.tar -C /opt/ && rm -f ninja.1.9.0.tar

# 724M 这个好大,每次都要下载好一会
RUN cd /opt && curl -O https://repo.huaweicloud.com/harmonyos/compiler/clang/9.0.0-34042/linux/llvm-linux-9.0.0-34042.tar && \
    tar -xf llvm-linux-9.0.0-34042.tar -C /opt/ && rm -f llvm-linux-9.0.0-34042.tar

RUN cd /opt && curl -O https://repo.huaweicloud.com/harmonyos/compiler/hc-gen/0.65/linux/hc-gen-0.65-linux.tar && \
    tar -xf hc-gen-0.65-linux.tar -C /opt/ && rm -f hc-gen-0.65-linux.tar

#安装gcc_riscv32 109M。
RUN cd /opt && curl -O https://repo.huaweicloud.com/harmonyos/compiler/gcc_riscv32/7.3.0/linux/gcc_riscv32-linux-7.3.0.tar.gz && \
    tar -xf gcc_riscv32-linux-7.3.0.tar.gz -C /opt/ && rm -f gcc_riscv32-linux-7.3.0.tar.gz

#增加语言utf-8
ENV LANG=zh_CN.UTF-8
ENV LC_CTYPE=zh_CN.UTF-8

# llvm 和其他路径不一样。
RUN echo "export PATH=/opt/gn:/opt/ninja:/opt/llvm/bin:/opt/hc-gen:/opt/gcc_riscv32/bin:$PATH" >> /root/.bashrc 

# 安装Python环境
RUN apt-get install -y python3.8 python3-pip dosfstools scons mtools zip && \
    pip3 install setuptools kconfiglib pycryptodome six ecdsa && \
    rm -f /usr/bin/python && ln -s /usr/bin/python3.8 /usr/bin/python


# 使用: 
# mkdir -p data && docker run -it -v $PWD/data:/data openharmony:dev bash

然后构建一个docker镜像:

docker build -t openharmony:dev .

3,使用镜像构建第一个程序Hi3516


没有设备,就研究烧录了。

参考
https://openharmony.gitee.com/openharmony/docs/blob/master/quick-start/%E5%BC%80%E5%8F%91Hi3516%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E7%A4%BA%E4%BE%8B.md

镜像可以多次使用,映射一个本地data 文件夹:

mkdir -p data && docker run -it -v $PWD/data:/data openharmony:dev bash

进镜像之后

cd /data
mkdir code-hi3516
cd code-hi3516
curl -O https://repo.huaweicloud.com/harmonyos/os/1.0/code-1.0.tar.gz
tar -zxvf code-1.0.tar.gz

# 直接执行 即可:
python build.py ipcamera_hi3516dv300 -b debug

最后显示构建成功,省略中间好多步。

conformance/interfaces/timer_settime/8-3 compile PASSED
conformance/interfaces/timer_settime/9-2 compile PASSED
conformance/interfaces/timer_settime/5-3 compile PASSED
../../../conformance/interfaces/timer_settime/5-1.c:92:6: warning: absolute value function 'labs' given an argument of type 'long long' but has parameter of type 'long' which may cause truncation of value [-Wabsolute-value]
        if (labs(tsleft.tv_sec - SLEEPDELTA) <= ACCEPTABLEDELTA) {
     
            ^
../../../conformance/interfaces/timer_settime/5-1.c:92:6: note: use function 'llabs' instead
        if (labs(tsleft.tv_sec - SLEEPDELTA) <= ACCEPTABLEDELTA) {
     
            ^~~~
            llabs
1 warning generated.
conformance/interfaces/timer_settime/5-1 compile PASSED
conformance/interfaces/timer_settime/3-3 compile PASSED
conformance/interfaces/timer_settime/3-1 compile PASSED
conformance/interfaces/timer_settime/3-2 compile PASSED
conformance/interfaces/timer_settime/5-2 compile PASSED
conformance/interfaces/timer_settime/8-4 compile PASSED
conformance/interfaces/timer_settime/13-1 compile PASSED
make[2]: Entering directory '/data/code-hi3561/third_party/ltp/testcases/open_posix_testsuite/conformance/interfaces/timer_settime/speculative'
conformance/interfaces/timer_settime/speculative/12-1 compile PASSED
conformance/interfaces/timer_settime/speculative/12-3 compile PASSED
conformance/interfaces/timer_settime/speculative/12-2 compile PASSED
make[2]: Leaving directory '/data/code-hi3561/third_party/ltp/testcases/open_posix_testsuite/conformance/interfaces/timer_settime/speculative'
make[1]: Leaving directory '/data/code-hi3561/third_party/ltp/testcases/open_posix_testsuite/conformance/interfaces/timer_settime'
make: Leaving directory '/data/code-hi3561/third_party/ltp/testcases/open_posix_testsuite/conformance/interfaces'
[1328/1338] STAMP obj/test/xts/acts/open_posix_testsuite/conformance/interfaces/prebuild_ActsOpenPosixTest.stamp
[1329/1338] ACTION //test/xts/acts/open_posix_testsuite/conformance/interfaces:ActsOpenPosixTest(//build/lite/toolchain:linux_x86_64_clang)
[1330/1338] STAMP obj/test/xts/acts/open_posix_testsuite/conformance/interfaces/ActsOpenPosixTest.stamp
[1331/1338] STAMP obj/test/xts/acts/acts_compoment.stamp
[1332/1338] COPY bin/query.bin suites/acts/resource/tools/query.bin
[1333/1338] STAMP obj/test/xts/acts/query_copy.stamp
[1334/1338] ACTION //test/xts/acts:acts(//build/lite/toolchain:linux_x86_64_clang)
[1335/1338] STAMP obj/test/xts/acts/acts.stamp
[1336/1338] STAMP obj/build/lite/ohos.stamp
[1337/1338] ACTION //build/lite:gen_rootfs(//build/lite/toolchain:linux_x86_64_clang)
[1338/1338] STAMP obj/build/lite/gen_rootfs.stamp
ohos ipcamera_hi3516dv300 build success!

4,构建另外一个程序Hi3861


和第一个类似,但是下载了代码之后执行编译:

  python build.py wifiiot

报错如下,看来和Hi3516 的项目构建的东西还是不一样的。

[196/197] ACTION //vendor/hisi/hi3861/hi3861:run_wifiiot_scons(//build/lite/toolchain:linux_x86_64_riscv32_gcc)
FAILED: obj/vendor/hisi/hi3861/hi3861/run_wifiiot_scons_build_ext_components.txt 
python ../../build/lite/build_ext_components.py --path=../../vendor/hisi/hi3861/hi3861 --command=sh\ hm_build.sh
/usr/lib/scons/SCons/Defaults.py:213: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  if len(operation_list) is not 2:
/data/code-hi3861/vendor/hisi/hi3861/hi3861/build/scripts/hi_config_parser.py:85: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if option is '':
/usr/lib/python3/dist-packages/Crypto/Random/Fortuna/FortunaGenerator.py:28: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if sys.version_info[0] is 2 and  sys.version_info[1] is 1:
/usr/lib/python3/dist-packages/Crypto/Random/Fortuna/FortunaGenerator.py:28: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if sys.version_info[0] is 2 and  sys.version_info[1] is 1:
Traceback (most recent call last):
  File "/usr/lib/scons/SCons/Script/Main.py", line 1376, in main
    _exec_main(parser, values)
  File "/usr/lib/scons/SCons/Script/Main.py", line 1339, in _exec_main
    _main(parser)
  File "/usr/lib/scons/SCons/Script/Main.py", line 1006, in _main
    SCons.Script._SConscript._SConscript(fs, script)
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 255, in _SConscript
    exec(compile(_file_.read(), _file_.name, 'exec'),
  File "/data/code-hi3861/vendor/hisi/hi3861/hi3861/SConstruct", line 34, in <module>
    from scripts import pkt_builder
  File "/data/code-hi3861/vendor/hisi/hi3861/hi3861/build/scripts/pkt_builder.py", line 24, in <module>
    import make_upg_file as MAKE_IMAGE
  File "/data/code-hi3861/vendor/hisi/hi3861/hi3861/build/scripts/make_upg_file.py", line 30, in <module>
    from Crypto.PublicKey import RSA
  File "/usr/lib/python3/dist-packages/Crypto/PublicKey/RSA.py", line 78, in <module>
    from Crypto import Random
  File "/usr/lib/python3/dist-packages/Crypto/Random/__init__.py", line 29, in <module>
    from Crypto.Random import _UserFriendlyRNG
  File "/usr/lib/python3/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in <module>
    from Crypto.Random.Fortuna import FortunaAccumulator
  File "/usr/lib/python3/dist-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in <module>
    from . import FortunaGenerator
  File "/usr/lib/python3/dist-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 35, in <module>
    from Crypto.Util import Counter
  File "/usr/lib/python3/dist-packages/Crypto/Util/Counter.py", line 59, in <module>
    from Crypto.Util import _counter
ImportError: cannot import name '_counter' from 'Crypto.Util' (/usr/lib/python3/dist-packages/Crypto/Util/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/scons", line 201, in <module>
    SCons.Script.main()
  File "/usr/lib/scons/SCons/Script/Main.py", line 1401, in main
    SCons.Script._SConscript.SConscript_exception()
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 319, in SConscript_exception
    stack = traceback.extract_tb(tb)
  File "/usr/lib/python3.8/traceback.py", line 72, in extract_tb
    return StackSummary.extract(walk_tb(tb), limit=limit)
  File "/usr/lib/python3.8/traceback.py", line 366, in extract
    f.line
  File "/usr/lib/python3.8/traceback.py", line 288, in line
    self._line = linecache.getline(self.filename, self.lineno).strip()
  File "/usr/lib/python3.8/linecache.py", line 16, in getline
    lines = getlines(filename, module_globals)
  File "/usr/lib/python3.8/linecache.py", line 47, in getlines
    return updatecache(filename, module_globals)
  File "/usr/lib/python3.8/linecache.py", line 137, in updatecache
    lines = fp.readlines()
  File "/usr/lib/python3.8/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xca in position 699: invalid continuation byte
Traceback (most recent call last):
  File "../../build/lite/build_ext_components.py", line 64, in 
    sys.exit(main())
  File "../../build/lite/build_ext_components.py", line 58, in main
    cmd_exec(args.command)
  File "../../build/lite/build_ext_components.py", line 32, in cmd_exec
    raise Exception("{} failed, return code is {}".format(cmd, ret_code))
Exception: ['sh', 'hm_build.sh'] failed, return code is 1
ninja: build stopped: subcommand failed.
you can check build log in /data/code-hi3861/out/wifiiot/build.log

5,总结


使用Docker镜像的方式,能最少的建设不同设备搭建环境的差异。
但是只成功构建了 Hi3516,没有构建成功 Hi3861 的Demo。
而且,我也没有设备。能成功构建,Demo 肯定可以烧录进去。
下面的就不研究了。接着开始看看相关的代码啦。

本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/108621002

博主地址是:https://blog.csdn.net/freewebsys

你可能感兴趣的:(鸿蒙操作系统,开源,鸿蒙系统)