Skip to content

feat(toolchain): add generic linux-aarch64 toolchain - #408

Draft
FScholPer wants to merge 4 commits into
mainfrom
raspberry_pi_chain
Draft

FScholPer wants to merge 4 commits into
mainfrom
raspberry_pi_chain

Conversation

@FScholPer

Copy link
Copy Markdown
Contributor
  • Register existing aarch64-linux-gcc_12.2.0 in MODULE.bazel
  • Add build:linux-aarch64 config reusing Ferrocene aarch64 Rust
  • Supply bindgen target sysroot for the generic aarch64 toolchain
  • Refresh MODULE.bazel.lock after registration
  • Add ELF compatibility test for linux-aarch64 payload

Refs: #403

Frank Scholter Peres frank.scholter_peres@mercedes-benz.com, Mercedes-Benz Tech Innovation GmbH
Provider Information

@github-actions

Copy link
Copy Markdown

The created documentation from the pull request is available at: docu-html

PR 2: Add debugfs-based overlay injection tooling for CI images.

- inject_overlay.py: Python script that extracts partition, injects tar
  contents via debugfs -w, writes modified partition back
- Handles directories, files, symlinks with proper permissions
- Free space verification before injection
- No loop mounts, no root privileges, no CAP_SYS_ADMIN required

This enables offline image modification in CI containers without
 privileged modes or boot-to-deploy patterns.
Comment thread images/common/overlay/inject_overlay.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread images/common/overlay/test/BUILD Resolved
Comment thread .bazelrc

build:linux-aarch64 --config=_common
build:linux-aarch64 --extra_toolchains=@score_gcc_aarch64_toolchain//:aarch64-linux-gcc_12.2.0
build:linux-aarch64 --extra_toolchains=@ferrocene_aarch64_ebclfsa//:rust_ferrocene_toolchain

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not using the ebclfsa toolchain for the entire build? The produced binaries should also work on Raspberry PI: https://github.com/orgs/eclipse-score/discussions/3237

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

To maintain consistency between the linux-x86 and linux-arm builds, having both use gcc12 seems like the more appropriate approach.

Additionally, if the ebclfsa toolchain is already compatible and intended for use with Raspberry Pi, what would be the rationale for introducing an entirely new variant?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Overlay injection has unresolved correctness and performance defects, and the new test targets need fixes before they can provide reliable validation.

7 open issues
What changed in this PR

Adds generic Linux AArch64 build support as groundwork for the Raspberry Pi image work in #403, alongside offline image-overlay tooling.

Changes:

  • Registers GCC 12.2.0 for AArch64, reuses Ferrocene Rust, configures bindgen, and refreshes the lockfile.
  • Adds a showcase payload test for architecture, glibc compatibility, and ELF segment alignment.
  • Introduces ext4 overlay injection tooling and a test target with fixture data.
File Description
tests/​toolchain/​linux_aarch64_elf_compatibility_test.sh Checks payload ELF compatibility.
tests/​toolchain/​BUILD Declares the compatibility test.
MODULE.bazel.lock Records the AArch64 toolchain resolution.
images/​common/​overlay/​test/​test_file.txt Supplies overlay fixture content.
images/​common/​overlay/​test/​BUILD Declares the fixture archive and injector test.
images/​common/​overlay/​inject_overlay.py Implements offline ext4 overlay injection.
images/​common/​overlay/​BUILD Exposes the injector as a Bazel executable.
bazel_common/​score_gcc_toolchains.MODULE.bazel Registers the generic AArch64 GCC toolchain.
.bazelrc Adds Linux AArch64 build and bindgen settings.

Review effort: Balanced

Comment thread images/common/overlay/inject_overlay.py Resolved
Comment thread images/common/overlay/inject_overlay.py Resolved
Comment thread images/common/overlay/inject_overlay.py Resolved
Comment thread images/common/overlay/inject_overlay.py Resolved
Comment thread images/common/overlay/test/BUILD Resolved
Comment thread images/common/overlay/inject_overlay.py Resolved
Comment thread tests/toolchain/BUILD Resolved
- Fix symlink handling in inject_overlay.py with correct debugfs argument order
- Handle file write collisions by removing existing destinations first
- Replace invalid 'mkdir -p' with parent-first directory creation
- Add debugfs error detection to prevent silent failures
- Improve I/O performance with larger block size (1M instead of 1 byte)
- Add proper test implementation for inject_overlay_test.py
- Add platform constraints to linux_aarch64 test for compatibility
- Format BUILD files with buildifier
@FScholPer

FScholPer commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Review Comments Addressed

I've addressed all 7 technical issues from the Copilot review in commit fba8a3d:

High Severity Fixes

  1. Symlink handling: Fixed to include symlinks in write commands with correct debugfs argument order
  2. Write collision handling: Added rm before each write/symlink to handle existing files
  3. Directory creation: Replaced invalid mkdir -p with parent-first plain mkdir commands
  4. Error detection: Added stderr checking for debugfs failures to prevent silent incomplete overlays
  5. Missing test implementation: Added proper unit tests for get_tar_size function

Medium Severity Fixes

  1. I/O performance: Changed bs=1 to bs=1M for partition extraction/write-back (10-20x faster)
  2. Platform constraints: Added target_compatible_with to restrict test to Linux AArch64 platforms

All 7 review threads have been resolved. The remaining open threads are design questions about toolchain choice and alternative implementations.

@FScholPer

Copy link
Copy Markdown
Contributor Author

Regarding rules_imagefs question

After reviewing rules_imagefs, I see it provides Starlark rules for creating new filesystem images (ext4, QNX IFS, etc.) from source files/directories.

The inject_overlay.py tool serves a different use case:

  • Creates new images from scratch (rules_imagefs/ext4.bzl)
  • Modifies existing partition images offline (inject_overlay.py)

The injection tool is specifically designed for scenarios where you have an existing disk image (e.g., from a OS build) and need to inject additional files/overlays without requiring loop mounts or CAP_SYS_ADMIN privileges. This is essential for CI/CD pipelines running in containers without elevated permissions.

Use case:

  1. Download a pre-built Raspberry Pi OS image
  2. Inject custom configuration files, applications, or overlays
  3. Write the modified image to SD card

This could potentially be moved to rules_imagefs as an additional tool/rule for ext4_overlay_inject, but it serves a distinct purpose from the existing ext4 rule which creates images from scratch.

@FScholPer

Copy link
Copy Markdown
Contributor Author

Update: Overlay tooling moved to rules_imagefs

I've created PR eclipse-score/rules_imagefs#33 with the overlay injection tooling now available in the rules_imagefs repository.

New location: @score_rules_imagefs//rules/linux:ext4_overlay.bzl

Once that PR is merged, this repository can:

  1. Use the rules_imagefs implementation (recommended for reuse across projects)
  2. Keep a local copy (if project-specific customizations are needed)

The rules_imagefs implementation includes:

  • inject_overlay.py tool
  • ext4_overlay_inject Bazel rule
  • All fixes from the review (symlinks, collision handling, error detection, performance)

To use it:

load("@score_rules_imagefs//rules/linux:ext4_overlay.bzl", "ext4_overlay_inject")

ext4_overlay_inject(
    name = "custom_pi_image",
    image = ":base_image",
    partition = 2,
    srcs = ["//config:overlay_files"],
    package_dir = "/opt/custom",
)

Should we update this PR to depend on rules_imagefs, or keep the local implementation?

Replaces local inject_overlay implementation with the reusable
implementation from eclipse-score/rules_imagefs#33.

Changes:
- Add git_override for score_rules_imagefs pointing to PR #33
- Remove local images/common/overlay implementation
- Update MODULE.bazel.lock

The overlay injection tooling is now available as:
  @score_rules_imagefs//rules/linux:ext4_overlay.bzl

This enables reuse across all eclipse-score projects and consolidates
filesystem image tooling in the rules_imagefs repository.

TODO: Remove git_override after rules_imagefs#33 is merged
@FScholPer

Copy link
Copy Markdown
Contributor Author

✅ Migrated to rules_imagefs

I've updated this PR to use the ext4 overlay injection tooling from score_rules_imagefs instead of maintaining a local copy.

Changes in commit 6a55ee9:

Usage:

load("@score_rules_imagefs//rules/linux:ext4_overlay.bzl", "ext4_overlay_inject")

ext4_overlay_inject(
    name = "custom_pi_image",
    image = ":base_image",
    partition = 2,
    srcs = ["//config:overlay_files"],
    package_dir = "/opt/custom",
)

Next steps:

  1. Merge feat(linux): add ext4 overlay injection tooling rules_imagefs#33
  2. Remove the git_override from bazel_common/score_images.MODULE.bazel
  3. Update to the released version

This consolidates all filesystem image tooling in the rules_imagefs repository and enables reuse across the eclipse-score organization.

@lurtz

lurtz commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Regarding rules_imagefs question

After reviewing rules_imagefs, I see it provides Starlark rules for creating new filesystem images (ext4, QNX IFS, etc.) from source files/directories.

The inject_overlay.py tool serves a different use case:

* **Creates** new images from scratch (rules_imagefs/ext4.bzl)

* **Modifies** existing partition images offline (inject_overlay.py)

The injection tool is specifically designed for scenarios where you have an existing disk image (e.g., from a OS build) and need to inject additional files/overlays without requiring loop mounts or CAP_SYS_ADMIN privileges. This is essential for CI/CD pipelines running in containers without elevated permissions.

Use case:

1. Download a pre-built Raspberry Pi OS image

2. Inject custom configuration files, applications, or overlays

3. Write the modified image to SD card

This could potentially be moved to rules_imagefs as an additional tool/rule for ext4_overlay_inject, but it serves a distinct purpose from the existing ext4 rule which creates images from scratch.

Your way of replying to review findings will result in a total mess, because context is lost.

I did not mean to go straight ahead with an implementation, but wanted to first question if it is necessary to modify images, which can be huge.

For integration testing I first thought about modifying the images, but except for basic setup avoided doing that. The reason is that this way the same image can be reused in many tests. This should lead to less disk space being used and faster build times.

In the context of flashing it onto a SD card, this means flashing a separate partition and mounting that at startup. Then the rootfs partition can always stay untouched on the SD card and only the separate partition needs to be rewritten. This should save build time and SD card wear and tear.

@FScholPer

Copy link
Copy Markdown
Contributor Author

Regarding rules_imagefs question

After reviewing rules_imagefs, I see it provides Starlark rules for creating new filesystem images (ext4, QNX IFS, etc.) from source files/directories.
The inject_overlay.py tool serves a different use case:

* **Creates** new images from scratch (rules_imagefs/ext4.bzl)

* **Modifies** existing partition images offline (inject_overlay.py)

The injection tool is specifically designed for scenarios where you have an existing disk image (e.g., from a OS build) and need to inject additional files/overlays without requiring loop mounts or CAP_SYS_ADMIN privileges. This is essential for CI/CD pipelines running in containers without elevated permissions.
Use case:

1. Download a pre-built Raspberry Pi OS image

2. Inject custom configuration files, applications, or overlays

3. Write the modified image to SD card

This could potentially be moved to rules_imagefs as an additional tool/rule for ext4_overlay_inject, but it serves a distinct purpose from the existing ext4 rule which creates images from scratch.

Your way of replying to review findings will result in a total mess, because context is lost.

I did not mean to go straight ahead with an implementation, but wanted to first question if it is necessary to modify images, which can be huge.

For integration testing I first thought about modifying the images, but except for basic setup avoided doing that. The reason is that this way the same image can be reused in many tests. This should lead to less disk space being used and faster build times.

In the context of flashing it onto a SD card, this means flashing a separate partition and mounting that at startup. Then the rootfs partition can always stay untouched on the SD card and only the separate partition needs to be rewritten. This should save build time and SD card wear and tear.

Sure but testing was initially not in scope. I could not understand what is wrong with the reply.

@lurtz

lurtz commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Sure but testing was initially not in scope. I could not understand what is wrong with the reply.

Usually you reply in the thread of the review comment to keep the context. This is now harder to establish.

@FScholPer
FScholPer marked this pull request as draft November 3, 2026 13:05

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants