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

Add Khadas VIM3L #3899

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft

Add Khadas VIM3L #3899

wants to merge 3 commits into from

Conversation

viraniac
Copy link
Contributor

@viraniac viraniac commented Feb 25, 2025

Add Khadas VIM3L board

  • 2GB Ram
  • 16 GB EMMC
  • Amlogic S905D3 (4xCortex A55)

Summary by CodeRabbit

  • New Features
    • Enhanced the boot setup with optional configuration hints for advanced hardware support.
    • Updated console settings for dual-output to improve boot diagnostics.
    • Introduced automation hooks for streamlined boot image preparation and conversion.
    • Implemented an improved boot management system with dual-slot retry capability.
    • Expanded build configurations with tailored board settings and dynamic bootloader options, including integrated support for Home Assistant.
    • Added support for a new boot image configuration and partition management for the Khadas VIM3L board.

Signed-off-by: Gunjan Gupta <[email protected]>
Copy link

coderabbitai bot commented Feb 25, 2025

Warning

Rate limit exceeded

@viraniac has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 42 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 88ebf81 and 3cb2927.

📒 Files selected for processing (1)
  • buildroot-external/package/khadas-boot/khadas-boot.mk (2 hunks)
📝 Walkthrough

Walkthrough

This pull request updates the Buildroot support for the Khadas Vim3L board. It adds new configuration entries, scripts, and metadata to refine boot image handling, bootloader management, and system builds. Notable changes include the addition of commented hints in boot configuration files, a new hook for pre/post image processing, updated image/partition settings, detailed board metadata, and enhancements to the U-Boot boot script with a retry mechanism. The Buildroot configuration and bootloader package scripts have also been modified to support conditional processing for different hardware variants.

Changes

File(s) Change Summary
buildroot-external/.../vim3l/boot-env.txt
buildroot-external/.../vim3l/cmdline.txt
Added two commented lines in boot-env.txt for optional GPIO support and overlay configuration; inserted a new console specification line in cmdline.txt.
buildroot-external/.../vim3l/hassos-hook.sh Introduced a new shell script with hassos_pre_image and hassos_post_image functions to copy boot files and execute disk image conversion.
buildroot-external/.../vim3l/image-spl-spl.cfg
buildroot-external/.../vim3l/partition-spl-spl.cfg
Added a new SPL image configuration with post-processing (using dd) and a corresponding partition definition excluding it from the partition table.
buildroot-external/.../vim3l/meta Introduced a new metadata file defining board parameters (e.g., BOARD_ID, BOARD_NAME, BOOTLOADER settings, kernel file, and boot sizes).
buildroot-external/.../vim3l/uboot-boot.ush
buildroot-external/.../vim3l/uboot.config
Added a new U-Boot boot management script with environment handling, slot-based boot attempts, and retry logic; updated U-Boot configuration to enable DOS partition support and board info display.
buildroot-external/.../configs/khadas_vim3l_defconfig Added a new Buildroot configuration file for the Khadas Vim3L, specifying architecture, toolchain, kernel version, systemd init, relevant package selections, and bootloader settings.
buildroot-external/.../khadas-boot/Config.in
buildroot-external/.../khadas-boot/khadas-boot.mk
Introduced a new boolean option to build the Khadas Vim3L bootloader; implemented conditional logic to set encryption commands and update the bootloader version based on the selected variant.

Sequence Diagram(s)

sequenceDiagram
    participant U as U-Boot Boot Script
    participant E as Boot Environment
    participant K as Kernel Boot Process

    U->>E: Load boot environment variables
    U->>U: Initialize boot parameters (slots A/B, retry counters)
    U->>K: Attempt boot from Slot A
    alt Slot A Fails
        U->>U: Decrement retry counter for Slot A
        U->>K: Attempt boot from Slot B
    end
    alt Both Slots Fail
        U->>E: Reset boot parameters and update environment
        U->>K: Retry kernel boot
    end
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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

🧹 Nitpick comments (2)
buildroot-external/board/khadas/vim3l/hassos-hook.sh (2)

1-12: The pre-image hook looks good but consider adding validation.

The hassos_pre_image function correctly copies the necessary files to prepare the boot directory for the Khadas VIM3L board. However, it might be helpful to add some validation to ensure the source files exist before attempting to copy them.

Consider adding error checking before copying files:

function hassos_pre_image() {
    local BOOT_DATA="$(path_boot_dir)"

+   # Validate that required files exist
+   for file in "${BINARIES_DIR}/boot.scr" "${BINARIES_DIR}/meson-sm1-khadas-vim3l.dtb" "${BOARD_DIR}/boot-env.txt" "${BOARD_DIR}/cmdline.txt"; do
+       if [ ! -f "${file}" ]; then
+           echo "Error: Required file ${file} is missing!"
+           exit 1
+       fi
+   done
+
    cp "${BINARIES_DIR}/boot.scr" "${BOOT_DATA}/boot.scr"
    cp "${BINARIES_DIR}/meson-sm1-khadas-vim3l.dtb" "${BOOT_DATA}/meson-sm1-khadas-vim3l.dtb"

    cp "${BOARD_DIR}/boot-env.txt" "${BOOT_DATA}/haos-config.txt"
    cp "${BOARD_DIR}/cmdline.txt" "${BOOT_DATA}/cmdline.txt"
}

19-19: Remove empty line at EOF.

There's an extra empty line at the end of file that should be removed to comply with standard file formatting.

-
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b3ce713 and 9890047.

📒 Files selected for processing (11)
  • buildroot-external/board/khadas/vim3l/boot-env.txt (1 hunks)
  • buildroot-external/board/khadas/vim3l/cmdline.txt (1 hunks)
  • buildroot-external/board/khadas/vim3l/hassos-hook.sh (1 hunks)
  • buildroot-external/board/khadas/vim3l/image-spl-spl.cfg (1 hunks)
  • buildroot-external/board/khadas/vim3l/meta (1 hunks)
  • buildroot-external/board/khadas/vim3l/partition-spl-spl.cfg (1 hunks)
  • buildroot-external/board/khadas/vim3l/uboot-boot.ush (1 hunks)
  • buildroot-external/board/khadas/vim3l/uboot.config (1 hunks)
  • buildroot-external/configs/khadas_vim3l_defconfig (1 hunks)
  • buildroot-external/package/khadas-boot/Config.in (1 hunks)
  • buildroot-external/package/khadas-boot/khadas-boot.mk (2 hunks)
✅ Files skipped from review due to trivial changes (4)
  • buildroot-external/board/khadas/vim3l/uboot.config
  • buildroot-external/board/khadas/vim3l/cmdline.txt
  • buildroot-external/board/khadas/vim3l/boot-env.txt
  • buildroot-external/board/khadas/vim3l/meta
🔇 Additional comments (18)
buildroot-external/board/khadas/vim3l/partition-spl-spl.cfg (1)

1-7: SPL partition configuration looks good and follows Amlogic boot requirements.

The partition configuration correctly defines the SPL (Second Program Loader) at the beginning of the device with appropriate settings:

  • Not included in the partition table which is standard for bootloaders
  • Starts at offset 0, which is required for Amlogic devices
  • Contains a hole at bytes 440-512 which preserves the MBR boot code area

This matches expected configuration for Amlogic S905D3-based devices like the Khadas VIM3L.

buildroot-external/board/khadas/vim3l/image-spl-spl.cfg (2)

1-16: SPL image configuration looks good for Amlogic bootloader.

The image configuration correctly defines how to create the SPL image containing the U-Boot bootloader for the Khadas VIM3L. The structure follows expected patterns for Amlogic S905D3 devices.


4-5:

❓ Verification inconclusive

Consider investigating if the post-processing is necessary.

The FIXME comment suggests this zeroing operation might be redundant. Since you've kept it for binary-identical output, it's reasonable for now, but you may want to test if removing it causes any issues once the basic implementation is working.


🏁 Script executed:

#!/bin/bash
# Description: Check if other Amlogic board configs use similar dd commands

echo "Checking for similar dd commands in other board configurations:"
rg -l "dd if=/dev/zero" buildroot-external/board/ | grep -v "vim3l"

Length of output: 259


Action: Investigate the necessity of the dd post-processing command

The zeroing operation here is currently used only for the Khadas boards and appears to be a board-specific workaround for ensuring binary-identical SPL images. Our repository search shows that aside from the configuration in vim3l, a similar dd command is found in the related vim3 configuration. Since there isn’t a broader pattern across other board configurations, it’s worthwhile to test removing this command to see if it impacts functionality or the expected binary output. If testing confirms that it’s redundant, consider cleaning up the configuration accordingly.

buildroot-external/board/khadas/vim3l/uboot-boot.ush (4)

1-107: Well-structured boot script with robust A/B boot implementation.

This U-Boot boot script implements a solid A/B boot system with retry mechanisms, which is excellent for system reliability. The script has good error handling, clear logging, and follows best practices for U-Boot scripting.


46-57: Good implementation of device tree overlay support.

The implementation of DTB overlay support with error handling is excellent. If an overlay fails to apply, the script correctly falls back to the original device tree to ensure the system can still boot.


59-90: Robust A/B boot implementation with retry mechanism.

The A/B boot implementation with retry counters is well designed. The script correctly:

  1. Tries boot slots in the order specified by BOOT_ORDER
  2. Decrements attempt counters for each failed boot
  3. Loads the appropriate kernel and sets the correct boot arguments for each slot

This provides excellent reliability for updates and recovery in the Home Assistant OS context.


40-44:

✅ Verification successful

Verify the device tree filename is correct for VIM3L.

The script hardcodes the device tree filename to "meson-sm1-khadas-vim3l.dtb". Please verify this is the correct DTB name for the Khadas VIM3L with Amlogic S905D3 processor.


🏁 Script executed:

#!/bin/bash
# Description: Check if the DTB file exists in the Linux kernel source

# Find the Linux kernel directory
KERNEL_DIR=$(find buildroot-external/packages -name "linux-*.tar.gz" -o -name "linux-*.tar.xz" | sort -V | tail -n 1 | xargs dirname)

if [ -n "$KERNEL_DIR" ]; then
  echo "Looking for VIM3L device tree file in kernel source:"
  find $KERNEL_DIR -name "*vim3l*.dts" -o -name "*khadas*vim3l*.dts" | sort
else
  echo "Linux kernel package not found. Checking for DTB references in other board config files:"
  rg "meson-sm1-khadas-vim3l" buildroot-external/
fi

Length of output: 881


Device Tree Filename Verified

After executing the verification script, we confirmed that the DTB file "meson-sm1-khadas-vim3l.dtb" is consistently referenced across the board configuration. Both the uboot-boot.ush and hassos-hook.sh scripts use this filename, and the defconfig file defines the corresponding DTS name (amlogic/meson-sm1-khadas-vim3l). No changes are required.

buildroot-external/board/khadas/vim3l/hassos-hook.sh (1)

15-17: Post-image hook looks good.

The hassos_post_image function properly calls the convert_disk_image_xz utility to compress the final disk image.

buildroot-external/package/khadas-boot/khadas-boot.mk (4)

15-19: The VIM3 configuration block looks good.

The block correctly sets KHADAS_BOOT_FIP_DIR and AML_ENCRYPT variables for the VIM3 board.


21-26: The new VIM3L configuration looks appropriate.

The configuration correctly sets up the VIM3L-specific directories and encryption tool. Good job on maintaining consistency with the existing VIM3 pattern.


28-30: Good implementation of conditional version setting.

The use of a conditional to set the version for both VIM3 and VIM3L is a clean approach, ensuring consistent versioning across both board types.


73-107: Great use of the AML_ENCRYPT variable.

The build commands now use the $(AML_ENCRYPT) variable instead of hardcoded values, which is a good practice that accommodates both board types without code duplication.

buildroot-external/configs/khadas_vim3l_defconfig (6)

25-25: Correct device tree specification.

The Linux kernel device tree name is properly set to amlogic/meson-sm1-khadas-vim3l, which matches the DTB file copied in the hassos-hook.sh script.


141-142: U-Boot configuration is well-specified.

The U-Boot board defconfig is correctly set to khadas-vim3l and includes appropriate configuration fragments.


156-157: Correct Khadas boot package configuration.

The configuration correctly enables the Khadas boot package and specifically selects the VIM3L variant, which aligns with the changes made in khadas-boot.mk.


151-151:

✅ Verification successful

Boot script source path is appropriate.

The U-Boot boot script source path points to the correct location for the VIM3L board-specific boot script.


🏁 Script executed:

#!/bin/bash
# Verify that the uboot-boot.ush exists at the specified path
if [ -f "buildroot-external/board/khadas/vim3l/uboot-boot.ush" ]; then
  echo "✅ uboot-boot.ush file found at the expected location"
else
  echo "❌ uboot-boot.ush file not found at the expected location"
fi

Length of output: 180


Verification Complete: Boot script source path validated
The verification confirmed that the uboot-boot.ush file exists at buildroot-external/board/khadas/vim3l/uboot-boot.ush, matching the expected configuration path. No further modifications are required.


16-16:

✅ Verification successful

Configuration looks good, but verify the hassos-hook.sh path.

The post-script args correctly point to the board-specific directory and hook script. This ensures that the Khadas VIM3L-specific build hooks are executed during the build process.


🏁 Script executed:

#!/bin/bash
# Verify that the hassos-hook.sh exists at the specified path
if [ -f "buildroot-external/board/khadas/vim3l/hassos-hook.sh" ]; then
  echo "✅ hassos-hook.sh file found at the expected location"
else
  echo "❌ hassos-hook.sh file not found at the expected location"
fi

Length of output: 180


Configuration Verified: hassos-hook.sh Path is Correct

The file buildroot-external/board/khadas/vim3l/hassos-hook.sh was confirmed to exist at the expected location. The post-script arguments in buildroot-external/configs/khadas_vim3l_defconfig correctly reference the board-specific directory and hook script, ensuring the intended build hooks will be executed.

  • Verified file location: buildroot-external/board/khadas/vim3l/hassos-hook.sh

No further changes are needed.


154-155:

❓ Verification inconclusive

Board naming consistency check needed.

The configuration uses both khadas-vim3l (lowercase with hyphens) and KhadasVim3l (CamelCase) in different settings. This might be intentional based on how different components expect the board name, but it's worth verifying for consistency.

Also applies to: 159-159


🏁 Script executed:

#!/bin/bash
# Check board naming consistency across config files
echo "Checking board naming conventions:"
echo "Home Assistant machine name: khadas-vim3l"
echo "OS Agent board name: KhadasVim3l"

# Check if these naming conventions are used consistently in other configs
grep -r "khadas-vim3l\|KhadasVim3l" buildroot-external/package/ buildroot-external/board/ --include="*.mk" --include="*.config" --include="*.sh"

Length of output: 540


Board Naming Consistency: Verify OS Agent Naming Convention

The Home Assistant machine name is set to "khadas-vim3l" in the defconfig (lines 154-155), and our search confirms that board-related files (e.g., in buildroot-external/board/khadas/vim3l/hassos-hook.sh) use the lowercase hyphenated format. However, the test script’s echo refers to the OS Agent board name as "KhadasVim3l" (CamelCase). Please verify whether the OS Agent component actually requires the CamelCase variant or if the lowercase "khadas-vim3l" should be used instead. Also, ensure that the naming for the corresponding setting on line 159 is consistent.

@agners
Copy link
Member

agners commented Feb 25, 2025

Hi @viraniac thanks for your PR!

Before we can add a new board there should be an architecture discussion (similar to this discussiion). We are rather busy with maintenance on existing boards, so only if we deem it low effort we can consider it.

Finally, we were also start to think about making it easier to add board support via unofficial forks of Home Asisstant OS. This would lower the maintenance effort on our end.

@agners agners marked this pull request as draft February 25, 2025 15:44
@viraniac
Copy link
Contributor Author

Before we can add a new board there should be an architecture discussion (similar to this discussiion). We are rather busy with maintenance on existing boards, so only if we deem it low effort we can consider it.

Sure will start a new discussion page for the same.

@viraniac
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants