> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OTA 与升级注意事项

在 RT 系统上进行 OTA 更新和手动内核升级,需要在标准内核升级流程之外执行额外步骤。RT 调优配置不会自动保留,升级后的延迟基线必须重新验证,然后才能将设备恢复到生产环境。

## 升级工作流程

Qualcomm<sup>®</sup> Linux 上的 OTA 更新会替换 ESP 上的 UKI 镜像,并在适用时替换 `dtb_a` 分区中的 DTB。标准内核和 RT 内核的刷写流程完全相同。

### 1. 记录当前的 RT 内核版本

升级前,记录正在运行的内核版本和最坏情况延迟作为基线:

```bash theme={null}
uname -r
cat /proc/version
```

运行一次简短的周期性测试,建立升级前的延迟基线:

```bash theme={null}
cyclictest -a 7 -t 1 -m -l 10000 -i 1000 -p 99 -h 100
```

记录输出中的 `Max` 延迟值。

### 2. 刷写新的 RT 镜像

**通过 Yocto 构建:**

```bash theme={null}
# Build the new RT image
kas shell meta-qcom/ci/<board>.yml:meta-qcom/ci/linux-qcom-rt-6.18.yml:meta-qcom/ci/qcom-distro.yml
bitbake qcom-multimedia-image

# Flash both ESP and DTB partitions
cd build/tmp/deploy/images/<Machine>/<Image>-*.rootfs.qcomflash/
fastboot flash efi efi.bin
fastboot flash dtb_a dtb.bin
```

**通过独立的 ESP 更新:**

```bash theme={null}
fastboot flash efi efi.bin
fastboot flash dtb_a dtb.bin
```

### 3. 重启并验证更新后的内核

```bash theme={null}
fastboot reboot
uname -r   # Confirm the new -rt version string
```

### 4. 重新应用 RT 调优并运行升级后验证

RT 调优设置在重启后不会保留。在运行验证之前,请手动或通过调优服务(见下文)重新应用它们:

```bash theme={null}
cyclictest -a 7 -t 1 -m -l 100000000 -i 1000 -p 99 -h 100
```

将 `Max` 延迟与升级前的基线进行比较。出现回退表明存在配置或内核问题。请参阅
[RT 验证与已知限制](./rt-validation-and-known-limitations)。

## 使 RT 调优在重启后持久化

RT 调优命令是一次性的,仅作用于正在运行的系统,重启后即失效。要在每次启动后自动重新应用调优,请将调优命令打包为一个 systemd 服务:

**1. 创建调优脚本:**

```bash theme={null}
cat > /usr/local/bin/rt-tuning.sh << 'EOF'
#!/bin/sh
# Disable timer migration
echo 0 > /proc/sys/kernel/timer_migration

# Affine workqueues to housekeeping CPUs (CPUs 0-6 on QCS6490/IQ-9075/IQ-615)
for wq in /sys/devices/virtual/workqueue/*; do
    [ -w "$wq/cpumask" ] && echo 7F > "$wq/cpumask"
done

# Set all CPUs to performance governor
for policy in /sys/devices/system/cpu/cpufreq/policy*; do
    [ -w "$policy/scaling_governor" ] && echo performance > "$policy/scaling_governor"
done

# Disable RT accounting/throttling
echo -1 > /proc/sys/kernel/sched_rt_runtime_us

# Set IRQ affinity to housekeeping CPUs 0-6
ALLOW_CPUS="0,1,2,3,4,5,6"
cpu_list_to_mask() {
    MASK=0
    for cpu in $(echo $1 | tr ',' ' '); do
        MASK=$((MASK | (1 << cpu)))
    done
    printf "%x\n" "$MASK"
}
MASK=$(cpu_list_to_mask "$ALLOW_CPUS")
for irq in /proc/irq/[0-9]*; do
    smp_file="$irq/smp_affinity"
    [ -w "$smp_file" ] && echo "$MASK" > "$smp_file" 2>/dev/null
done
EOF
chmod +x /usr/local/bin/rt-tuning.sh
```

**2. 创建 systemd 单元文件:**

```ini theme={null}
# /etc/systemd/system/rt-tuning.service
[Unit]
Description=RT kernel tuning
After=multi-user.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/rt-tuning.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
```

**3. 启用服务:**

```bash theme={null}
systemctl enable rt-tuning.service
systemctl start rt-tuning.service
```

对于 IQ-8275,请调整工作队列掩码和 IRQ 亲和性 CPU 列表以匹配平台拓扑(CPU 0-2、4-7;掩码 `F7`)。IQ-8275 专用的调优命令请参阅
[RT 验证与已知限制](./rt-validation-and-known-limitations)。

## 已知的升级约束

**内核与 DTB 版本对齐**

始终同时刷写 `dtb.bin` 和 `efi.bin`。内核与 DTB 版本不匹配可能导致设备树绑定失败和启动错误。

**Initramfs**

如果 initramfs 是为 RT 构建定制的(例如,在早期启动阶段运行调优脚本),升级内核版本时请重新构建它。针对旧内核构建的过期 initramfs 可能无法加载所需的模块。

**PREEMPT\_RT 配置片段**

每次内核版本升级后,都必须检查添加到 `linux-qcom-rt_6.18.bb` 的自定义 `.cfg` Kconfig 片段。选项可能被重命名、移除或依赖关系发生变化。不匹配的片段会导致 Yocto 构建警告(`Fragment ... references unknown config`)或静默失效。

**安全启动(Secure boot)**

如果设备配置为安全启动,新的 UKI 在刷写前必须使用正确的密钥签名。未签名或签名不正确的 UKI 会在启动时被 UEFI 固件拒绝。请参阅
[UEFI 与 systemd-boot](./uefi-and-systemd-boot)。
