Skip to content

Extension: UFS for image generation pipeline #8474

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HeyMeco
Copy link
Contributor

@HeyMeco HeyMeco commented Aug 8, 2025

Description

This extension checks if the installed sfdisk version supports declaring sector sizes (version 2.41 or newer) and sets up configuration variables needed to create a UFS-aligned images
Related to #8053

How Has This Been Tested?

  • Working on Debian Trixie with sfdisk 2.41
  • Correctly: Not working on Ubuntu Noble with 2.39
  • Correctly: Not working on Ubuntu Noble with 2.39 util-linux but no fdisk

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

@HeyMeco HeyMeco requested a review from igorpecovnik as a code owner August 8, 2025 18:51
@github-actions github-actions bot added 08 Milestone: Third quarter release size/small PR with less then 50 lines Needs review Seeking for review Framework Framework components and removed size/small PR with less then 50 lines labels Aug 8, 2025
Copy link
Contributor

coderabbitai bot commented Aug 8, 2025

Walkthrough

A new shell function, extension_prepare_config__ufs, has been added to the extensions/ufs.sh file. This function checks for the presence of the sfdisk utility and verifies that its version is at least 2.41, which is necessary for UFS support. If the requirements are met, it appends -ufs to the EXTRA_IMAGE_SUFFIXES array and sets the SECTOR_SIZE variable to 4096. The function is designed to prepare configurations for UFS-aligned image creation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Suggested labels

Ready to merge, 05, size/small

Suggested reviewers

  • HeyMeco
  • igorpecovnik
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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 explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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 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.

@coderabbitai coderabbitai bot added 05 Milestone: Second quarter release Ready to merge Reviewed, tested and ready for merge size/small PR with less then 50 lines labels Aug 8, 2025
Copy link
Contributor

@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

🧹 Nitpick comments (4)
extensions/ufs.sh (4)

9-11: Version gating logic looks good; consider slightly tighter messaging.

Comparison via linux-version is correct. Minor wording nit in message to align with package naming.

-        exit_with_error "UFS extension requires sfdisk >= 2.41 (from util-linux). Current version: ${sfdisk_version}"
+        exit_with_error "UFS extension requires util-linux (sfdisk) >= 2.41. Detected: ${sfdisk_version}"

12-12: Avoid duplicate “-ufs” suffix if the hook runs more than once.

Be defensive and only append if not present.

-    EXTRA_IMAGE_SUFFIXES+=("-ufs")
+    if [[ " ${EXTRA_IMAGE_SUFFIXES[*]} " != *" -ufs "* ]]; then
+        EXTRA_IMAGE_SUFFIXES+=("-ufs")
+    fi

13-13: Don’t overwrite SECTOR_SIZE if already set; keep it global.

Respect an existing value and still ensure global scope.

-    declare -g SECTOR_SIZE=4096
+    if [[ -z ${SECTOR_SIZE-} ]]; then
+        declare -g SECTOR_SIZE=4096
+    fi

1-1: Clarify the host requirement wording.

This is a util-linux (sfdisk) 2.41+ requirement; Debian 13 (Trixie) is an example host that satisfies it.

-# Create UFS aligned image (requires >= Debian 13 (Trixie) Host)
+# Create UFS-aligned image (requires util-linux/sfdisk >= 2.41; e.g., Debian 13 (Trixie) or newer)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 534b97f and 0bf6a12.

📒 Files selected for processing (1)
  • extensions/ufs.sh (1 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: EvilOlaf
PR: armbian/build#8428
File: config/boards/lckfb-taishanpi.csc:5-9
Timestamp: 2025-07-25T03:51:50.830Z
Learning: When reviewing PRs in the Armbian build system, U-Boot defconfig files and patches may be added as part of the PR changes but might not be visible in the current repository clone state during review. It's important to check the actual PR file changes directly via GitHub API (https://api.github.com/repos/armbian/build/pulls/{pr_number}/files) to get the complete picture of what files are being added or modified, especially for U-Boot patches that will be applied during the build process.
Learnt from: pyavitz
PR: armbian/build#8421
File: config/kernel/linux-sunxi64-edge.config:2664-2671
Timestamp: 2025-07-27T13:03:53.146Z
Learning: In the Armbian build system's kernel configuration, when CONFIG_EXT2_FS=y and CONFIG_EXT3_FS=y are both set to built-in, EXT4 filesystem support becomes automatically available/hard-coded without requiring an explicit CONFIG_EXT4_FS line in the configuration file. This is specific to how Armbian handles kernel configuration and differs from typical standalone Linux kernel configuration behavior.
Learnt from: leggewie
PR: armbian/build#8133
File: extensions/apa.sh:1-2
Timestamp: 2025-04-28T08:27:26.890Z
Learning: In the Armbian build system, extension scripts in the `extensions/` directory contain hook functions and are meant to be sourced, not executed directly. These scripts don't require a shebang or `set -euo pipefail`.
📚 Learning: 2025-06-14T05:53:10.627Z
Learnt from: EvilOlaf
PR: armbian/build#8298
File: extensions/https_proxy.sh:1-9
Timestamp: 2025-06-14T05:53:10.627Z
Learning: In Armbian build framework, extensions are loaded and executed via lib/functions/general/extensions.sh using call_extension_method. The framework sets set -o errexit and set -o errtrace globally, and individual commands run with pipefail protection through the command execution functions.

Applied to files:

  • extensions/ufs.sh
📚 Learning: 2025-04-28T08:27:26.890Z
Learnt from: leggewie
PR: armbian/build#8133
File: extensions/apa.sh:1-2
Timestamp: 2025-04-28T08:27:26.890Z
Learning: In the Armbian build system, extension scripts in the `extensions/` directory contain hook functions and are meant to be sourced, not executed directly. These scripts don't require a shebang or `set -euo pipefail`.

Applied to files:

  • extensions/ufs.sh
📚 Learning: 2025-07-27T13:03:53.146Z
Learnt from: pyavitz
PR: armbian/build#8421
File: config/kernel/linux-sunxi64-edge.config:2664-2671
Timestamp: 2025-07-27T13:03:53.146Z
Learning: In the Armbian build system's kernel configuration, when CONFIG_EXT2_FS=y and CONFIG_EXT3_FS=y are both set to built-in, EXT4 filesystem support becomes automatically available/hard-coded without requiring an explicit CONFIG_EXT4_FS line in the configuration file. This is specific to how Armbian handles kernel configuration and differs from typical standalone Linux kernel configuration behavior.

Applied to files:

  • extensions/ufs.sh
📚 Learning: 2025-06-22T00:45:26.182Z
Learnt from: djurny
PR: armbian/build#8315
File: lib/functions/rootfs/distro-agnostic.sh:54-68
Timestamp: 2025-06-22T00:45:26.182Z
Learning: In Armbian build system, external command dependencies like envsubst are handled by adding the required packages (e.g., gettext for envsubst) to host_dependencies in adaptative_prepare_host_dependencies function in lib/functions/host/prepare-host.sh, rather than checking command availability at runtime.

Applied to files:

  • extensions/ufs.sh

Comment on lines +5 to +8
sfdisk_version=$(sfdisk --version | awk '/util-linux/ {print $NF}')
if [[ -z "${sfdisk_version}" ]]; then
exit_with_error "sfdisk not found - please install util-linux / fdisk >= 2.41 package"
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Guard against errexit on missing sfdisk; use a presence check before version parsing.

With errexit enabled globally, sfdisk --version inside $(...) will terminate the shell if sfdisk is absent. Guard presence first and sanitize version parsing.

-    sfdisk_version=$(sfdisk --version | awk '/util-linux/ {print $NF}')
-    if [[ -z "${sfdisk_version}" ]]; then
-        exit_with_error "sfdisk not found - please install util-linux / fdisk >= 2.41 package"
-    fi
+    if ! command -v sfdisk >/dev/null 2>&1; then
+        exit_with_error "sfdisk not found. Please install util-linux (provides sfdisk) >= 2.41."
+    fi
+    # Extract the util-linux version and strip any non-numeric characters for robustness
+    sfdisk_version="$(sfdisk --version 2>/dev/null | awk '/util-linux/ {print $NF}' | tr -cd '0-9.')"
+    if [[ -z "${sfdisk_version}" ]]; then
+        exit_with_error "Unable to determine util-linux version from 'sfdisk --version'."
+    fi
📝 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
sfdisk_version=$(sfdisk --version | awk '/util-linux/ {print $NF}')
if [[ -z "${sfdisk_version}" ]]; then
exit_with_error "sfdisk not found - please install util-linux / fdisk >= 2.41 package"
fi
if ! command -v sfdisk >/dev/null 2>&1; then
exit_with_error "sfdisk not found. Please install util-linux (provides sfdisk) >= 2.41."
fi
# Extract the util-linux version and strip any non-numeric characters for robustness
sfdisk_version="$(sfdisk --version 2>/dev/null | awk '/util-linux/ {print $NF}' | tr -cd '0-9.')"
if [[ -z "${sfdisk_version}" ]]; then
exit_with_error "Unable to determine util-linux version from 'sfdisk --version'."
fi
🤖 Prompt for AI Agents
In extensions/ufs.sh around lines 5 to 8, the script runs `sfdisk --version`
directly which causes the shell to exit if sfdisk is missing due to errexit. To
fix this, first check if the sfdisk command exists using a command presence
check like `command -v sfdisk` before attempting to parse its version. This
prevents the script from exiting prematurely and allows for a proper error
message if sfdisk is not installed.

@leggewie
Copy link
Collaborator

" Correctly: Not working on Ubuntu Noble with 2.39 "

Am I reading this correctly, your extension does not work on Ubuntu Noble compile host? That would be a dealbreaker IMHO.

@HeyMeco
Copy link
Contributor Author

HeyMeco commented Aug 10, 2025

@leggewie

That would be a dealbreaker IMHO.

here it isn’t. The code regarding armbian is already merged. This Extension just makes it "easier" to integrate into CI for automated UFS builds. Also the code in the util-linux tools is comparatively very new that’s why it just isn’t available in pre Debian 13 distro's. I tried opening an issue with Canonical for Noble but they’re not interested in backporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
05 Milestone: Second quarter release 08 Milestone: Third quarter release Framework Framework components Needs review Seeking for review Ready to merge Reviewed, tested and ready for merge size/small PR with less then 50 lines
Development

Successfully merging this pull request may close these issues.

3 participants