一、准备环境
- CentOS8
- 已经正常安装Jenkins
二、升级 cmake
cmake 升到 3.16以上。
bash
cmake --version
# 安装 g++
sudo yum install gcc-c++
export CXX=g++
# 安装 CMake 的依赖项
sudo yum install -y openssl-devel
# 下载 CMake 源码并进行编译安装
wget https://github.com/Kitware/CMake/releases/download/v3.21.1/cmake-3.21.1.tar.gz
tar -zxvf cmake-3.21.1.tar.gz
cd cmake-3.21.1
./bootstrap
make
sudo make install
三、升级 bash
bash要升到 4 以上。
bash
cd /opt
wget -v http://ftp.gnu.org/gnu/bash/bash-5.1.16.tar.gz
tar zxvf bash-5.1.16.tar.gz
cd bash-5.1.16/
./configure
make install
mv /bin/bash /bin/bash.bak && ln -s /usr/local/bin/bash /bin/bash
四、安装IDF编译工具链
1. 替换源
bash
git clone https://gitee.com/EspressifSystems/esp-gitee-tools.git
cd esp-gitee-tools/
./jihu-mirror.sh set
bash
# 依赖准备
sudo yum -y update && sudo yum install git wget flex bison gperf cmake ninja-build ccache dfu-util libusbx
在这里遇到个问题,提示:
Public key for jenkins-2.401.2-1.1.noarch.rpm is not installed
,
意思是系统中缺少 Jenkins 软件包的公钥,因此无法验证软件包的真实性。
执行下面操作:
bash
cd /opt
wget -O jenkins.rpm https://pkg.jenkins.io/redhat-stable/jenkins-2.401.2-1.1.noarch.rpm --no-check-certificate
sudo yum localinstall jenkins.rpm
2. 安装python3.8
ESP-IDF 需要python3.7以上版本,如果yum仓库版本比较低,则需要手动下载安装。
bash
cd /opt
wget https://www.python.org/ftp/python/3.8.16/Python-3.8.16.tgz
tar -zxvf Python-3.8.16.tgz
ls
cd Python-3.8.16
./configure --prefix=/opt/Python-3.8.16 --with-openssl=/usr/local/openssl
make
make install
rm -rf /usr/bin/pip3 /usr/bin/python3
ln -s /usr/local/bin/pip3.8 /usr/bin/pip3
ln -s /usr/local/bin/python3.8 /usr/bin/python3
2. 获取 ESP-IDF
bash
mkdir -p /opt/esp
cd /opt/esp
git clone -b v5.1 --recursive https://github.com/espressif/esp-idf.git
3. 安装 ESP-IDF
bash
cd /opt/esp/esp-idf
# 提高下载速度
export IDF_GITHUB_ASSETS="dl.espressif.com/github_assets"
./install.sh esp32,esp32s2,esp32c2,esp32c3
. ./export.sh
五、流水线设置
Jenkinsfile脚本 :
groovy
pipeline{
agent any
environment {
IDF_PATH = "/opt/esp/esp-idf" // 替换为您的 ESP-IDF 安装路径
IDF_PYTHON_ENV = "/usr/bin/python3" // 替换为您的 Python 虚拟环境路径(可选)
}
parameters{
choice(name: 'ENV', choices: 'intranet\ntest\n', description: '部署环境')
choice(name: 'CHIPSET', choices: 'esp32c3\nesp32c2\n', description: '芯片')
choice(name: 'VERSION_TYPE', choices: '最新版本\n指定版本\n', description: '版本指定方式')
string(name: 'VERSION', description: '版本', defaultValue: '1')
choice(name: 'LOG', choices: '打印\n屏蔽\n', description: '是否打印日志')
}
stages{
stage('Build') {
steps {
echo 'Building'
script {
echo "start"
sh "/usr/local/bin/python3 /opt/esp/esp-idf/tools/idf_tools.py install"
sh "cd $IDF_PATH && . /opt/esp/esp-idf/export.sh" // 激活 ESP-IDF 环境和 Python 虚拟环境
if (params.VERSION_TYPE == '最新版本') {
// 从 constants.h 文件中获取 MODULE_SOFT_VERSION 的值
def versionHex = sh(
returnStdout: true,
script: "cat main/config/include/constants.h | grep 'MODULE_SOFT_VERSION' | awk '{print \$3}'"
).trim()
// 将十六进制转换为十进制
def versionDecimal = versionHex.toLong(16)
// 赋值给 VERSION
params.VERSION = versionDecimal.toString()
}
sh "idf.py set-target ${params.CHIPSET}"
sh "idf.py build" // 在工作目录下运行 idf.py build 命令进行编译
String calcPath = '/www/server/tomcat/webapps/upload';
// 上传到指定路径
sh "scp ${env.WORKSPACE}/build/whr_wifi_esp32.bin root@${host['test']}:${calcPath}/${params.VERSION}"
sh "scp ${env.WORKSPACE}/build/partition_table/partition-table.bin root@${host['test']}:${calcPath}/${params.VERSION}"
// 这里可以根据需要打印下载地址
echo "烧写命令"
echo "/opt/esp/esp-idf/components/esptool_py/esptool/esptool.py -p (PORT) -b 460800 --before default_reset --after hard_reset --chip ${params.CHIPSET} write_flash --flash_mode dio --flash_size 4MB --flash_freq 60m 0x0 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin 0x10000 build/project.bin"
echo "或运行 'idf.py -p (PORT) flash'"
}
}
}
}
}
六、问题处理
1. 找不到 GLIBCXX_3.4.20
bash
Run Build Command(s):/usr/bin/ninja-build cmTC_a92c3 && [1/2] Building CXX object CMakeFiles/cmTC_a92c3.dir/testCXXCompiler.cxx.obj
FAILED: CMakeFiles/cmTC_a92c3.dir/testCXXCompiler.cxx.obj
/root/.espressif/tools/riscv32-esp-elf/esp-12.2.0_20230208/riscv32-esp-elf/bin/riscv32-esp-elf-g++ -march=rv32imc_zicsr_zifencei -o CMakeFiles/cmTC_a92c3.dir/testCXXCompiler.cxx.obj -c /var/lib/jenkins/workspace/whr-wifi-esp32/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
/root/.espressif/tools/riscv32-esp-elf/esp-12.2.0_20230208/riscv32-esp-elf/bin/../libexec/gcc/riscv32-esp-elf/12.2.0/cc1plus: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /root/.espressif/tools/riscv32-esp-elf/esp-12.2.0_20230208/riscv32-esp-elf/bin/../libexec/gcc/riscv32-esp-elf/12.2.0/cc1plus)
执行:
bash
strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX
拷一个 libstdc++.so.6.0.25到 /usr/lib64,执行:
bash
ln -s libstdc++.so.6.0.25 libstdc++.so.6
ls -l libstdc++.so.6
strings libstdc++.so.6 | grep GLIBC
2. 提示"/lib64/libc.so.6: version GLIBC_2.18' not found (required by /lib64/libstdc++.so.6)"
bash
curl -O http://ftp.gnu.org/gnu/glibc/glibc-2.18.tar.gz
tar zxf glibc-2.18.tar.gz
cd glibc-2.18/
mkdir build
cd build/
../configure --prefix=/usr
make -j2
make install