Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Yellow's RAUC post-install hook with the install hook #3678

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions buildroot-external/ota/manifest.raucm.gtpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ hooks=install-check;

[image.boot]
filename=boot.vfat
{{- if eq (env "ota_compatible") "haos-yellow" }}
hooks=install;post-install;
{{- else }}
hooks=install;
{{- end }}

[image.kernel]
filename=kernel.img
Expand Down
29 changes: 10 additions & 19 deletions buildroot-external/ota/rauc-hook
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ install_boot() {
cp -f "${BOOT_TMP}"/*.txt "${BOOT_MNT}/" || true
cp -f "${BOOT_TMP}"/grubenv "${BOOT_MNT}"/EFI/BOOT/ || true
fi

# Add CM5 support for Yellow. Can be removed in HAOS 15.
if [ "$RAUC_SYSTEM_COMPATIBLE" = "haos-yellow" ]; then
if ! grep -q "\[cm5\]" "${BOOT_MNT}/config.txt"; then
echo "Adding CM5 config to config.txt"

# Remove old single device_tree config and add CM-specific ones
sed -i '/device_tree=bcm2711-rpi-cm4-ha-yellow.dtb/d; s/\[all\]/\[cm4\]\ndevice_tree=bcm2711-rpi-cm4-ha-yellow.dtb\n\n\[cm5\]\ndevice_tree=bcm2712-rpi-cm5-ha-yellow.dtb\n\n\[all\]/' "${BOOT_MNT}/config.txt"
fi
fi
Comment on lines +46 to +54
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling and backup mechanism for config.txt modifications

While the CM5 support addition is good, there are several reliability concerns:

  1. The sed operation is complex and lacks error checking
  2. No backup is created before modifying config.txt
  3. No validation of the final content

Consider this safer approach:

 if [ "$RAUC_SYSTEM_COMPATIBLE" = "haos-yellow" ]; then
     if ! grep -q "\[cm5\]" "${BOOT_MNT}/config.txt"; then
         echo "Adding CM5 config to config.txt"
+        # Create backup
+        cp "${BOOT_MNT}/config.txt" "${BOOT_MNT}/config.txt.bak"
+        
+        # Remove old device tree config
+        sed -i '/device_tree=bcm2711-rpi-cm4-ha-yellow.dtb/d' "${BOOT_MNT}/config.txt" || {
+            echo "Failed to remove old device tree config"
+            cp "${BOOT_MNT}/config.txt.bak" "${BOOT_MNT}/config.txt"
+            exit 1
+        }
+        
+        # Add new CM-specific configs
+        sed -i 's/\[all\]/[cm4]\ndevice_tree=bcm2711-rpi-cm4-ha-yellow.dtb\n\n[cm5]\ndevice_tree=bcm2712-rpi-cm5-ha-yellow.dtb\n\n[all]/' "${BOOT_MNT}/config.txt" || {
+            echo "Failed to add CM-specific configs"
+            cp "${BOOT_MNT}/config.txt.bak" "${BOOT_MNT}/config.txt"
+            exit 1
+        }
+        
+        # Verify the changes
+        if ! grep -q "\[cm5\]" "${BOOT_MNT}/config.txt" || ! grep -q "bcm2712-rpi-cm5-ha-yellow.dtb" "${BOOT_MNT}/config.txt"; then
+            echo "Failed to verify CM5 configuration"
+            cp "${BOOT_MNT}/config.txt.bak" "${BOOT_MNT}/config.txt"
+            exit 1
+        }
     fi
 fi

Would you like me to create a GitHub issue to track the removal of this code in HAOS 15?

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Add CM5 support for Yellow. Can be removed in HAOS 15.
if [ "$RAUC_SYSTEM_COMPATIBLE" = "haos-yellow" ]; then
if ! grep -q "\[cm5\]" "${BOOT_MNT}/config.txt"; then
echo "Adding CM5 config to config.txt"
# Remove old single device_tree config and add CM-specific ones
sed -i '/device_tree=bcm2711-rpi-cm4-ha-yellow.dtb/d; s/\[all\]/\[cm4\]\ndevice_tree=bcm2711-rpi-cm4-ha-yellow.dtb\n\n\[cm5\]\ndevice_tree=bcm2712-rpi-cm5-ha-yellow.dtb\n\n\[all\]/' "${BOOT_MNT}/config.txt"
fi
fi
# Add CM5 support for Yellow. Can be removed in HAOS 15.
if [ "$RAUC_SYSTEM_COMPATIBLE" = "haos-yellow" ]; then
if ! grep -q "\[cm5\]" "${BOOT_MNT}/config.txt"; then
echo "Adding CM5 config to config.txt"
# Create backup
cp "${BOOT_MNT}/config.txt" "${BOOT_MNT}/config.txt.bak"
# Remove old device tree config
sed -i '/device_tree=bcm2711-rpi-cm4-ha-yellow.dtb/d' "${BOOT_MNT}/config.txt" || {
echo "Failed to remove old device tree config"
cp "${BOOT_MNT}/config.txt.bak" "${BOOT_MNT}/config.txt"
exit 1
}
# Add new CM-specific configs
sed -i 's/\[all\]/[cm4]\ndevice_tree=bcm2711-rpi-cm4-ha-yellow.dtb\n\n[cm5]\ndevice_tree=bcm2712-rpi-cm5-ha-yellow.dtb\n\n[all]/' "${BOOT_MNT}/config.txt" || {
echo "Failed to add CM-specific configs"
cp "${BOOT_MNT}/config.txt.bak" "${BOOT_MNT}/config.txt"
exit 1
}
# Verify the changes
if ! grep -q "\[cm5\]" "${BOOT_MNT}/config.txt" || ! grep -q "bcm2712-rpi-cm5-ha-yellow.dtb" "${BOOT_MNT}/config.txt"; then
echo "Failed to verify CM5 configuration"
cp "${BOOT_MNT}/config.txt.bak" "${BOOT_MNT}/config.txt"
exit 1
}
fi
fi

}

install_spl() {
Expand Down Expand Up @@ -88,25 +98,6 @@ check_grubenv() {
fi
}

post_install_boot() {
BOOT_MNT=/mnt/boot

# Add CM5 support for Yellow. Can be removed in HAOS 15. Make sure manifest.raucm.gtpl is updated.
if [ "$RAUC_SYSTEM_COMPATIBLE" = "haos-yellow" ]; then
# Mount boot
if ! systemctl -q is-active mnt-boot.mount; then
systemctl start mnt-boot.mount
fi

if ! grep -q "\[cm5\]" "${BOOT_MNT}/config.txt"; then
echo "Adding CM5 config to config.txt"

# Remove old single device_tree config and add CM-specific ones
sed -i '/device_tree=bcm2711-rpi-cm4-ha-yellow.dtb/d; s/\[all\]/\[cm4\]\ndevice_tree=bcm2711-rpi-cm4-ha-yellow.dtb\n\n\[cm5\]\ndevice_tree=bcm2712-rpi-cm5-ha-yellow.dtb\n\n\[all\]/' "${BOOT_MNT}/config.txt"
fi
fi
}

post_install_kernel() {
BOOT_MNT=/mnt/boot

Expand Down