Sophgo ALIOS SDK 交叉编译环境Docker镜像生成
Sophgo ALIOS SDK 交叉编译环境Docker镜像构建
前言
为了验证学习成果,尝试编译一个镜像使用。目标是算能的CV181x和CV180x两款处理器ALIOS SDK的编译环境镜像。
Dockerfile
首先根据编译环境准备编写Dockerfile,如下
# 设置基础镜像为Ubuntu 20.04
FROM ubuntu:20.04
# 设置环境变量,用于非交互式安装
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update \
&& apt install -y sudo build-essential ninja-build automake autoconf libtool wget curl git gcc libssl-dev bc slib squashfs-tools android-sdk-libsparse-utils android-sdk-ext4-utils jq cmake python3-distutils tclsh scons parallel ssh-client tree python3-dev python3-pip device-tree-compiler libssl-dev ssh cpio squashfs-tools fakeroot libncurses5 flex bison unzip python
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 2
RUN pip3 install --upgrade pip
RUN pip3 install pyserial pyusb pyyaml yoctools -U
RUN useradd -c 'xsuns user' -m -d /home/xsuns -s /bin/bash xsuns \
&& sed -i -e '/\%sudo/ c \%sudo ALL=(ALL) NOPASSWD: ALL' /etc/sudoers \
&& usermod -a -G sudo xsuns
RUN yoc init
USER xsuns
WORKDIR /home/xsuns
其中有以下几点值得注意:
- ENV: DEBIAN_FRONTEND设置为
noninteractive
时,apt
和dpkg
会自动选择默认选项 - RUN: 尽量将多条指令合成为一条指令,这样可以减少Docker的镜像layer层数,提供容器运行时的性能。
- 新建了一个用户xsuns作为容器中的用户,并将其家目录作为入口工作目录。
编译镜像
进入Dockerfile所在的目录,执行下面指令编译镜像。
docker build -t cvi_alios_open .
其中 -t 选项表示容器的名称,格式为 name:tag。当 tag 不存在时默认使用 "latest"。编译出来的镜像如下:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
cvi_alios_open latest cdd1bdcd0771 26 minutes ago 713MB
运行容器
将容器运行指令写成脚本build.sh,编译时调用。
#!/bin/bash
docker run --rm --mount type=bind,source=$PWD,target=/home/xsuns --entrypoint make cvi_alios_open $@
选项含义如下:
- --rm:一次性容器,容器运行完毕后自动删除。
- --mount:挂载volume,将宿主机的source挂载到容器的target。类似-v,但是功能更丰富,可以声明权限。
- --entrypoint:进入容器调用的指令,容器运行时的参数将作为此指令的参数传入。此处为make指令。
编译指令如下:
./build.sh tdl_sample PROJECT=tdl_sample_180xb
分类:
Docker
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律