特别说明
已经为大家编译好了一个示例镜像,上传到了 百度网盘
中:
立创·泰山派开发板资料
-> 第06章.【立创·泰山派】系统镜像
-> 【镜像】OpenKylin
可以自由下载尝试
希望大家先暂时自行摸索本文档。
因为 openkylin
编译涉及到的东西比较庞大,需要自身具备相关的系统知识,所以目前 暂时无法提供编译问题相关支持 。
文档修订历史
版本 | 修订内容 | 修订人 | 审核人 | 日期 |
---|---|---|---|---|
V1.0 | 创建文档 | 2025/07/07 |
一、说明
宿主机环境使用的是
Ubuntu22.04.5 LTS Desktop
lipeng@lipeng:~$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.5 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.5 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
2
3
4
5
6
7
8
9
10
11
12
13
有两种构建方式:
- Docker构建
- 宿主机构建
这两种方式任选其一即可!
Openkylin登录账号:openkylin
Openkylin登录密码:openkylin
二、Docker构建方式
1、Docker的安装与配置(可跳过)
如果docker在环境中之前已经安装并使用过,没有问题,则可以跳过
Docker的安装与配置
卸载旧版本
如果卸载过docker没有卸载干净,要运行下面的命令!
sudo apt-get remove docker docker-engine docker.io containerd runc
Docker安装方式
📌 目前国外的 Docker Hub
有问题,不知道什么时候恢复,可以使用阿里安装方式!
更新 apt
包索引并安装相关软件包以允许 apt
通过 HTTPS
下载安装:
sudo apt-get update && \
sudo apt-get install ca-certificates curl gnupg lsb-release
2
添加阿里云的 Docker GPG
密钥
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
添加阿里云加速器
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
安装 Docker engine
sudo apt-get update && \
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
2
验证安装完成
sudo docker -v
# 打印出版本号
Docker version 28.0.2, build 0442a73
2
3
4
配置Docker网络
修改或创建 /etc/docker/daemon.json
文件
sudo vi /etc/docker/daemon.json
将文件内容改为:
{
"registry-mirrors": ["https://ccr.ccs.tencentyun.com/"]
}
2
3
然后保存退出。 重启docker:
sudo systemctl restart docker
2、编写dockerfile
创建dockerfiles文件夹
用于存放
dockerfile
文件。
运行下面的命令:
mkdir dockerfiles
效果:
lipeng@lipeng:~/openkylin-sdk/docker$ ls
lipeng@lipeng:~/openkylin-sdk/docker$ mkdir dockerfiles
lipeng@lipeng:~/openkylin-sdk/docker$ ls
dockerfiles
lipeng@lipeng:~/openkylin-sdk/docker$
2
3
4
5
进入 dockerfiles
文件夹
cd dockerfiles
编写dockerfile文件
创建并编写 dockerfile
文件:
vim dockerfile
编写以下内容:
# 基础镜像
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
# 备份源列表文件
RUN cp -a /etc/apt/sources.list /etc/apt/sources.list.bak
# 配置https://help.mirrors.cernet.edu.cn/ubuntu/
# APT镜像源(加速下载)
# 清理apt旧文件
RUN cat <<'EOF' > /etc/apt/sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.cernet.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.cernet.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.cernet.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.cernet.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.cernet.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.cernet.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb http://mirrors.cernet.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.cernet.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
EOF
RUN apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
apt-get update -o Acquire::http::No-Cache=True
RUN apt-get update && apt-get install -f -y
# 安装基本的工具和依赖
RUN apt-get update && apt install -y --fix-missing mount util-linux build-essential crossbuild-essential-arm64 \
bash-completion vim sudo locales time rsync bc python3 python2 whiptail zfs-fuse
# 安装完整工具链
RUN apt-get update && apt-get install -y --fix-missing \
git ssh make gcc-9 g++-9 libssl-dev liblz4-tool expect \
patchelf chrpath gawk texinfo diffstat binfmt-support \
qemu-user-static live-build bison flex fakeroot cmake \
gcc-multilib g++-multilib unzip device-tree-compiler \
ncurses-dev vim net-tools u-boot-tools dpkg-dev \
build-essential ccache rsync python3-pip libgmp-dev \
live-build qemu-user-static binfmt-support libmpc-dev \
libgmp-dev build-essential dpkg-dev fakeroot binutils \
libelf-dev bc bison flex libssl-dev liblz4-tool \
u-boot-tools
RUN apt-get update && apt-get install -y --fix-missing git ssh make gcc libssl-dev \
liblz4-tool expect g++ patchelf chrpath gawk texinfo chrpath \
diffstat binfmt-support qemu-user-static live-build bison \
flex fakeroot cmake gcc-multilib g++-multilib unzip \
device-tree-compiler ncurses-dev pv
RUN apt-get update && \
apt-get install -y --fix-missing \
build-essential \
devscripts \
equivs
# 交叉编译工具链
RUN apt-get update && apt-get install -y --fix-missing \
gcc-aarch64-linux-gnu \
g++-aarch64-linux-gnu \
libc6-dev-arm64-cross \
libgcc-11-dev-arm64-cross
# Openkylin 额外依赖安装
RUN apt-get update && apt-get install -y --fix-missing debootstrap coreutils
# RUN apt-get install -y --fix-missing qemu-system-arm
# 可自动添加 PPA 源并处理密钥
RUN apt-get install -y --fix-missing software-properties-common
# QEMU配置
RUN update-binfmts --enable qemu-aarch64
# Python依赖
RUN pip3 install pyelftools
# 将python命令指向python3
RUN ln -s /usr/bin/python3 /usr/bin/python
# 内核头文件
RUN apt install -y linux-headers-generic
# 时区配置
RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 创建开发板用户
RUN useradd -c 'lckfb user' -m -d /home/lckfb -s /bin/bash lckfb
# sudo免密登录
RUN sed -i -e '/\%sudo/ c \%sudo ALL=(ALL) NOPASSWD: ALL' /etc/sudoers
RUN usermod -a -G sudo lckfb
# 设置openkulin的环境
RUN wget https://launchpad.net/ubuntu/+archive/primary/+files/debootstrap_1.0.118ubuntu1.11_all.deb \
-P /home/lckfb/
RUN dpkg -i /home/lckfb/debootstrap_1.0.118ubuntu1.11_all.deb
# 解决SSH连接错误等问题:Connection closed by 198.18.0.65 port 22
RUN mkdir -p /home/lckfb/.ssh/
RUN touch /home/lckfb/.ssh/config
RUN cat <<'EOF' > /home/lckfb/.ssh/config
Host github.com
HostName ssh.github.com
Port 443
EOF
# 登录lckfb用户
USER lckfb
RUN mkdir -p /home/lckfb/sdk
# 工作目录
WORKDIR /home/lckfb/sdk
VOLUME ["/home/lckfb/sdk"]
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
效果:
lipeng@lipeng:~/openkylin-sdk/docker/dockerfiles$ vim dockerfile
lipeng@lipeng:~/openkylin-sdk/docker/dockerfiles$ ls -l
total 4
-rw-r--r-- 1 lipeng lipeng 4074 7月 3 17:52 dockerfile
2
3
4
3、构建Docker镜像
下面两个构建命令,二选一即可!
- 经典构建:
docker build -t openkylin-build-docker-img .
- 构建时不使用旧缓存(更加干净的构建新的镜像):
docker build --no-cache -t openkylin-build-docker-img .
构建完成:
4、创建SDK目录
退回上一级目录
cd ..
创建目录:
mkdir openkylin-sdk
5、启动Docker容器
此命令使用到了
-v
,映射了宿主机SDK目录
到容器内SDK目录
。
docker run -itd --name openkylin-sdk-docker-build \
--hostname lckfb-openkylin \
--privileged \
--mount type=bind,source="$(pwd)/openkylin-sdk",target="/home/lckfb/sdk" \
openkylin-build-docker-img
2
3
4
5
运行效果:
6、进入容器
通过exec进入新终端(推荐):
/bin/bash 进入交互式终端!
docker exec -it openkylin-sdk-docker-build /bin/bash
7、repo拉取Github泰山派SDK
设定github的SSH密钥
查看本文档最后面 Q&A
章节中的 【如何设定Github-SSH密钥】
设定密钥。
运行repo拉取manifests
修改name
、email
信息,运行下面的命令会自动保存在 ~/.gitconfig
文件中:
NOTE
<Your Name>
和 you@example.com
需要改为你自己的 Github名字
和 Github有效邮箱
不知道 Github名字
和 Github有效邮箱
在哪里找的,就去最后的 Q&A
章节里面看下 【Github的名字和有效邮箱在哪里?】
,有详细的教程。
git config --global user.name "<Your Name>"
git config --global user.email <you@example.com>
2
从 百度网盘
里面下载 repo
工具,放置在我们的 sdk
目录下:
TIP
之前 启动docker容器
的时候,已经将主机中的 openkylin-sdk/
目录映射到了容器内的 /home/lckfb/sdk
目录。 所以我向 openkylin-sdk/
目录中存放东西,就相当于往 /home/lckfb/sdk
目录中存放东西;反之亦然。
NOTE
百度网盘链接在 泰山派 - 下载中心
立创·泰山派开发板资料
-> 第07章.【立创·泰山派】开发工具
-> repo工具
给予运行权限:
sudo chmod +x ./repo
效果:
运行命令,开始拉取:
./repo init -u https://github.com/TaishanPi/manifests.git \
-b default \
-m taishanpi_rk3566_linux5.10_release.xml \
--repo-url=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo
2
3
4
多出了一个
.repo
目录
同步repo代码
.repo/repo/repo sync -j$(nproc)
等待同步完成:
8、编译内核
在
SDK
根目录下运行命令,编译内核
./build.sh lunch && ./build.sh extboot-dpkg && ./build.sh extboot
先选择 5
的配置文件,单独的配置问题,之后会解决:
编译成功:
- 会在
SDK
根目录下生成几个.deb
包,这个是用于内核升级用的。- 会在
kernel/
目录下生成一个boot.img
镜像,这个就是内核镜像。
9、Git拉取Openkylin代码
拉取nile分支的代码
git clone -b nile https://gitee.com/openkylin/openkylin-embedded-builder.git
进入 openkylin-embedded-builder/
目录:
cd openkylin-embedded-builder/
切换版本:
特别说明:这个操作是因为
github
上泰山派的kernel
目前有点问题,下个月新版本会解决!
# 切换指定节点
git checkout 7ff84ba7bc1de884da3624f37bc88fd2ff33b454
# 切换软件源的版本,单文件切换版本
git checkout b57223f5f0209535a13fb23b413095965fe70912 -- config/openkylin/apt_source-arm64.sh
git checkout b57223f5f0209535a13fb23b413095965fe70912 -- functions.sh
# 查看当前 HEAD 对应的提交哈希是不是已经切换
git rev-parse HEAD
# 查看单文件切换的状态
git status
2
3
4
5
6
7
8
9
10
11
12
10、编译Openkylin文件系统
确保自己在
openkylin-embedded-builder/
目录中
开始编译:
sudo ./check-env.sh && sudo ./okbuild.sh -p prop_tspi
编译成功:会在 openkylin-embedded-builder/
目录中生成一个相关的 .img
文件系统镜像。
11、生成相关固件
返回 SDK
根目录,在 SDK
根目录下运行:
./build.sh firmware
会自动生成一个
rockdev/
文件夹,里面是一些其他的镜像文件,烧录的时候要用。
接下来就可以去【Linux5.10版本SDK镜像烧录】
章节进行镜像烧录测试了!
三、宿主机构建方式
0、环境说明
系统:
lckfb@lckfb-openkylin:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.2 LTS
Release: 22.04
Codename: jammy
2
3
4
5
6
1、环境搭建
分别运行下面的命令安装相关的依赖:
sudo apt-get update && sudo apt-get install -f -y && \
sudo apt-get install -y --fix-missing \
git ssh make gcc-9 g++-9 libssl-dev liblz4-tool expect \
patchelf chrpath gawk texinfo diffstat binfmt-support \
qemu-user-static live-build bison flex fakeroot cmake \
gcc-multilib g++-multilib unzip device-tree-compiler \
ncurses-dev vim net-tools u-boot-tools dpkg-dev \
build-essential ccache rsync python3-pip libgmp-dev \
live-build qemu-user-static binfmt-support libmpc-dev \
libgmp-dev build-essential dpkg-dev fakeroot binutils \
libelf-dev bc bison flex libssl-dev liblz4-tool \
u-boot-tools g++ patchelf chrpath gawk texinfo chrpath \
diffstat binfmt-support qemu-user-static live-build bison \
flex fakeroot cmake unzip pv devscripts equivs && \
sudo apt install -y \
gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \
libc6-dev-arm64-cross libgcc-11-dev-arm64-cross && \
sudo apt-get install -y debootstrap coreutils software-properties-common
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
相关的配置:
这里使用python3.
sudo update-binfmts --enable qemu-aarch64 && \
pip3 install pyelftools && \
sudo rm -rf /usr/bin/python && \
sudo ln -s /usr/bin/python3 /usr/bin/python
2
3
4
安装 openkylin
构建所需的 debootstrap
版本:
wget https://launchpad.net/ubuntu/+archive/primary/+files/debootstrap_1.0.118ubuntu1.11_all.deb \
-P /tmp/ && \
sudo dpkg -i /tmp/debootstrap_1.0.118ubuntu1.11_all.deb
2
3
解决 github
的 SSH
连接问题:
Error: Connection closed by 198.18.0.65 port 22
mkdir -p ~/.ssh/ && \
touch ~/.ssh/config && \
cat <<'EOF' > ~/.ssh/config
Host github.com
HostName ssh.github.com
Port 443
EOF
2
3
4
5
6
7
创建一个文件夹作为 sdk
的根目录:
mkdir -p ~/openkylin-sdk/host/
进入 sdk
根目录:
cd ~/openkylin-sdk/host/
2、repo拉取Github泰山派SDK
设定github的SSH密钥
查看本文档最后面 Q&A
章节中的 【如何设定Github-SSH密钥】
设定密钥。
运行repo拉取manifests
修改name
、email
信息,运行下面的命令会自动保存在 ~/.gitconfig
文件中:
NOTE
<Your Name>
和 you@example.com
需要改为你自己的 Github名字
和 Github有效邮箱
不知道 Github名字
和 Github有效邮箱
在哪里找的,就去最后的 Q&A
章节里面看下 【Github的名字和有效邮箱在哪里?】
,有详细的教程。
git config --global user.name "<Your Name>"
git config --global user.email <you@example.com>
2
从 百度网盘
里面下载 repo
工具,放置在我们的 sdk
目录下:
TIP
之前 启动docker容器
的时候,已经将主机中的 openkylin-sdk/
目录映射到了容器内的 /home/lckfb/sdk
目录。 所以我向 openkylin-sdk/
目录中存放东西,就相当于往 /home/lckfb/sdk
目录中存放东西;反之亦然。
NOTE
百度网盘链接在 泰山派 - 下载中心
立创·泰山派开发板资料
-> 第07章.【立创·泰山派】开发工具
-> repo工具
给予运行权限:
sudo chmod +x ./repo
效果:
运行命令,开始拉取:
./repo init -u https://github.com/TaishanPi/manifests.git \
-b default \
-m taishanpi_rk3566_linux5.10_release.xml \
--repo-url=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo
2
3
4
多出了一个
.repo
目录
同步repo代码
.repo/repo/repo sync -j$(nproc)
等待同步完成:
3、编译内核
在
SDK
根目录下运行命令,编译内核
./build.sh lunch && ./build.sh extboot-dpkg && ./build.sh extboot
先选择 5
,这个问题之后会解决:
编译成功:
- 会在
SDK
根目录下生成几个.deb
包,这个是用于内核升级用的安装包。- 会在
kernel/
目录下生成一个boot.img
镜像,这个就是内核镜像。
4、Git拉取Openkylin代码
拉取nile分支的代码
git clone -b nile https://gitee.com/openkylin/openkylin-embedded-builder.git
进入 openkylin-embedded-builder/
目录:
cd openkylin-embedded-builder/
切换版本:
特别说明:这个操作是因为
github
上泰山派的kernel
目前有点问题,下个月新版本会解决!
# 切换指定节点
git checkout 7ff84ba7bc1de884da3624f37bc88fd2ff33b454
# 切换软件源的版本,单文件切换版本
git checkout b57223f5f0209535a13fb23b413095965fe70912 -- config/openkylin/apt_source-arm64.sh
git checkout b57223f5f0209535a13fb23b413095965fe70912 -- functions.sh
# 查看当前 HEAD 对应的提交哈希是不是已经切换
git rev-parse HEAD
# 查看单文件切换的状态
git status
2
3
4
5
6
7
8
9
10
11
12
5、编译Openkylin文件系统
确保自己在
openkylin-embedded-builder/
目录中
开始编译:
sudo ./check-env.sh && sudo ./okbuild.sh -p prop_tspi
编译成功:会在 openkylin-embedded-builder/
目录中生成一个相关的 .img
文件系统镜像。
lipeng@lipeng:~/openkylin-sdk/host/openkylin-embedded-builder$ ls -l *.img
-rw-r--r-- 1 root root 6220152832 7月 7 14:09 openKylin-Embedded-V2.0-rc-tspi-arm64.img
2
6、生成相关固件
返回 SDK
根目录,在 SDK
目录下运行:
./build.sh firmware
会自动生成一个
rockdev/
文件夹,里面是一些其他的镜像文件,烧录的时候要用。
接下来就可以去【Linux5.10版本SDK镜像烧录】
章节进行镜像烧录测试了!
四、Linux5.10版本SDK镜像烧录
注意:镜像烧录的演示,使用的是
docker
目录,但基本的相对位置是一致的,可以不用担心。
泰山派 linux5.10
版本的 SDK
编译出来的 img镜像
,已经极大的压缩了数量,目前烧录只需要 5
个 img镜像
。
- Loader
- Parameter
- uboot
- boot
- rootfs
在 rockdev/
目录中有 3
个相关的镜像固件:MiniLoaderAll.bin
、parameter.txt
和 uboot.img
lckfb@lckfb-openkylin:~/sdk$ ls rockdev/
MiniLoaderAll.bin oem.img parameter.txt uboot.img update.img userdata.img
2
在 openkylin-embedded-builder/
目录中有 openKylin-Embedded-V2.0-rc-tspi-arm64.img
镜像文件,这个就是 rootfs.img
只不过名字不一样罢了,作用是一样的。
lckfb@lckfb-openkylin:~/sdk$ ls -l openkylin-embedded-builder/openKylin-Embedded-V2.0-rc-tspi-arm64.img
-rw-r--r-- 1 root root 6151995392 Jul 4 11:14 openkylin-embedded-builder/openKylin-Embedded-V2.0-rc-tspi-arm64.img
2
在 kernel/
目录中有 boot.img
镜像文件,这个就是内核镜像文件。
lckfb@lckfb-openkylin:~/sdk$ ls -l kernel/boot.img
-rw-r--r-- 1 lckfb lckfb 134217728 Jul 4 11:08 kernel/boot.img
2
瑞芯微开发工具中相关位置的对照表:
名字 | 所对应的img镜像在SDK中的位置 |
---|---|
Loader | SDK/rockdev/MiniLoaderAll.bin |
Parameter | SDK/rockdev/parameter.txt |
uboot | SDK/rockdev/uboot.img |
boot | SDK/kernel/boot.img |
rootfs | SDK/openkylin-embedded-builder/openKylin-Embedded-V2.0-rc-tspi-arm64.img |
Loader ------> SDK/rockdev/MiniLoaderAll.bin
Parameter ---> SDK/rockdev/parameter.txt
uboot -------> SDK/rockdev/uboot.img
boot --------> SDK/kernel/boot.img
rootfs ------> SDK/openkylin-embedded-builder/openKylin-Embedded-V2.0-rc-tspi-arm64.img
2
3
4
5
瑞芯微开发工具导入配置:
选择
parameter.txt
文件导入!
烧录:
按住
泰山派REC按键
然后轻按一下RST按键
,等待3秒后松开REC按键
,这样泰山派就进入了LOADER
模式,可以开始进行烧录了。
等待烧录完成:
【Q&A】
如何设定Github-SSH密钥
公钥和私钥的区别
- 公钥(Public Key):可以公开分享的密钥,用于加密信息或验证数字签名。
- 私钥(Private Key):必须保密的密钥,用于解密信息或创建数字签名。
这里我们主要用到的是 SSH
密钥身份认证,将公钥加入到 SSH Keys
中,通过相关的身份验证。
运行命令,生成密钥对:
ssh-keygen -t ed25519 -C "lipeng@sz-jlc.com"
查看并手动复制公钥(用于粘贴到 Github
上):
cat ~/.ssh/id_ed25519.pub
打开 Github
主页,进入设置:
选择设置:
添加 SSH Keys
:
注意!点击 Add SSH Key
的时候输入会让你输入一次 Github
账号密码。成功之后:
Github的名字和有效邮箱在哪里?
打开 Github
主页,进入设置:
选择设置:
即可查看: