Skip to content

Conversation

@efectn
Copy link
Member

@efectn efectn commented Apr 26, 2025

Description

This PR adds multiple SPI image selection option to armbian-install for rockchip boards when there are rkspi_loader*.img files more than one. This is useful for boards like Orange Pi 5 as there should be different SPI image for mSata boot scenario.

image

GitHub issue reference:
Jira reference number [AR-9999]

Documentation summary for feature / change

Please delete this section if entry to main documentation is not needed.

If documentation entry is predicted, please provide key elements for further implementation into main documentation and set label to "Needs Documentation". You are welcome to open a PR to documentation or you can leave following information for technical writer:

  • short description (copy / paste of PR title)
  • summary (description relevant for end users)
  • example of usage (how to see this in function)

How Has This Been Tested?

  • Tested both SPI images writing with OPi5.
  • Tested single SPI image case.

Checklist:

Please delete options that are not relevant.

  • 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

@efectn efectn requested a review from igorpecovnik as a code owner April 26, 2025 10:49
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 26, 2025

Walkthrough

The function write_uboot_platform_mtd in the rockchip64_common.inc configuration file was updated to support handling multiple SPI loader images. Instead of only processing a single rkspi_loader.img file, the function now searches for all files matching the pattern rkspi_loader*.img within the source directory. If no matching files are found, the script prints an error and exits. If exactly one matching file is found, it is written directly to the target device. If multiple matching files are detected, the function presents a dialog menu to the user, allowing them to select the desired SPI image. The dialog displays a radiolist with numbered entries and filenames, and includes a backtitle referencing the Armbian board name and website. If the user cancels the selection, the script prints an error and exits. The output and errors from the dd command are now redirected to /dev/null. The function's signature remains unchanged.

Suggested labels

ready to merge


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

@github-actions github-actions bot added 05 Milestone: Second quarter release size/small PR with less then 50 lines Needs review Seeking for review Hardware Hardware related like kernel, U-Boot, ... labels Apr 26, 2025
@coderabbitai coderabbitai bot added the Ready to merge Reviewed, tested and ready for merge label Apr 26, 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: 0

🧹 Nitpick comments (1)
config/sources/families/include/rockchip64_common.inc (1)

334-339: Consider adding error handling for dd command

While the implementation correctly handles dialog cancellation, it would be beneficial to check for errors from the dd command to ensure the write operation succeeded.

if [ $? -eq 0 ]; then
-    dd if=$1/${MENU_ITEMS[($CHOICE*3)-2]} of=$2 conv=notrunc status=none > /dev/null 2>&1
+    if ! dd if=$1/${MENU_ITEMS[($CHOICE*3)-2]} of=$2 conv=notrunc status=none > /dev/null 2>&1; then
+        echo "Error writing SPI image to device."
+        exit 1
+    fi
else
    echo "No SPI image chosen."
    exit 1
fi
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a4b1edd and 008e535.

📒 Files selected for processing (1)
  • config/sources/families/include/rockchip64_common.inc (1 hunks)
🔇 Additional comments (5)
config/sources/families/include/rockchip64_common.inc (5)

302-306: LGTM: Effective file search pattern for SPI images.

The implementation correctly searches for SPI images using a wildcard pattern, allowing it to find multiple SPI loader files. This is essential for supporting different boot scenarios on boards like the Orange Pi 5.


308-317: LGTM: Clean array implementation for menu items.

Good implementation using a while loop to populate the menu items array with file indices and basenames. The array structure (index, filename, empty description) aligns well with dialog's radiolist format requirements.


319-322: LGTM: Smart optimization for single image case.

Good optimization to skip the dialog when only one SPI image is found, improving user experience. The implementation correctly uses the index value to determine when only one image is present.


324-333: LGTM: Nice user-friendly dialog implementation.

The dialog implementation is well-structured with a descriptive title and proper Armbian branding in the backtitle. Good practice to source the board information from /etc/armbian-release to customize the interface.


302-340: Great implementation of multiple SPI images support.

The implementation successfully addresses the requirements in PR objectives for supporting multiple SPI images on rockchip boards. The code provides a user-friendly selection interface while maintaining backward compatibility for single image scenarios. The dialog UI is well-structured and the calculations for menu item selection are correct.

@efectn efectn mentioned this pull request Apr 26, 2025
10 tasks
Copy link
Member

@rpardini rpardini left a comment

Choose a reason for hiding this comment

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

Good stuff, the SATA variants have long been hidden despite available.

The only downside I can see here is that the function becomes intrinsically tied to a TUI using dialog, which I think would be best handled by the caller utility (armbian-install or some "configng").

If this affected the mmc code path I'd be against it, as I know many different scripts consume write_uboot_platform directly, I'd say the TUI would be blocker -- many callers do not expect to be interactive -- since that TUI is in decrepit state, and this only affects the mtd code path, I think it's fine.

((i++))
done <<< "$FILES"

# If there is only one image, we can skip the dialog
Copy link
Member

Choose a reason for hiding this comment

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

Also skip and log if

  • terminal not interactive (eg [[ -t 0 ]] for stdin if I am not mistaken)
  • dialog not available

@github-actions github-actions bot removed the Needs review Seeking for review label Apr 26, 2025
@efectn
Copy link
Member Author

efectn commented Apr 26, 2025

Good stuff, the SATA variants have long been hidden despite available.

The only downside I can see here is that the function becomes intrinsically tied to a TUI using dialog, which I think would be best handled by the caller utility (armbian-install or some "configng").

If this affected the mmc code path I'd be against it, as I know many different scripts consume write_uboot_platform directly, I'd say the TUI would be blocker -- many callers do not expect to be interactive -- since that TUI is in decrepit state, and this only affects the mtd code path, I think it's fine.

Yes agree, i was also hesitant to make this global for all rockchip boards. It might be better to add this to armbian-install and keep platform codes minimal. I just didn't want to mess with legacy installer code, but will investigate it.

@rpardini
Copy link
Member

I just didn't want to mess with legacy installer code,

I feel you. I've been there, and it's not looking pretty. A full rewrite (using a proper TUI framework eg Python's rich or textual) is easier IMHO.

On armbian/build side I've started writing out some metadata, but it still relies on bash functions to do the actual writing (burden of the declare -f magic involved in the whole thing here).

Also the way the image-builder ends up consuming all this is just bizarre (through the chroot's installed .deb!), not to mention the whole UBOOT_TARGET_MAP-hell.

but will investigate it.

Sincerely, I'd just merge this change as-is and we can coordinate the long-needed structural changes separately.

@efectn
Copy link
Member Author

efectn commented Apr 27, 2025

Sincerely, I'd just merge this change as-is and we can coordinate the long-needed structural changes separately.

OK then, lets keep this as-is until armbian/configng#384 is merged.

Also the way the image-builder ends up consuming all this is just bizarre (through the chroot's installed .deb!), not to mention the whole UBOOT_TARGET_MAP-hell.

Agree, it bothers me every time i play with uboot configurations :D

I will apply your requests and then let's merge it. As far as i've seen write_uboot_platform_mtd is only used by armbian-install.

@igorpecovnik igorpecovnik merged commit 2d73b58 into main Apr 30, 2025
1 check passed
@igorpecovnik igorpecovnik deleted the allow-rk-multiple-spi-images branch April 30, 2025 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

05 Milestone: Second quarter release Hardware Hardware related like kernel, U-Boot, ... 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.

4 participants