双十一趁活动买了一个树莓派,尝试接触下 Arm 平台。

  树莓派的默认存储是tf卡,以防存储掉链子,顺便配了个emmc转的tf卡。

  没想到上来就给个下马威,刷好系统后无法启动引导。


更新 EEPROM

  Raspberry Pi 4具有SPI连接的EEPROM(4MBits / 512KB),其中包含用于启动系统的代码。可以通过更新树莓派的EEPROM获得新的功能和错误修复。
  刚到手的新机器因为使用的是旧EEPROM,对USB引导或Emmc引导的兼容性不太好,所以建议到手就先更新一下。

1. 下载 Raspberry_Pi_Imager

  打开 官网下载页 按当前系统选择对应的Imager并下载。这里我下载Raspberry Pi Imager for Windows

2. 安装并运行

  安装下载好的"imager_1.4.exe",然后启动。

3. 刷写 EEPROM 固件到 SD 卡

  点击 Choose OS,向下滚动,找到 Misc utility images 点击进去后再选择 Raspberry Pi 4 EEPROM boot recovery

4. 将SD卡插入板子,开机

  通电开机后,红灯常亮,几秒种后绿灯闪烁,这就说明 EEPROM 已经更新完成。


官方 Raspberrypi OS

  官方系统的刷写教程比较简单,这里就不再详细介绍。
  官方镜像的下载链接:
http://downloads.raspberrypi.org/raspios_lite_armhf/images/
http://downloads.raspberrypi.org/raspios_lite_arm64/images/
http://downloads.raspberrypi.org/raspios_armhf/images/
http://downloads.raspberrypi.org/raspios_arm64/images/

1. Raspberry Pi 4 官方预编译固件映像

https://github.com/raspberrypi/firmware

2. Raspberry Pi 4 UEFI固件映像

https://github.com/pftf/RPi4/


安装 CentOS 8

  服务器系统我用CentOS比较习惯,所以我选择在树莓派上安装CentOS 8。

1. 官方镜像

http://isoredirect.centos.org/centos/8/isos/aarch64/
安装时会内核崩溃

2. Oracle Linux 镜像

Oracle Linux for Arm 下载
账号root,密码oracle
安装后不认板载WiFi、蓝牙(通过安装NetworkManager-wifi可解决)
不认USB网卡(mt7601u)(未找到修复方法)

3. CentOS-Userland 定制镜像

CentOS-Userland-8-aarch64-RaspberryPI-Minimal-4
账号root,密码centos
安装后不认板载WiFi、蓝牙(通过安装驱动可解决)
mutipath有问题(未找到修复方法)

CentOS-Userland-8-stream-aarch64-RaspberryPI-Minimal-4
账号root,密码centos
缺少brcmfmac43455-sdio.clm_blob

(可选)安装无线网卡固件

curl -o /lib/firmware/brcm/brcmfmac43455-sdio.bin https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm/brcmfmac43455-sdio.bin
curl -o /lib/firmware/brcm/brcmfmac43455-sdio.clm_blob https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm/brcmfmac43455-sdio.clm_blob
curl -o /lib/firmware/brcm/brcmfmac43455-sdio.txt https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm/brcmfmac43455-sdio.txt
(可选)安装蓝牙固件
curl -o /lib/firmware/brcm/BCM4345C0.hcd https://github.com/RPi-Distro/bluez-firmware/raw/master/broadcom/BCM4345C0.hcd
通过网络重装系统(CentOS-Userland-8)
wget -qO- 'http://192.168.1.2:8080/CentOS-Userland-8-stream-aarch64-RaspberryPI-Minimal-4-sda_2020-08-27.raw.xz' | xz -dc | /bin/dd of=/dev/mmcblk1;
升级系统内核(CentOS-Userland-8)
wget https://people.centos.org/pgreco/rpi_aarch64_el8/20201220125702/raspberrypi2-firmware-5.4.84-v8.1.el8.aarch64.rpm
wget https://people.centos.org/pgreco/rpi_aarch64_el8/20201220125702/raspberrypi2-kernel4-5.4.84-v8.1.el8.aarch64.rpm
wget https://people.centos.org/pgreco/rpi_aarch64_el8/20201220125702/raspberrypi2-kernel4-devel-5.4.84-v8.1.el8.aarch64.rpm
rpm -Uvh raspberrypi2-firmware-5.4.84-v8.1.el8.aarch64.rpm
rpm -Uvh raspberrypi2-kernel4-5.4.84-v8.1.el8.aarch64.rpm
rpm -Uvh raspberrypi2-kernel4-devel-5.4.84-v8.1.el8.aarch64.rpm

参考资料:

  The easies way to install vanilla CentOS 8.2 aarch64 on raspberry pi 4b
  Raspberry Pi 4B 安装 CentOS 8(64bit)


基本环境

# 设置用户默认语言为中文
echo 'export LANG=zh_CN.UTF-8' >> /etc/profile.d/custom.sh

# 设置上网代理
export http_proxy=http://192.168.10.11:1081
export https_proxy=http://192.168.10.11:1081

# 设置当前时区
timedatectl set-timezone 'Asia/Shanghai'

# 设置当前时间(默认2018年,不修改会导致SSL错误)
timedatectl set-time "2020-12-01 00:00:00"

# 磁盘扩容(Oracle Linux)
# growpart /dev/mmcblk1 3
# btrfs filesystem resize max /

# 添加常用源
# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf -y install redhat-release epel-release
dnf -y install langpacks-zh_CN glibc-langpack-zh yum-utils screen wget sysstat e2fsprogs

# 启用常用源
# dnf config-manager --set-enabled ol8_codeready_builder
dnf config-manager --set-enabled powertools

# 更新系统
dnf -y update
dnf clean all
rpm --rebuilddb

# 启用copr
# dnf -y install 'dnf-command(copr)'
# dnf -y copr enable @caddy/caddy

# 安装基础常用软件
dnf -y install cronie curl mailx nano net-tools rrdtool sudo tar telnet unzip vim-common which zip

# 安装硬件所需软件
#  pulseaudio pulseaudio-module-bluetooth
dnf -y install bluez crda NetworkManager-bluetooth NetworkManager-wifi i2c-tools

# 安装常用软件
dnf -y install git make cmake gcc gcc-c++
dnf -y install rclone sqlite mariadb-server ImageMagick policycoreutils-python-utils \
  php php-bcmath php-cli php-common php-fpm php-gd php-gmp php-json php-ldap php-mbstring \
  php-mysqlnd php-odbc php-pdo php-pgsql php-snmp php-soap php-xml php-xmlrpc

# 安装python3,默认是3.6
dnf -y install python38 python38-setuptools python38-pip python38-devel
alternatives --config python
alternatives --config python3
ln -s /usr/bin/pip3 /usr/bin/pip

磁盘扩容

# 必须在英文环境运行
export LANG=en_US.UTF-8

# 安装growpart
# dnf install -y epel-release
dnf install -y cloud-utils-growpart

# 查看分区
lsblk

# 扩容块设备
growpart /dev/mmcblk0 3

# 拉伸块设备
resize2fs /dev/mmcblk0p3
# resize2fs /dev/sda2 (ext4 文件系统)
# xfs_growfs /dev/sda2 (xfs 文件系统) azure 执行这个

# 查看是否调整成功
df -TH

修改虚拟内存

# 关闭自带虚拟内存
swapoff -a

# 分配新的虚拟内存
touch /home/swapfile
chmod 600 /home/swapfile
chattr +C /home/swapfile
dd if=/dev/zero of=/home/swapfile bs=1M count=2048
mkswap /home/swapfile
swapon /swapfile

# 开机自动挂载虚拟内存
vi /etc/fstab
/home/swapfile swap swap defaults,noatime 0 0

连接网络

# 启动服务并加载固件
/usr/bin/hciattach /dev/ttyAMA0 bcm43xx 921600 noflow

# 启动蓝牙守护程序,也可以再执行一遍加载固件
# /usr/libexec/bluetooth/bluetoothd &
/usr/bin/hciattach /dev/ttyAMA0 bcm43xx 921600 noflow

# 查看wifi状态
nmcli radio wifi

# 启用wifi
nmcli radio wifi on

# 查看设备
nmcli device

# 查看wifi
nmcli device wifi list

# 连接wifi
nmcli dev wifi con "My_WiFi_FFFF" password ""
nmcli dev wifi con "TP-LINK_4394" password "" ifname wlp1s0u1u3

# 断开wifi
nmcli device dis wlan0

# 设置代理
export http_proxy=http://192.168.1.102:1081
export https_proxy=http://192.168.1.102:1081

# 安装或更新 Frp
VERSION=`curl "https://github.com/fatedier/frp/releases/latest" | awk -F '["/]' '{print substr($9, 2)}'`
wget "https://github.com/fatedier/frp/releases/download/v${VERSION}/frp_${VERSION}_linux_arm64.tar.gz"
if [ -f "frp_${VERSION}_linux_arm64.tar.gz" ]; then
  tar -xvzf "frp_${VERSION}_linux_arm64.tar.gz"
  chmod +x "frp_${VERSION}_linux_arm64/"{frpc,frps}
  mv -f "frp_${VERSION}_linux_arm64/"{frpc,frps} "/usr/local/bin/"
  rm -rf "frp_${VERSION}_linux_arm64"*
fi

# 安装或更新 Caddy
VERSION=`curl "https://github.com/caddyserver/caddy/releases/latest" | awk -F '["/]' '{print substr($9, 2)}'`
wget https://github.com/caddyserver/caddy/releases/download/v${VERSION}/caddy_${VERSION}_linux_arm64.tar.gz
if [ -f "caddy_${VERSION}_linux_arm64.tar.gz" ]; then
  tar -xvzf "caddy_${VERSION}_linux_arm64.tar.gz"
  chmod +x "caddy"
  mv -f "caddy" "/usr/local/bin/caddy"
  rm -rf "caddy_"* README.md LICENSE
fi

# 安装或更新 Clash
VERSION=`curl "https://github.com/Dreamacro/clash/releases/latest" | awk -F '["/]' '{print substr($9, 2)}'`
wget https://github.com/Dreamacro/clash/releases/download/v${VERSION}/clash-linux-armv8-v${VERSION}.gz
if [ -f "clash-linux-armv8-v${VERSION}.gz" ]; then
  gunzip "clash-linux-armv8-v${VERSION}.gz"
  chmod +x "clash-linux-armv8-v${VERSION}"
  mv -f "clash-linux-armv8-v${VERSION}" "/usr/local/bin/clash"
fi

# 局域网设置
ip addr add 192.168.101.12/24 dev eth0
ip addr del 192.168.101.12/24 dev eth0

参考资料:

Raspberry Pi 3 Native Wifi and Bluetooth

使用ARM

Raspberry Pi上使用的ARM端库的源代码 EGL, mmal, GLESv2, vcos, openmaxil, vchiq_arm, bcm_host, WFC, OpenVG。

# 安装依赖项
dnf -y install git make cmake gcc gcc-c++

# Clone仓库
git clone https://github.com/raspberrypi/userland.git
cd userland

# 如果你使用的是32位OS,输入
./buildme

# 如果是64位OS,则输入
./buildme --aarch64

# 清理文件
cd ../
rm -rf userland
# 刷新链接库
echo "/opt/vc/lib" > /etc/ld.so.conf.d/vcgencmd.conf
ldconfig

# 测试运行
/opt/vc/bin/vcgencmd measure_temp | sed 's/temp=//g'

- 列出指定的配置参数.
/opt/vc/bin/vcgencmd get_config arm_freq
/opt/vc/bin/vcgencmd get_config
- 列出所有已设置的整形配置参数(非零)
/opt/vc/bin/vcgencmd get_config int
- 列出所有已设置的字符型配置参数(非零)
/opt/vc/bin/vcgencmd get_config str

https://shumeipai.nxez.com/2015/11/23/raspberry-pi-configuration-file-config-txt-nstructions.html


# 获取CPU温度
cat /sys/class/thermal/thermal_zone0/temp

# 获取当前CPU频率
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq

# 获取GPU温度
/opt/vc/bin/vcgencmd measure_temp | sed 's/temp=//g'

使用I2C

### 1.启用I2C
编辑config.txt,然后重启

### I2C是否启用
lsmod | grep i2c

### 2.安装I2C库和工具
dnf install i2c-tools

### 当连接上I2C设备后,可以通过以下命令查看
i2cdetect -y -a 1

### 老版都请使用,以下命令
i2cdetect -y -a 0

var="$(xxd /sys/class/i2c-adapter/i2c-1/of_node/clock-frequency | awk -F': ' '{print $2}')"
var=${var//[[:blank:].\}]/}
printf "I2C Clock Rate: %d Hz\n" 0x$var

# SD3078-rtc
dnf install kernel-headers kernel-uek-devel
https://raw.githubusercontent.com/PiSugar/pisugar-power-manager-rs/911526a35ff8aa3c02d9f901b876af515a4a27b0/pisugar-module/Makefile
https://raw.githubusercontent.com/PiSugar/pisugar-power-manager-rs/911526a35ff8aa3c02d9f901b876af515a4a27b0/pisugar-module/rtc-sd3078.c
# Oracle linux 需要修改编译路经
# sed -i 's#linux-headers-#kernels/#g' rtc-sd3078.c
make

insmod rtc-sd3078.ko
echo sd3078 0x32 > /sys/class/i2c-adapter/i2c-1/new_device


hwclock --localtime 硬件时钟真正的时间
hwclock -r 显示RTC时间
hwclock -s 通过RTC时间设置系统时间
hwclock -w 把系统时间写入RTC
hwclock --set --date="2020-04-09 14:01:08" 修改RTC时间为任意值
hwclock -h 获取帮助

系统备份

# 相关资料
https://blog.csdn.net/lzjsqn/article/details/72058293
https://raw.githubusercontent.com/nanhantianyi/rpi-backup

# Clone脚本
wget https://raw.githubusercontent.com/nanhantianyi/rpi-backup/master/back.sh

# 安装依赖项
sudo pacman -Sy && pacman -S dosfstools parted multipath-tools rsync

# 开始备份
./back.sh youImageName.img

参考资料:

树莓派镜像备份与恢复
rpi-backup