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

Conversation

sairon
Copy link
Member

@sairon sairon commented Nov 18, 2024

As stated in the docs [1], post-install hook is not executed if the slot already has an install hook defined. Merge the post-install hook with the install hook to fix CM5 migration for Yellow.

[1] https://rauc.readthedocs.io/en/latest/using.html#slot-hooks

Summary by CodeRabbit

  • New Features

    • Added support for the "CM5" configuration in the boot installation process for "haos-yellow" systems.
  • Bug Fixes

    • Streamlined the boot image installation process by simplifying the hook configuration.
  • Refactor

    • Consolidated CM5 support logic into the main installation function, removing the need for a separate post-install function.

As stated in the docs [1], post-install hook is not executed if the slot
already has an install hook defined. Merge the post-install hook with the
install hook to fix CM5 migration for Yellow.

[1] https://rauc.readthedocs.io/en/latest/using.html#slot-hooks
@sairon sairon added the board/yellow Home Assistant Yellow label Nov 18, 2024
@sairon sairon requested a review from agners November 18, 2024 10:31
Copy link

coderabbitai bot commented Nov 18, 2024

📝 Walkthrough

Walkthrough

The changes involve modifications to the manifest.raucm.gtpl configuration file and the rauc-hook script. In the configuration file, the hooks for the boot image have been simplified to consistently use hooks=install;, while the kernel and SPL sections retain their existing logic. In the script, the install_boot function has been updated to support the "CM5" configuration for "haos-yellow," consolidating related logic and removing the separate post_install_boot function. Overall, the changes streamline the installation process for the boot image.

Changes

File Change Summary
buildroot-external/ota/manifest.raucm.gtpl Simplified boot image hooks to hooks=install;, removed post-install for "haos-yellow".
buildroot-external/ota/rauc-hook Modified install_boot() to add CM5 support for "haos-yellow"; removed post_install_boot().

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant RAUC
    participant Config
    participant Boot

    User->>RAUC: Initiate installation
    RAUC->>Config: Check boot image hooks
    Config->>RAUC: Return hooks=install;
    RAUC->>Boot: Install boot image
    Boot->>RAUC: Boot image installed
    RAUC->>User: Installation complete
Loading
sequenceDiagram
    participant User
    participant RAUC
    participant Config
    participant Boot

    User->>RAUC: Initiate installation
    RAUC->>Config: Check for CM5 configuration
    Config->>RAUC: CM5 section not present
    RAUC->>Config: Modify config.txt for CM5
    Config->>RAUC: Config updated
    RAUC->>Boot: Install boot image
    Boot->>RAUC: Boot image installed
    RAUC->>User: Installation complete
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
buildroot-external/ota/rauc-hook (1)

Line range hint 192-194: Critical: Remove reference to non-existent post_install_boot function

The post_install_boot function has been removed, but it's still being called in the slot-post-install section. This will cause the script to fail when processing boot slot post-installation.

Apply this fix:

     slot-post-install)
-        if [ "${RAUC_SLOT_CLASS}" = "boot" ]; then
-            post_install_boot
-        fi
         if [ "${RAUC_SLOT_CLASS}" = "kernel" ]; then
             post_install_kernel
         fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b9e66fb and da26806.

📒 Files selected for processing (2)
  • buildroot-external/ota/manifest.raucm.gtpl (0 hunks)
  • buildroot-external/ota/rauc-hook (1 hunks)
💤 Files with no reviewable changes (1)
  • buildroot-external/ota/manifest.raucm.gtpl
🔇 Additional comments (1)
buildroot-external/ota/rauc-hook (1)

Line range hint 177-199: Verify hook merging approach with RAUC documentation

The approach of merging the post-install hook with the install hook aligns with the PR objectives. However, we should verify that this doesn't conflict with RAUC's expected behavior for other scenarios.

Let's verify the RAUC documentation and usage:

✅ Verification successful

Let me gather more information about RAUC hooks to make a well-informed decision.


Let me check the actual implementation of these hooks and their dependencies to understand the impact of merging them.


Merging post-install hook with install hook is safe in this context

The verification shows that:

  • The hooks are only used within the rauc-hook script and have no external dependencies
  • The install_boot and post_install_boot functions are self-contained
  • The hook merging only affects the boot slot class, keeping other slot classes (like 'spl' and 'kernel') unchanged
  • No other files in the codebase reference these hooks

The approach of merging the post-install functionality into the install hook is safe as it maintains the same operational sequence while reducing complexity.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for RAUC hook documentation and usage patterns

# Search for RAUC hook documentation files
fd -t f -e md -e rst . | xargs rg -l "post-install.*hook"

# Search for similar hook merging patterns in the codebase
rg -p "slot-(install|post-install)"

Length of output: 179


Script:

#!/bin/bash
# Search for RAUC hook documentation and implementation patterns
# Look for hook-related content in documentation files
fd README . | xargs rg -i "rauc.*hook|hook.*rauc"

# Look for hook implementation patterns
rg -A 5 "slot-(install|post-install)" buildroot-external/ota/rauc-hook

# Search for any hook-related comments or documentation
rg -i "hook" buildroot-external/ota/rauc-hook

Length of output: 562


Script:

#!/bin/bash
# Check the implementation of install_boot and post_install_boot functions
rg -A 10 "^install_boot\(\)" buildroot-external/ota/rauc-hook
rg -A 10 "^post_install_boot\(\)" buildroot-external/ota/rauc-hook

# Check if there are any other files referencing these hooks
rg "install_boot|post_install_boot" --type-not sh

Length of output: 614

Comment on lines +46 to +54
# 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
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

@sairon sairon merged commit 78cdaab into dev Nov 18, 2024
3 checks passed
@sairon sairon deleted the move-yellow-rauc-post-install-to-install branch November 18, 2024 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
board/yellow Home Assistant Yellow cla-signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants