前言:

安装交叉编译环境,繁琐,耗时间,还得解决ubuntu版本不同,导致的各种错误。docker很好的解决了,不同版本,不同系统之间的差异性的问题。DOPI制作了docker方式的交叉编译环境。

工作环境:

     vmare安装的ubuntu18.04 amd64版本
dopi@ubuntu:~$ cat /proc/version
Linux version 5.3.0-62-generic (buildd@lcy01-amd64-004) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #56~18.04.1-Ubuntu SMP Wed Jun 24 16:17:03 UTC 2020

安装docker

sudo chmod 777 /etc/apt/sources.list
vi /etc/apt/sources.list

从源中选择对应版本的更新源:复制到 source.list 中。

  • 卸载老版本:
 sudo apt-get remove docker docker-engine docker.io containerd runc
  • 安装docker
 sudo apt-get install -y curl
 curl https://releases.rancher.com/install-docker/18.09.sh | sh

执行过程:

dopi@ubuntu:$ curl https://releases.rancher.com/install-docker/18.09.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15521  100 15521    0     0  16406      0 --:--:-- --:--:-- --:--:-- 16389
Warning: the "docker" command appears to already exist on this system.

If you already have Docker installed, this script can cause trouble, which is
why we're displaying this warning and provide the opportunity to cancel the
installation.

If you installed the current Docker package using this script and are using it
again to update Docker, you can safely ignore this message.

You may press Ctrl+C now to abort this script.
+ sleep 20
+ sudo -E sh -c apt-get update
Hit:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic InRelease
Get:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates InRelease [88.7 kB]                                                                             
Get:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-backports InRelease [74.6 kB]                                                                           
Get:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-security InRelease [88.7 kB]                                                                          
Hit:5 http://us.archive.ubuntu.com/ubuntu bionic InRelease                                                                                                     
Get:6 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]                                                                                    
Get:7 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]                                                             
Hit:8 https://download.docker.com/linux/ubuntu bionic InRelease                            
Get:9 http://security.ubuntu.com/ubuntu bionic-security/main amd64 DEP-11 Metadata [46.0 kB]    
Get:10 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 DEP-11 Metadata [49.2 kB]
Get:11 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 DEP-11 Metadata [2,464 B]
Get:12 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:13 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 DEP-11 Metadata [295 kB]
Get:14 http://us.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 DEP-11 Metadata [279 kB]                                                                
Get:15 http://us.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 DEP-11 Metadata [2,468 B]                                                             
Get:16 http://us.archive.ubuntu.com/ubuntu bionic-backports/universe amd64 DEP-11 Metadata [7,968 B]                                                             
Fetched 1,186 kB in 17s (69.0 kB/s)                                                                                                                              
Reading package lists... Done
+ sudo -E sh -c apt-get install -y -q apt-transport-https ca-certificates curl software-properties-common
Reading package lists...
Building dependency tree...
Reading state information...
ca-certificates is already the newest version (20190110~18.04.1).
curl is already the newest version (7.58.0-2ubuntu3.9).
software-properties-common is already the newest version (0.96.24.32.13).
apt-transport-https is already the newest version (1.6.12ubuntu0.1).
0 upgraded, 0 newly installed, 0 to remove and 94 not upgraded.
+ + sudo -E sh -c apt-key add -
curl -fsSl https://download.docker.com/linux/ubuntu/gpg
OK
+ sudo -E sh -c add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
Hit:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic InRelease
Get:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates InRelease [88.7 kB]                                                                             
Get:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-backports InRelease [74.6 kB]                                                                           
Hit:4 http://us.archive.ubuntu.com/ubuntu bionic InRelease                                                                                                     
Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease                                                                                              
Get:6 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-security InRelease [88.7 kB]                                                                          
Hit:7 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease                                                                       
Hit:8 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease                                   
Hit:9 https://download.docker.com/linux/ubuntu bionic InRelease                                        
Fetched 252 kB in 1s (179 kB/s)
Reading package lists... Done
+ [ ubuntu = debian ]
+ sudo -E sh -c apt-get update
Hit:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic InRelease
Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease                                                                                  
Hit:3 http://us.archive.ubuntu.com/ubuntu bionic InRelease                                                                    
Get:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates InRelease [88.7 kB]                                          
Hit:5 https://download.docker.com/linux/ubuntu bionic InRelease                 
Hit:6 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease                   
Hit:7 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease                 
Get:8 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-backports InRelease [74.6 kB]
Get:9 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-security InRelease [88.7 kB]
Fetched 252 kB in 2s (116 kB/s)     
Reading package lists... Done
+ apt-cache madison docker-ce
+ cut+ grep 18.09.9
 -d   -f 4
+ head -n 1
+ pkg_version=5:18.09.9~3-0~ubuntu-bionic
+ sudo -E sh -c apt-get install -y -q docker-ce=5:18.09.9~3-0~ubuntu-bionic docker-ce-cli=5:18.09.9~3-0~ubuntu-bionic
Reading package lists...
Building dependency tree...
Reading state information...
docker-ce-cli is already the newest version (5:18.09.9~3-0~ubuntu-bionic).
The following additional packages will be installed:
  aufs-tools cgroupfs-mount containerd.io pigz
The following NEW packages will be installed:
  aufs-tools cgroupfs-mount containerd.io docker-ce pigz
0 upgraded, 5 newly installed, 0 to remove and 93 not upgraded.
Need to get 0 B/41.6 MB of archives.
After this operation, 194 MB of additional disk space will be used.
Selecting previously unselected package pigz.
(Reading database ... 175687 files and directories currently installed.)
Preparing to unpack .../archives/pigz_2.4-1_amd64.deb ...
Unpacking pigz (2.4-1) ...
Selecting previously unselected package aufs-tools.
Preparing to unpack .../aufs-tools_1%3a4.9+20170918-1ubuntu1_amd64.deb ...
Unpacking aufs-tools (1:4.9+20170918-1ubuntu1) ...
Selecting previously unselected package cgroupfs-mount.
Preparing to unpack .../cgroupfs-mount_1.4_all.deb ...
Unpacking cgroupfs-mount (1.4) ...
Selecting previously unselected package containerd.io.
Preparing to unpack .../containerd.io_1.2.13-2_amd64.deb ...
Unpacking containerd.io (1.2.13-2) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../docker-ce_5%3a18.09.9~3-0~ubuntu-bionic_amd64.deb ...
Unpacking docker-ce (5:18.09.9~3-0~ubuntu-bionic) ...
Setting up aufs-tools (1:4.9+20170918-1ubuntu1) ...
Setting up containerd.io (1.2.13-2) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up cgroupfs-mount (1.4) ...
Setting up pigz (2.4-1) ...
Setting up docker-ce (5:18.09.9~3-0~ubuntu-bionic) ...
update-alternatives: using /usr/bin/dockerd-ce to provide /usr/bin/dockerd (dockerd) in auto mode
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for systemd (237-3ubuntu10.38) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
+ sudo -E sh -c docker version
Client:
 Version:           18.09.9
 API version:       1.39
 Go version:        go1.11.13
 Git commit:        039a7df9ba
 Built:             Wed Sep  4 16:57:28 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.9
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.11.13
  Git commit:       039a7df
  Built:            Wed Sep  4 16:19:38 2019
  OS/Arch:          linux/amd64
  Experimental:     false

If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

  sudo usermod -aG docker dopi

Remember that you will have to log out and back in for this to take effect!

WARNING: Adding a user to the "docker" group will grant the ability to run
         containers which can be used to obtain root privileges on the
         docker host.
         Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
         for more information.

安装成功,按提示将ubuntu用户添加到docker组,我这里用户是dopi,所以执行
sudo usermod -aG docker dopi
查看docker版本

dopi@ubuntu:$ sudo docker -v
Docker version 18.09.9, build 039a7df9ba

更换docker镜像源

修改 /etc/docker/daemon.json 文件配置,没有则 新建

{
  "registry-mirrors": ["https://m3dz4myl.mirror.aliyuncs.com"]
}

重启docker更新镜像源

sudo service docker restart

镜像拉取

DOPI已经把交叉编译环境使用Docker进行构建 拉取Docker镜像:

docker pull cijliu/arm-himix100-linux

执行过程:

 dopi@ubuntu:$ sudo docker pull cijliu/arm-himix100-linux
Using default tag: latest
latest: Pulling from cijliu/arm-himix100-linux
396e9d6ee8c9: Already exists 
403b0fc2e6f1: Already exists 
7124ef1a91d2: Already exists 
f47441d15565: Already exists 
588e8920e707: Already exists 
9b7af414de8c: Already exists 
f9d6674257e7: Already exists 
Digest: sha256:cc8bcb23cc011a74faec7c0645d27eba26317efe5c32d65b793c768ff78e20be
Status: Downloaded newer image for cijliu/arm-himix100-linux:latest
dopi@ubuntu:/home/ev200_tools/arm-himix100-linux$ 

查看拉取的交叉编译环境:

dopi@ubuntu:$ sudo docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
cijliu/arm-himix100-linux   latest              cdaa62aa5d4c        8 weeks ago         4.73GB

创建Docker容器

假设您的git的uboot,linux,rootfs文件在/usr/dopi目录下,然后执行:

sudo docker run -it -v $PWD:/usr/dopi --name dopi_ev200  cijliu/arm-himix100-linux bash

这样,就进入到了Docker容器内,并且把当前路径挂载在容器的/usr/dopi路径,接下来开始编译。

# arm-himix100-linux-gcc -v //查看是否gcc版本,输出信息说明成功
Using built-in specs.
COLLECT_GCC=arm-himix100-linux-gcc
COLLECT_LTO_WRAPPER=/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../libexec/gcc/arm-linux-uclibceabi/6.3.0/lto-wrapper
Target: arm-linux-uclibceabi
Configured with: /home/sying/SDK_CPU_UNIFIED/build/script/arm-himix100-linux/arm_himix100_build_dir/src/gcc-6.3.0/configure --host=i386-redhat-linux --build=i386-redhat-linux --target=arm-linux-uclibceabi --prefix=/home/sying/SDK_CPU_UNIFIED/build/script/arm-himix100-linux/arm_himix100_build_dir/install --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --enable-shared --enable-lto --enable-symvers=gnu --enable-__cxa_atexit --disable-libatomic --disable-nls --enable-clocale=gnu --enable-extra-hisi-multilibs --with-sysroot=/home/sying/SDK_CPU_UNIFIED/build/script/arm-himix100-linux/arm_himix100_build_dir/install/target --with-build-sysroot=/home/sying/SDK_CPU_UNIFIED/build/script/arm-himix100-linux/arm_himix100_build_dir/install/target --with-gmp=/home/sying/SDK_CPU_UNIFIED/build/script/arm-himix100-linux/arm_himix100_build_dir/obj/host-libs/usr --with-mpfr=/home/sying/SDK_CPU_UNIFIED/build/script/arm-himix100-linux/arm_himix100_build_dir/obj/host-libs/usr --with-mpc=/home/sying/SDK_CPU_UNIFIED/build/script/arm-himix100-linux/arm_himix100_build_dir/obj/host-libs/usr --disable-libgomp --disable-libquadmath --disable-fixed-point --disable-libsanitizer --disable-libitm --enable-poison-system-directories --with-pkgversion='HC&C V100R002C00B032_20190114'
Thread model: posix
gcc version 6.3.0 (HC&C V100R002C00B032_20190114)

下次使用可能需要启动容器

sudo docker container restart dopi_ev200  //启动已经创建好的容器
sudo docker exec -it dopi_ev200  bash //进入容器环境

感谢阅读

感谢您的阅读,此文献给初学者,关注DOPI的海思开源项目。

文档更新时间: 2021-02-18 06:59   作者:Tony