提交 6922551d 编写于 作者: Y yafen

add build scripts in a Docker container

lack /sbin/depmod

完善描述
上级 e246d4dc
/firmware
/firmware-nonfree
/bluez-firmware
/raspberrypi-kernel
/log
/repo
/output*
/root
/boot
/rootfs*
/img
/scripts/firmware
/scripts/firmware-nonfree
/scripts/bluez-firmware
/scripts/raspberrypi-kernel
/scripts/log
/scripts/tmp
/scripts/output*
/scripts/root
/scripts/boot
/scripts/rootfs*
/scripts/img
......@@ -6,7 +6,7 @@ This repository is main repository of openEuler RaspberryPi SIG, and provides sc
## How to collaborate
You can get introduction of openEuler RaspberryPi SIG from [sig-RaspberryPi](https://gitee.com/jianminw/community/tree/master/sig/sig-RaspberryPi)
You can get introduction of openEuler RaspberryPi SIG from [sig-RaspberryPi](https://gitee.com/jianminw/community/tree/master/sig/sig-RaspberryPi).
- Issues: welcome to collaborate with us by create new issues or reply opened issues. You can get repository list from [sig-RaspberryPi](https://gitee.com/jianminw/community/tree/master/sig/sig-RaspberryPi).
- Join Slack workspace: [openeuler-raspberrypi](https://openeuler-raspberrypi.slack.com )
......@@ -20,8 +20,9 @@ You can get introduction of openEuler RaspberryPi SIG from [sig-RaspberryPi](htt
## Files and Directories
- [build_img.sh](build_img.sh): Script for building openEuler image for Raspberry Pi
- [config](./config/): config files for building image
- [scripts](./scripts): Script for building openEuler image for Raspberry Pi
- [Build on host](scripts/build-img.sh)
- [Build in a Docker container](scripts/build-img-docker.sh)
- [documents](./documents/):
- [Building openEuler image for Raspberry Pi](documents/openEuler镜像的构建.md)
- [Cross-compile the kernel](documents/交叉编译内核.md)
......@@ -52,32 +53,56 @@ To build openEuler AArch64 image for Raspberry Pi, the requirements of runing sc
- OS: openEuler or CentOS 7/8
- Hardware: AArch64 hardware, such as Raspberry Pi
For other architecture hardwareyou can use [QEMU](https://www.qemu.org/) to build AArch64 system emulation.
For other architecture hardware, you can use [QEMU](https://www.qemu.org/) to build AArch64 system emulation.
### Run the scripts to build image
Refer to [Script for building openEuler image for Raspberry Pi](documents/openEuler镜像的构建.md) for details.
Build script: build_img.sh,which can be set 0/5/7 parameters.
#### Build on host
Build script: [build-img.sh](scripts/build-img.sh), which can be set 0/5/7 parameters.
1. Build with default parameters
`sudo bash build_img.sh`
`sudo bash build-img.sh`
2. Build with custom parameters
`sudo bash build_img.sh KERNEL_URL KERNEL_BRANCH KERNEL_DEFCONFIG DEFAULT_DEFCONFIG REPO_FILE_URL --cores MAKE_CORES`
`sudo bash build-img.sh KERNEL_URL KERNEL_BRANCH KERNEL_DEFCONFIG DEFAULT_DEFCONFIG REPO_FILE --cores MAKE_CORES`
or
`sudo bash build_img.sh KERNEL_URL KERNEL_BRANCH KERNEL_DEFCONFIG DEFAULT_DEFCONFIG REPO_FILE_URL`
`sudo bash build-img.sh KERNEL_URL KERNEL_BRANCH KERNEL_DEFCONFIG DEFAULT_DEFCONFIG REPO_FILE`
The meaning of each parameter:
- KERNEL_URL:The URL of kernel source's repository,which defaults to `git@gitee.com:openeuler/raspberrypi-kernel.git`.
- KERNEL_BRANCH:The branch name of kernel source's repository,which defaults to `openEuler-1.0-LTS-raspi`.
- KERNEL_DEFCONFIG:The filename of configuration for compiling kernel, which defaults to `openeuler-raspi_defconfig`. The configuration file should be in the config directory or in arch/arm64/configs of the kernel source. If this configuration file does not exist, the script uses the next parameter: DEFAULT_DEFCONFIG.
- DEFAULT_DEFCONFIG:The filename of configuration for kernel, which defaults to `openeuler-raspi_defconfig`. The configuration file should be in arch/arm64/configs of the kernel source. If both KERNEL_DEFCONFIG and this file do not exist, the process of building image will exit.
- REPO_FILE:The URL or name of openEuler's file, which defaults to `openEuler-20.03-LTS.repo`. Caution, if REPO_FILE is a file name, please make sure this file in the config directory. Otherwise, if REPO_FILE is a URL, please make sure you can get a correct repo file from this URL.
- --cores:Followed by parameter MAKE_CORES
- MAKE_CORES:The number of parallel compilations, according to the actual number of CPU of the server running the script. The default is 18.
- KERNEL_URL: The URL of kernel source's repository, which defaults to `https://gitee.com/openeuler/raspberrypi-kernel.git`.
- KERNEL_BRANCH: The branch name of kernel source's repository, which defaults to `openEuler-1.0-LTS-raspi`.
- KERNEL_DEFCONFIG: The filename of configuration for compiling kernel, which defaults to `openeuler-raspi_defconfig`. The configuration file should be in the config directory or in arch/arm64/configs of the kernel source. If this configuration file does not exist, the script uses the next parameter: DEFAULT_DEFCONFIG.
- DEFAULT_DEFCONFIG: The filename of configuration for kernel, which defaults to `openeuler-raspi_defconfig`. The configuration file should be in arch/arm64/configs of the kernel source. If both KERNEL_DEFCONFIG and this file do not exist, the process of building image will exit.
- REPO_FILE: The URL or name of openEuler's file, which defaults to `openEuler-20.03-LTS.repo`. Caution, if REPO_FILE is a file name, please make sure this file in the config directory. Otherwise, if REPO_FILE is a URL, please make sure you can get a correct repo file from this URL.
- --cores: Followed by parameter MAKE_CORES
- MAKE_CORES: The number of parallel compilations, according to the actual number of CPU of the server running the script. The default is 18.
#### Build in a Docker container
Build script: [build-img-docker.sh](scripts/build-img-docker.sh), which can be set 0/6/8 parameters. The script will automatically download a Docker image of openEuler and import it into the local system. The Docker image version is determined by the script's parameter: DOCKER_FILE.
Caution, before running the script, you need to install Docker.
1. Build with default parameters
`sudo bash build-img-docker.sh`
2. Build with custom parameters
`sudo bash build-img-docker.sh DOCKER_FILE KERNEL_URL KERNEL_BRANCH KERNEL_DEFCONFIG DEFAULT_DEFCONFIG REPO_FILE --cores MAKE_CORES`
or
`sudo bash build-img-docker.sh DOCKER_FILE KERNEL_URL KERNEL_BRANCH KERNEL_DEFCONFIG DEFAULT_DEFCONFIG REPO_FILE`
In addition to the first parameter DOCKER_FILE, the other parameters are the same as the corresponding parameters in "Build on host":
- DOCKER_FILE: The URL or name of the Docker image, which defaults to `https://repo.openeuler.org/openEuler-20.03-LTS/docker_img/aarch64/openEuler-docker.aarch64.tar.xz`. With the default parameter, the script will automatically download the Docker image of openEuler 20.03 LTS and import it into the local system. Caution, if DOCKER_FILE is a file name, please make sure this file in the config directory. Otherwise, if DOCKER_FILE is a URL, please make sure you can get a correct Docker image from this URL.
\ No newline at end of file
......@@ -18,8 +18,9 @@ SIG 组基本信息位于 [sig-RaspberryPi](https://gitee.com/jianminw/community
## 仓库目录
- [build_img.sh](build_img.sh): 构建 openEuler 树莓派镜像的主脚本
- [config](./config/): 构建使用的配置文件
- [scripts](./scripts): 构建 openEuler 树莓派镜像的脚本
- [主机上构建](scripts/build-img.sh)
- [Docker 容器中构建](scripts/build-img-docker.sh)
- [documents](./documents/): 使用文档
- [openEuler 镜像的构建](documents/openEuler镜像的构建.md)
- [交叉编译内核](documents/交叉编译内核.md)
......@@ -59,26 +60,50 @@ openEuler 20.03 LTS 的内测版本镜像:<https://isrc.iscas.ac.cn/EulixOS/re
详细过程参见 [openEuler 镜像的构建](documents/openEuler镜像的构建.md)
构建脚本 build_img.sh,其后可设置 0/5/7 个参数。
#### 主机上构建
构建脚本 [build-img.sh](scripts/build-img.sh),其后可设置 0/5/7 个参数。
1. 使用脚本默认参数构建
`sudo bash build_img.sh`
`sudo bash build-img.sh`
2. 自行设置参数构建
`sudo bash build_img.sh <KERNEL_URL> <KERNEL_BRANCH> <KERNEL_DEFCONFIG> <DEFAULT_DEFCONFIG> <REPO_FILE_URL> --cores <MAKE_CORES>`
`sudo bash build-img.sh KERNEL_URL KERNEL_BRANCH KERNEL_DEFCONFIG DEFAULT_DEFCONFIG REPO_FILE --cores MAKE_CORES`
`sudo bash build_img.sh <KERNEL_URL> <KERNEL_BRANCH> <KERNEL_DEFCONFIG> <DEFAULT_DEFCONFIG> <REPO_FILE_URL>`
`sudo bash build-img.sh KERNEL_URL KERNEL_BRANCH KERNEL_DEFCONFIG DEFAULT_DEFCONFIG REPO_FILE`
其中,各个参数意义:
- KERNEL_URL:内核源码的项目地址,默认为 `git@gitee.com:openeuler/raspberrypi-kernel.git`
- KERNEL_URL:内核源码的项目地址,默认为 `https://gitee.com/openeuler/raspberrypi-kernel.git`
- KERNEL_BRANCH:内核源码的对应分支,默认为 `openEuler-1.0-LTS-raspi`
- KERNEL_DEFCONFIG:内核编译使用的配置文件名称,默认为 `openeuler-raspi_defconfig`,在本目录的 config 目录下或内核源码的目录 arch/arm64/configs 下。如果该文件不存在则使用配置文件 DEFAULT_DEFCONFIG。
- DEFAULT_DEFCONFIG:内核默认配置文件名称,默认为 `openeuler-raspi_defconfig`,在内核源码的目录 arch/arm64/configs 下。如果 KERNEL_DEFCONFIG 和该文件均不存在则退出镜像构建过程。
- REPO_FILE:openEuler 开发源的 repo 文件的 URL 或者文件名称, 默认为 `openEuler-20.03-LTS.repo`。注意,如果 REPO_FILE 为文件名称,需要保证该文件在脚本 build_img.sh 所在目录的 config 文件夹下
- REPO_FILE:openEuler 开发源的 repo 文件的 URL 或者文件名称, 默认为 `openEuler-20.03-LTS.repo`。注意,如果 REPO_FILE 为文件名称,需要保证该文件在本目录的 config 文件夹下。否则,如果 REPO_FILE 为 URL,请保证可以通过该链接获取到该 repo 文件
- --cores:其后跟参数 MAKE_CORES。
- MAKE_CORES:并行编译的数量,根据运行脚本的服务器CPU实际数目设定,默认为 18。
#### Docker 容器内构建
构建脚本 [build-img-docker.sh](scripts/build-img-docker.sh),其后可设置 0/6/8 个参数。该脚本会自动下载 openEuler 的 Docker 镜像,并导入本机系统中,下载并导入的 Docker 镜像版本由该脚本参数 DOCKER_FILE 决定。
注意!!!运行该脚本前,需安装 Docker 运行环境。
1. 使用脚本默认参数构建
`sudo bash build-img-docker.sh`
2. 自行设置参数构建
`sudo bash build-img-docker.sh DOCKER_FILE KERNEL_URL KERNEL_BRANCH KERNEL_DEFCONFIG DEFAULT_DEFCONFIG REPO_FILE --cores MAKE_CORES`
`sudo bash build-img-docker.sh DOCKER_FILE KERNEL_URL KERNEL_BRANCH KERNEL_DEFCONFIG DEFAULT_DEFCONFIG REPO_FILE`
其中,除第一个参数 DOCKER_FILE 外,剩余参数与`主机上构建`中对应参数一致:
- DOCKER_FILE:Docker 镜像的 URL 或者文件名称, 默认为 `https://repo.openeuler.org/openEuler-20.03-LTS/docker_img/aarch64/openEuler-docker.aarch64.tar.xz`。使用该默认参数时,脚本会自动下载 openEuler 20.03 LTS 的 Docker 镜像,并导入本机系统中。注意,如果 DOCKER_FILE 为文件名称,需要保证该文件在本目录的 config 文件夹下。否则,如果 DOCKER_FILE 为 URL,请保证可以通过该链接获取到该 Docker 镜像。
\ No newline at end of file
......@@ -71,9 +71,10 @@
### 输入新分区的起始扇区号
注意!!!不要直接输入回车或使用默认参数。这是需要输入删除分区 /dev/mmcblk0p3 之前查看到的的起始扇区号。
`xxx`
这是输入删除分区 /dev/mmcblk0p3 之前查看到的的起始扇区号。
### 输入新分区的终止扇区号
......@@ -89,7 +90,7 @@
### 保存并退出
`wq`
`w`
该操作结束后,使用 `fdisk -l` 命令可以看到 /dev/mmcblk0p3 大小已经扩展。但是通过 `df -lh` 可以看到根目录大小没有变化。
......
#!/bin/bash
set -e
cur_dir=$(cd $(dirname $0);pwd)
cd "${cur_dir}"
if [[ $# -ne 0 && $# -ne 6 && $# -ne 8 ]]; then
echo Error: params length: $# is not 0/6/8.
echo Example1: bash $0
echo Example2: bash $0 DOCKER_FILE KERNEL_URL KERNEL_BRANCH KERNEL_DEFCONFIG DEFAULT_DEFCONFIG REPO_FILE --cores MAKE_CORES
echo Example3: bash $0 DOCKER_FILE KERNEL_URL KERNEL_BRANCH KERNEL_DEFCONFIG DEFAULT_DEFCONFIG REPO_FILE
exit 1
fi
docker_file="https://repo.openeuler.org/openEuler-20.03-LTS/docker_img/aarch64/openEuler-docker.aarch64.tar.xz"
kernel_url="https://gitee.com/openeuler/raspberrypi-kernel.git"
kernel_branch="openEuler-1.0-LTS-raspi"
kernel_defconfig="openeuler-raspi_defconfig"
default_defconfig="openeuler-raspi_defconfig"
repo_file=openEuler-20.03-LTS.repo
make_cores=18
if [[ $# -eq 6 || $# -eq 8 ]]; then
if [[ $1 != "" ]]; then
docker_file=$1
fi
if [[ $2 != "" ]]; then
kernel_url=$2
fi
if [[ $3 != "" ]]; then
kernel_branch=$3
fi
if [[ $4 != "" ]]; then
kernel_defconfig=$4
fi
if [[ $5 != "" ]]; then
default_defconfig=$5
fi
if [[ $6 != "" ]]; then
repo_file=$6
fi
fi
if [[ $# -eq 8 && $7 == "--cores" && $8 -ne 0 ]]; then
make_cores=$8
fi
buildid=$(date +%Y%m%d%H%M%S)
builddate=${buildid:0:8}
if [ ! -d ${cur_dir}/log ]; then
mkdir ${cur_dir}/log
fi
if [ ! -d ${cur_dir}/tmp ]; then
mkdir ${cur_dir}/tmp
fi
ERROR(){
echo `date` - ERROR, $* | tee -a ${cur_dir}/log/log_${builddate}.log
}
LOG(){
echo `date` - INFO, $* | tee -a ${cur_dir}/log/log_${builddate}.log
}
docker_file_name=${docker_file##*/}
if [ "${docker_file:0:4}" = "http" ]; then
if [ ! -f ${cur_dir}/tmp/${docker_file_name} ]; then
wget ${docker_file} -P ${cur_dir}/tmp/
fi
else
cp ${cur_dir}/config/${docker_file} ${cur_dir}/tmp/
fi
docker_img_name=`docker load --input ${cur_dir}/tmp/${docker_file_name}`
docker_img_name=${docker_img_name##*: }
(echo "FROM $docker_img_name" && grep -v FROM config/Dockerfile_makeraspi) | docker build -t ${docker_img_name}-${buildid} --no-cache -f- .
echo docker run --rm --privileged=true -v ${cur_dir}:/work ${docker_img_name}-${buildid} $kernel_url $kernel_branch $kernel_defconfig $default_defconfig $repo_file --cores $make_cores
docker run --rm --privileged=true -v ${cur_dir}:/work ${docker_img_name}-${buildid} $kernel_url $kernel_branch $kernel_defconfig $default_defconfig $repo_file --cores $make_cores
chmod -R a+r ${cur_dir}/img
docker image rm ${docker_img_name}-${buildid}
echo
echo Done.
......@@ -3,19 +3,23 @@ set -e
if [[ $# -ne 0 && $# -ne 5 && $# -ne 7 ]]; then
echo "params length: $# is not 0/5/7."
echo Example1: bash $0
echo Example2: bash $0 KERNEL_URL KERNEL_BRANCH KERNEL_DEFCONFIG DEFAULT_DEFCONFIG REPO_FILE --cores MAKE_CORES
echo Example3: bash $0 KERNEL_URL KERNEL_BRANCH KERNEL_DEFCONFIG DEFAULT_DEFCONFIG REPO_FILE
exit 1
fi
cur_dir=`pwd`
cur_dir=$(cd $(dirname $0);pwd)
run_dir=${cur_dir}
kernel_url="git@gitee.com:openeuler/raspberrypi-kernel.git"
kernel_branch="openEuler-1.0-LTS-rasp"
kernel_url="https://gitee.com/openeuler/raspberrypi-kernel.git"
kernel_branch="openEuler-1.0-LTS-raspi"
kernel_defconfig="openeuler-raspi_defconfig"
default_defconfig="openeuler-raspi_defconfig"
repo_file=openEuler-20.03-LTS.repo
date_str=$(date "+%Y%m%d")
buildid=$(date +%Y%m%d%H%M%S)
builddate=${buildid:0:8}
output_dir=${run_dir}/output
rootfs_dir=${run_dir}/rootfs_${date_str}
rootfs_dir=${run_dir}/rootfs_${builddate}
root_mnt=${run_dir}/root
boot_mnt=${run_dir}/boot
make_cores=18
......@@ -45,14 +49,14 @@ repo_file_name=${repo_file##*/}
img_suffix=${repo_file_name%%-*}
img_suffix=`echo $img_suffix | grep -Eo "^[a-zA-Z ]*"`
os_release_name=${img_suffix}-release
img_file=${run_dir}/img/${date_str}/${img_suffix}_${date_str}.img
img_file=${run_dir}/img/${builddate}/${img_suffix}_${buildid}.img
ERROR(){
echo `date` - ERROR, $* | tee -a ${cur_dir}/log/log_${date_str}.log
echo `date` - ERROR, $* | tee -a ${cur_dir}/log/log_${builddate}.log
}
LOG(){
echo `date` - INFO, $* | tee -a ${cur_dir}/log/log_${date_str}.log
echo `date` - INFO, $* | tee -a ${cur_dir}/log/log_${builddate}.log
}
prepare(){
......@@ -73,30 +77,30 @@ prepare(){
if [ ! -d ${run_dir}/img ]; then
mkdir ${run_dir}/img
fi
if [ -d ${cur_dir}/repo ]; then
rm -rf ${cur_dir}/repo
if [ ! -d ${cur_dir}/tmp ]; then
mkdir ${cur_dir}/tmp
fi
mkdir ${cur_dir}/repo
if [ "${repo_file:0:4}" = "http" ]; then
# rpm_url=`wget -q -O - ${repo_file} | grep "^baseurl=" | cut -d '=' -f 2 | xargs`
wget ${repo_file} -P ${cur_dir}/repo/
wget ${repo_file} -P ${cur_dir}/tmp/
else
# rpm_url=`cat ${repo_file} | grep "^baseurl=" | grep "everything" | cut -d '=' -f 2 | xargs`
cp ${cur_dir}/config/${repo_file} ${cur_dir}/repo/${repo_file_name}
cp ${cur_dir}/config/${repo_file} ${cur_dir}/tmp/${repo_file_name}
fi
if [ $? -ne 0 ]; then
ERROR ${repo_file} not found.
exit 1
else
yumdownloader --downloaddir=${cur_dir}/repo/ $os_release_name -c ${cur_dir}/repo/${repo_file_name}
os_release_name=`ls -r ${cur_dir}/repo/${os_release_name}*.rpm | head -n 1`
yumdownloader --downloaddir=${cur_dir}/tmp/ $os_release_name -c ${cur_dir}/tmp/${repo_file_name}
os_release_name=`ls -r ${cur_dir}/tmp/${os_release_name}*.rpm | head -n 1`
if [ -z "${os_release_name}" ]; then
ERROR "Fail to download ${os_release_name}!"
exit 1
fi
fi
if [ ! -d ${run_dir}/img/${date_str} ]; then
mkdir -p ${run_dir}/img/${date_str}
if [ ! -d ${run_dir}/img/${builddate} ]; then
mkdir -p ${run_dir}/img/${builddate}
fi
LOG "prepare end."
}
......@@ -324,7 +328,7 @@ make_rootfs(){
if [[ ! -d ${rootfs_dir}/etc/yum.repos.d ]]; then
mkdir -p ${rootfs_dir}/etc/yum.repos.d
fi
cp ${cur_dir}/repo/*.repo $rootfs_dir/etc/yum.repos.d/
cp ${cur_dir}/tmp/*.repo $rootfs_dir/etc/yum.repos.d/
dnf --installroot=${rootfs_dir}/ install dnf --nogpgcheck -y #--repofrompath=${repo_file_name},${rootfs_dir}/etc/yum.repos.d/${repo_file_name}
dnf --installroot=${rootfs_dir}/ makecache
dnf --installroot=${rootfs_dir}/ install -y wpa_supplicant vim net-tools iproute iputils NetworkManager openssh-server passwd hostname ntp
......@@ -476,3 +480,4 @@ update_kernel
make_rootfs
make_img
FROM openeuler-20.03-lts:latest
RUN dnf clean expire-cache
COPY config/openEuler-20.03-LTS.repo /etc/yum.repos.d/openEuler-20.03-LTS.repo
RUN dnf -y install cmake gdb gcc gcc-c++ libstdc++-static ncurses ncurses-devel make python bash coreutils && \
dnf -y clean all
RUN dnf -y install module-init-tools git openssl-devel bc bison flex dosfstools parted wget device-mapper-multipath
RUN dnf -y install tar passwd diffutils
ENV SHELL=/bin/bash
ENTRYPOINT ["/bin/bash", "/work/build-img.sh"]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册