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 Hailo-8 firmware for Raspberry Pi AI Kit/HAT on RPi 5 #3680

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

sairon
Copy link
Member

@sairon sairon commented Nov 18, 2024

Add Hailo-8 firmware binary for Rasperry Pi AI accelerators. The version needs to be determined from the Git history of the kernel sources, as the driver source code is included in the RPi downstream kernel and the version string can't be found in the code directly.

Fixes #3663

Summary by CodeRabbit

  • New Features

    • Integrated Hailo-8 firmware configuration into the build system.
    • Added support for Hailo-8 firmware in Raspberry Pi 5 configuration.
    • Introduced a new configuration option for Hailo-8 firmware.
  • Bug Fixes

    • Added SHA256 hash for firmware integrity verification.
  • Documentation

    • Updated configuration files with descriptions for new firmware options.
  • Chores

    • Created a Makefile for managing Hailo-8 firmware package operations.

@sairon sairon added the board/raspberrypi Raspberry Pi Boards label Nov 18, 2024
@sairon sairon requested a review from agners November 18, 2024 16:39
Copy link

coderabbitai bot commented Nov 18, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes introduce support for the Hailo8 firmware in the buildroot configuration for Raspberry Pi 5. This includes adding a configuration source for the firmware, defining a new package, and creating a Makefile that manages the firmware's build and installation processes. A SHA256 hash for the firmware binary is also included to ensure its integrity.

Changes

File Path Change Summary
buildroot-external/Config.in Added line to include Hailo8 firmware configuration: source "$BR2_EXTERNAL_HASSOS_PATH/package/hailo8-firmware/Config.in"
buildroot-external/configs/rpi5_64_defconfig Added new package configuration: BR2_PACKAGE_HAILO8_FIRMWARE=y
buildroot-external/package/hailo8-firmware/Config.in Introduced new configuration option: config BR2_PACKAGE_HAILO8_FIRMWARE
buildroot-external/package/hailo8-firmware/hailo8-firmware.hash Added SHA256 hash for hailo8_fw.4.18.0.bin: bfa576dd782359d74cabcb19e87c3a934dce03dea0785e41f86fecc9a687a92b
buildroot-external/package/hailo8-firmware/hailo8-firmware.mk Created Makefile with variables and commands for firmware management, including version and source details.

Assessment against linked issues

Objective Addressed Explanation
Firmware Upload Issue (3663)
Driver Loading (3663)
Issue Identification (3663) The specific firmware file path needs to be confirmed for persistence.
Operating System (3663)
Reproduction Steps (3663) Unclear if the new setup resolves the reproduction of the issue.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 74e2f56 and 724ee1d.

📒 Files selected for processing (5)
  • buildroot-external/Config.in (1 hunks)
  • buildroot-external/configs/rpi5_64_defconfig (1 hunks)
  • buildroot-external/package/hailo8-firmware/Config.in (1 hunks)
  • buildroot-external/package/hailo8-firmware/hailo8-firmware.hash (1 hunks)
  • buildroot-external/package/hailo8-firmware/hailo8-firmware.mk (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • buildroot-external/package/hailo8-firmware/Config.in
🚧 Files skipped from review as they are similar to previous changes (4)
  • buildroot-external/Config.in
  • buildroot-external/configs/rpi5_64_defconfig
  • buildroot-external/package/hailo8-firmware/hailo8-firmware.hash
  • buildroot-external/package/hailo8-firmware/hailo8-firmware.mk

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: 0

🧹 Outside diff range and nitpick comments (4)
buildroot-external/package/hailo8-firmware/Config.in (1)

3-6: Consider enhancing the help text documentation

While the current help text provides basic information, consider adding:

  • Firmware version or source information
  • Specific kernel version requirements
  • Expected installation path of the firmware file
  • License information for the firmware

Example enhancement:

 help
   Firmware for Hailo-8 PCIe device found e.g. on Raspberry Pi AI
   Kit and Raspberry Pi AI HAT+. Requires the hailo kernel driver
-  (included in Raspberry Pi's downstream kernel).
+  (included in Raspberry Pi's downstream kernel >= X.Y).
+
+  The firmware file (hailo8_fw.bin) will be installed to
+  /lib/firmware/hailo and is distributed under the license XXX.
+  Version: X.Y.Z (sourced from RPi kernel git history)
buildroot-external/package/hailo8-firmware/hailo8-firmware.mk (2)

12-14: Consider adding integrity verification during extraction

While the copy operation is correct, consider adding SHA256 verification of the firmware file during extraction for additional security.

 define HAILO8_FIRMWARE_EXTRACT_CMDS
+	echo "$(sha256sum $(HAILO8_FIRMWARE_DL_DIR)/$(HAILO8_FIRMWARE_SOURCE))" | \
+		grep -q "^$(shell cat $(HAILO8_FIRMWARE_PKGDIR)/hailo8-firmware.hash)"
 	cp $(HAILO8_FIRMWARE_DL_DIR)/$(HAILO8_FIRMWARE_SOURCE) $(@D)
 endef

20-23: LGTM! Installation follows firmware best practices

The installation commands correctly:

  1. Create a vendor-specific firmware directory
  2. Set appropriate read-only permissions (0644)
  3. Use the standard /lib/firmware path hierarchy

This should resolve the firmware persistence issue mentioned in #3663.

Consider adding a post-install verification step in the OS startup scripts to confirm firmware presence and permissions, helping diagnose any potential installation issues.

buildroot-external/configs/rpi5_64_defconfig (1)

Line range hint 1-146: Architectural consideration: Ensure firmware persistence with EROFS.

The configuration uses EROFS with compression and deduplication enabled. This setup, combined with the following relevant settings, should properly handle firmware persistence:

  • BR2_TARGET_ROOTFS_EROFS=y
  • BR2_TARGET_ROOTFS_EROFS_LZ4HC_LEVEL=12
  • BR2_TARGET_ROOTFS_EROFS_DEDUPE=y

To ensure the firmware persists across reboots (addressing issue #3663), verify that:

  1. The firmware is installed to the correct path in the EROFS image
  2. The firmware is included in the initial ramdisk if needed before root filesystem mount
  3. The firmware path matches the driver's expected location

Would you like me to generate a script to verify these aspects in the build configuration?

Also applies to: 146-159

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f169f78 and 74e2f56.

📒 Files selected for processing (5)
  • buildroot-external/Config.in (1 hunks)
  • buildroot-external/configs/rpi5_64_defconfig (1 hunks)
  • buildroot-external/package/hailo8-firmware/Config.in (1 hunks)
  • buildroot-external/package/hailo8-firmware/hailo8-firmware.hash (1 hunks)
  • buildroot-external/package/hailo8-firmware/hailo8-firmware.mk (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • buildroot-external/package/hailo8-firmware/hailo8-firmware.hash
🧰 Additional context used
📓 Path-based instructions (1)
buildroot-external/Config.in (6)

Pattern */**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

Pattern */**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

Pattern */**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"


Pattern */**(html|markdown|md): - Use sentence-style capitalization also in headings.


Pattern */**(html|markdown|md): do not comment on HTML used for icons


Pattern */**(html|markdown|md): Avoid flagging inline HTML for embedding videos in future reviews for this repository.

🔇 Additional comments (8)
buildroot-external/package/hailo8-firmware/Config.in (2)

1-2: LGTM! Configuration follows buildroot conventions

The package configuration name and type are correctly defined following buildroot naming conventions.


1-6: Verify firmware installation path and persistence

Given issue #3663 where the firmware file wasn't found during boot and manual uploads didn't persist, we should verify the package installation configuration.

✅ Verification successful

Let me analyze the firmware installation configuration from the output. I can see that:

  1. The package has a proper .mk file defining installation paths:
define HAILO8_FIRMWARE_INSTALL_TARGET_CMDS
	$(INSTALL) -d $(TARGET_DIR)/lib/firmware/hailo
	$(INSTALL) -m 0644 $(@D)/hailo8_fw.bin $(TARGET_DIR)/lib/firmware/hailo/
endef
  1. The firmware is installed to /lib/firmware/hailo/ which is a standard firmware location in Linux systems.

  2. No cleanup scripts were found that would affect firmware persistence (the search for cleanup scripts returned no results).

  3. The installation is done through Buildroot's standard package installation mechanism which ensures files are properly installed into the target filesystem.

  4. The firmware will be included in the root filesystem and persist across reboots since it's installed to a standard system location.

Firmware installation path and persistence verified

The firmware will be installed to the correct system path /lib/firmware/hailo/ and will persist across reboots since:

  • It uses standard firmware installation paths
  • Installation is handled by Buildroot's package system
  • No cleanup scripts were found that would remove it
  • The target directory is part of the root filesystem
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the firmware installation configuration

# Check if there's a corresponding .mk file defining the installation path
echo "Checking for package makefile..."
find . -name "hailo8-firmware.mk"

# Check if other firmware packages use similar paths
echo -e "\nChecking firmware installation paths in other packages..."
rg -A 3 "$(FIRMWARE_DIR)" "buildroot-external/package/"

# Check for firmware cleanup scripts that might affect persistence
echo -e "\nChecking for firmware cleanup scripts..."
rg -l "/lib/firmware.*clean" "buildroot-external/"

Length of output: 350559

buildroot-external/package/hailo8-firmware/hailo8-firmware.mk (4)

16-18: LGTM! Filename matches driver expectations

The build command correctly renames the firmware to hailo8_fw.bin, which matches the filename expected by the driver as mentioned in issue #3663.


25-25: LGTM! Correct package infrastructure used

The use of generic-package is appropriate for binary-only firmware packages.


9-10: Verify S3 bucket accessibility and stability

The firmware is sourced from an AWS S3 bucket. Please ensure:

  1. The bucket is publicly accessible
  2. The URL is stable and won't change
  3. There's a backup source in case the S3 bucket becomes unavailable

Let's verify the URL accessibility:

#!/bin/bash
# Verify URL accessibility
curl -I "${HAILO8_FIRMWARE_SITE}/${HAILO8_FIRMWARE_SOURCE}"

7-8: Version determination approach differs from PR objectives

The PR objectives mention that the firmware version should be determined from the Git history of the kernel sources. However, the version is currently hardcoded to 4.18.0.

Let's verify if this version matches the kernel sources:

buildroot-external/Config.in (1)

5-5: LGTM! The change follows buildroot conventions.

The addition maintains consistent formatting and correct alphabetical ordering.

Let's verify the existence of the referenced configuration file:

✅ Verification successful

✓ Config.in file exists and is properly configured

The referenced configuration file exists and contains the correct package configuration for Hailo-8 firmware. The file includes:

  • Proper package naming convention (BR2_PACKAGE_HAILO8_FIRMWARE)
  • Clear description and help text
  • Correct dependency information for Raspberry Pi AI Kit/HAT
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the Hailo8 firmware configuration file
# Expected: The file should exist and contain the firmware package configuration

# Check if the Config.in file exists
fd -t f "Config.in" package/hailo8-firmware

# If found, display its contents to verify the package configuration
fd -t f "Config.in" package/hailo8-firmware -x cat

Length of output: 316


Script:

#!/bin/bash
# Let's verify from the repository root with correct path
fd -t f "Config.in" buildroot-external/package/hailo8-firmware

# If found, display its contents
fd -t f "Config.in" buildroot-external/package/hailo8-firmware -x cat

# Let's also check if the directory exists
ls -la buildroot-external/package/hailo8-firmware 2>/dev/null || echo "Directory not found"

Length of output: 794

buildroot-external/configs/rpi5_64_defconfig (1)

146-146: LGTM! Verify firmware persistence across reboots.

The addition of BR2_PACKAGE_HAILO8_FIRMWARE=y is correctly positioned and integrated with the existing firmware configuration. The EROFS configuration ensures proper firmware handling.

Let's verify the firmware package configuration:

✅ Verification successful

Firmware package configuration is correct and well-structured

The verification shows that the Hailo-8 firmware package is properly configured:

  • Config.in correctly defines the package with appropriate help text
  • Makefile properly handles firmware installation to /lib/firmware/hailo/hailo8_fw.bin
  • SHA256 hash is present for firmware integrity verification
  • Version 4.18.0 firmware is sourced from official Hailo repository
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Hailo-8 firmware package configuration and dependencies

# Check if the package configuration exists
if ! fd -t f "Config.in$" | xargs grep -l "BR2_PACKAGE_HAILO8_FIRMWARE"; then
    echo "Error: Missing Config.in file for Hailo-8 firmware package"
    exit 1
fi

# Verify firmware installation path in package makefile
if ! fd -t f "hailo8-firmware.mk$" | xargs grep -l "\/lib\/firmware\/hailo8_fw.bin"; then
    echo "Error: Firmware installation path might be incorrect"
    exit 1
fi

# Check for firmware hash file
if ! fd -t f "hailo8-firmware.hash$"; then
    echo "Error: Missing hash file for firmware verification"
    exit 1
fi

Length of output: 324


Script:

#!/bin/bash
# Let's examine the actual content of these files to verify the configuration

# Check Config.in content
echo "=== Config.in content ==="
fd -t f "Config.in$" -x cat {} \; | grep -A 5 "config BR2_PACKAGE_HAILO8_FIRMWARE"

# Check makefile content
echo -e "\n=== Makefile content ==="
fd -t f "hailo8-firmware.mk$" -x cat {}

# Check hash file content
echo -e "\n=== Hash file content ==="
fd -t f "hailo8-firmware.hash$" -x cat {}

Length of output: 1547

Add Hailo-8 firmware binary for Rasperry Pi AI accelerators. The version needs
to be determined from the Git history of the kernel sources, as the driver
source code is included in the RPi downstream kernel and the version string
can't be found in the code directly.

Fixes #3663
@sairon sairon force-pushed the add-hailo8-firmware branch from 74e2f56 to 724ee1d Compare November 18, 2024 16:59
@sairon
Copy link
Member Author

sairon commented Nov 18, 2024

FTR, I was wrong the version is not defined in the sources, it is in drivers/media/pci/hailo/common/hailo_ioctl_common.h. So we could maybe use it for some kind of a sanity check (rather than using the version from kernel sources to install it dynamically - then we couldn't check the hash etc.).

@sairon sairon merged commit eec6dfb into dev Nov 18, 2024
3 checks passed
@sairon sairon deleted the add-hailo8-firmware branch November 18, 2024 18:01
@sairon sairon mentioned this pull request Nov 19, 2024
@sairon sairon mentioned this pull request Dec 3, 2024
@drkpxl
Copy link

drkpxl commented Dec 4, 2024

Is this a pre-cursor to native Frigate support or any other projects that can leverage the Hailo-8?

@sairon
Copy link
Member Author

sairon commented Dec 5, 2024

@drkpxl Frigate already supports it but there are still some issues that need to be addressed for seamless usage in HAOS, see here: blakeblackshear/frigate#15172

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

Successfully merging this pull request may close these issues.

Home Assistant and Hailo 8L
3 participants