Skip to main content

Advantech Board Support Package (BSP) Registry Manager

Project description

bsp-registry-tools

Python tools to build, fetch, and work with Yocto-based BSPs using the KAS build system.

Overview

bsp-registry-tools provides a command-line interface and Python API for managing Advantech Board Support Packages (BSPs). It uses YAML-based registry files to define BSP configurations, build environments, and Docker containers, making reproducible Yocto builds straightforward.

Key Features

  • ๐Ÿ“‹ BSP registry management via YAML configuration files
  • ๐Ÿณ Docker container support for reproducible build environments
  • ๐Ÿ”ง KAS integration for Yocto-based builds (kas, kas-container)
  • ๐Ÿ–ฅ๏ธ Interactive shell access to build environments
  • ๐Ÿ”„ Environment variable expansion ($ENV{VAR} syntax)
  • ๐Ÿ“ค Configuration export for sharing and archiving build configs
  • โœ… Comprehensive validation of configurations before building

Installation

From PyPI

pip install bsp-registry-tools

From Source

git clone https://github.com/Advantech-EECC/bsp-registry-tools.git
cd bsp-registry-tools
pip install .

Dependencies

Quick Start

1. Create a BSP Registry File

Create a bsp-registry.yml file (see examples/bsp-registry.yml):

specification:
  version: "1.0"

environment:
  - name: "DL_DIR"
    value: "$ENV{HOME}/yocto-cache/downloads"
  - name: "SSTATE_DIR"
    value: "$ENV{HOME}/yocto-cache/sstate"

containers:
  - debian-bookworm:
      image: "bsp/registry/debian/kas:5.1"
      file: Dockerfile
      args:
        - name: "DISTRO"
          value: "debian-bookworm"
        - name: "KAS_VERSION"
          value: "5.1"

registry:
  bsp:
    - name: poky-qemuarm64-scarthgap
      description: "Poky QEMU ARM64 Scarthgap (Yocto 5.0 LTS)"
      build:
        path: build/qemu-arm64-scarthgap
        environment:
          container: "debian-bookworm"
        configuration:
          - kas/scarthgap.yml
          - kas/qemu/qemuarm64.yml

2. List Available BSPs

bsp list
- poky-qemuarm64-scarthgap: Poky QEMU ARM64 Scarthgap (Yocto 5.0 LTS)

3. Build a BSP

bsp build poky-qemuarm64-scarthgap

4. Enter Interactive Shell

bsp shell poky-qemuarm64-scarthgap

CLI Reference

usage: bsp [-h] [--verbose] [--registry REGISTRY] [--no-color] {build,list,containers,export,shell} ...

Advantech Board Support Package Registry

positional arguments:
  {build,list,containers,export,shell}
                        Command to execute
    build               Build an image for BSP
    list                List available BSPs
    containers          List available containers
    export              Export BSP configuration
    shell               Enter interactive shell for BSP

options:
  -h, --help            show this help message and exit
  --verbose, -v         Verbose output
  --registry REGISTRY, -r REGISTRY
                        BSP Registry file
  --no-color            Disable colored output

Global Options

Option Description
--verbose, -v Enable verbose/debug output
--registry REGISTRY, -r REGISTRY Path to BSP registry file (default: bsp-registry.yml)
--no-color Disable colored output

Commands

list โ€” List available BSPs

bsp list
bsp --registry my-registry.yml list

containers โ€” List available container definitions

bsp containers

build โ€” Build a BSP image

bsp build <bsp_name> [--clean] [--checkout]
Option Description
--clean Clean build directory before building
--checkout Validate configuration and checkout repos without building

Examples:

# Full build
bsp build poky-qemuarm64-scarthgap

# Checkout/validate only (fast, no build)
bsp build poky-qemuarm64-scarthgap --checkout

shell โ€” Interactive shell in build environment

bsp shell <bsp_name> [--command COMMAND]
Option Description
--command COMMAND, -c COMMAND Execute a specific command instead of starting interactive shell

Examples:

# Interactive shell
bsp shell poky-qemuarm64-scarthgap

# Execute single command
bsp shell poky-qemuarm64-scarthgap --command "bitbake core-image-minimal"

export โ€” Export BSP configuration

bsp export <bsp_name> [--output OUTPUT]
Option Description
--output OUTPUT, -o OUTPUT Output file path (default: stdout)

Examples:

# Print to stdout
bsp export poky-qemuarm64-scarthgap

# Save to file
bsp export poky-qemuarm64-scarthgap --output exported-config.yml

Registry Configuration Reference

The BSP registry is a YAML file with the following top-level sections:

specification

specification:
  version: "1.0"

environment

Global environment variables applied to all builds. Supports $ENV{VAR_NAME} expansion to reference system environment variables.

environment:
  - name: "GITCONFIG_FILE"
    value: "$ENV{HOME}/.gitconfig"
  - name: "DL_DIR"
    value: "$ENV{HOME}/yocto-cache/downloads"
  - name: "SSTATE_DIR"
    value: "$ENV{HOME}/yocto-cache/sstate"

Supported variables:

Variable Description
DL_DIR Yocto downloads cache directory
SSTATE_DIR Yocto shared state cache directory
GITCONFIG_FILE Git configuration file path

containers

Docker container definitions for build environments:

containers:
  - ubuntu-22.04:
      image: "my-registry/ubuntu-22.04/kas:4.7"
      file: Dockerfile.ubuntu
      args:
        - name: "DISTRO"
          value: "ubuntu:22.04"
        - name: "KAS_VERSION"
          value: "4.7"
  - ubuntu-20.04:
      image: "my-registry/ubuntu-20.04/kas:4.7"
      file: Dockerfile.ubuntu
      args:
        - name: "DISTRO"
          value: "ubuntu:20.04"

registry.bsp

List of BSP definitions:

registry:
  bsp:
    - name: my-bsp-name           # Unique identifier
      description: "My BSP"       # Human-readable description
      os:                         # Optional OS information
        name: linux
        build_system: yocto
        version: "5.0"
      build:
        path: build/my-bsp        # Build output directory
        environment:
          container: "ubuntu-22.04"   # Reference to containers section
          # OR use direct Docker configuration:
          # docker:
          #   image: "my-image:latest"
        configuration:            # KAS configuration files (in order)
          - kas/scarthgap.yml
          - kas/qemu/qemuarm64.yml

KAS Configuration Files

KAS configuration files define Yocto layer repositories, machine settings, and build targets. See the examples/kas/ directory for reference configurations.

QEMU Example Configurations

The examples/ directory contains ready-to-use KAS configurations for QEMU targets:

File Description
examples/kas/scarthgap.yml Yocto Scarthgap (5.0 LTS) base configuration
examples/kas/styhead.yml Yocto Styhead (5.1) base configuration
examples/kas/qemu/qemuarm64.yml QEMU ARM64 machine configuration
examples/kas/qemu/qemux86-64.yml QEMU x86-64 machine configuration
examples/kas/qemu/qemuarm.yml QEMU ARM (32-bit) machine configuration

KAS File Structure

header:
  version: 14
  includes:            # Optional: include other KAS files
    - base.yml

distro: poky
machine: qemuarm64

target:
  - core-image-minimal

repos:
  poky:
    url: "https://git.yoctoproject.org/poky"
    commit: "abc123..."
    path: "layers/poky"
    layers:
      meta:
      meta-poky:

local_conf_header:
  my_config: |
    DISTRO_FEATURES += "x11"

Python API

You can also use bsp-registry-tools as a Python library:

from bsp import BspManager, EnvironmentManager, KasManager

# Load and manage BSP registry
manager = BspManager("bsp-registry.yml")
manager.initialize()

# List BSPs programmatically
for bsp in manager.model.registry.bsp:
    print(f"{bsp.name}: {bsp.description}")

# Get a specific BSP
bsp = manager.get_bsp_by_name("poky-qemuarm64-scarthgap")

# Environment variable management with $ENV{} expansion
from bsp import EnvironmentVariable
env_vars = [
    EnvironmentVariable(name="DL_DIR", value="$ENV{HOME}/downloads"),
]
env_manager = EnvironmentManager(env_vars)
print(env_manager.get_value("DL_DIR"))  # Expanded path

# Use KasManager directly
kas = KasManager(
    kas_files=["kas/scarthgap.yml", "kas/qemu/qemuarm64.yml"],
    build_dir="build/my-bsp",
    use_container=False,
)
kas.validate_kas_files()

Development

Setup Development Environment

git clone https://github.com/Advantech-EECC/bsp-registry-tools.git
cd bsp-registry-tools
pip install -e ".[dev]"

Running Tests

# Run all tests
pytest

# Run with verbose output
pytest -v

# Run with coverage report
pytest --cov=bsp --cov-report=term-missing

# Run specific test class
pytest tests/test_bsp.py::TestEnvironmentManager -v

Project Structure

bsp-registry-tools/
โ”œโ”€โ”€ bsp.py                    # Main module
โ”œโ”€โ”€ pyproject.toml            # Package configuration
โ”œโ”€โ”€ README.md                 # This file
โ”œโ”€โ”€ LICENSE                   # MIT License
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ test_bsp.py           # Comprehensive pytest tests
โ”œโ”€โ”€ examples/
โ”‚   โ”œโ”€โ”€ bsp-registry.yml      # Sample BSP registry for QEMU targets
โ”‚   โ””โ”€โ”€ kas/
โ”‚       โ”œโ”€โ”€ scarthgap.yml     # Yocto Scarthgap base config
โ”‚       โ”œโ”€โ”€ styhead.yml       # Yocto Styhead base config
โ”‚       โ””โ”€โ”€ qemu/
โ”‚           โ”œโ”€โ”€ qemuarm64.yml  # QEMU ARM64 machine config
โ”‚           โ”œโ”€โ”€ qemux86-64.yml # QEMU x86-64 machine config
โ”‚           โ””โ”€โ”€ qemuarm.yml    # QEMU ARM machine config
โ””โ”€โ”€ .github/
    โ””โ”€โ”€ workflows/
        โ”œโ”€โ”€ tests.yml         # CI: run tests on push/PR
        โ””โ”€โ”€ publish.yml       # CD: publish to PyPI on release

Publishing to PyPI

This repository uses GitHub Actions for automated publishing.

Setup

  1. Create PyPI and TestPyPI accounts and configure Trusted Publishers:

    • PyPI: Add GitHub Actions publisher for Advantech-EECC/bsp-registry-tools
    • TestPyPI: Same configuration on test.pypi.org
  2. Create GitHub Environments named pypi and testpypi in your repository settings.

Publish Workflow

Automatic (on GitHub Release):

  • Creating a non-prerelease GitHub Release automatically publishes to both TestPyPI and PyPI.
  • Creating a prerelease publishes to TestPyPI only.

Manual:

GitHub โ†’ Actions โ†’ "Publish to PyPI" โ†’ Run workflow โ†’ Select environment

Build Locally

pip install build
python -m build
# Artifacts are in dist/

Architecture

Classes

Class Description
BspManager Main coordinator for BSP operations
KasManager Handles KAS build system operations
EnvironmentManager Manages build environment variables with $ENV{} expansion
PathResolver Utility for path resolution and validation

Data Classes

Class Description
RegistryRoot Root registry container
Registry Contains list of BSP definitions
BSP Single BSP definition
BuildSetup Build configuration (path, environment, KAS files)
BuildEnvironment Docker/container settings
Docker Docker image and build arg configuration
EnvironmentVariable Name/value pair with $ENV{} expansion support

Exceptions

Exception Description
ScriptError Base exception for all script errors
ConfigurationError Configuration file issues
BuildError Build process failures
DockerError Docker operation failures
KasError KAS operation failures

License

This project is licensed under the Apache 2.0 License โ€” see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bsp_registry_tools-0.0.1.3.tar.gz (40.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bsp_registry_tools-0.0.1.3-py3-none-any.whl (34.2 kB view details)

Uploaded Python 3

File details

Details for the file bsp_registry_tools-0.0.1.3.tar.gz.

File metadata

  • Download URL: bsp_registry_tools-0.0.1.3.tar.gz
  • Upload date:
  • Size: 40.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bsp_registry_tools-0.0.1.3.tar.gz
Algorithm Hash digest
SHA256 cb617d013f95b3e6e9c8c52e0a06aa91dfa9e9baba8678b312dc97b60a7ddb52
MD5 6328e5d17dcc29ff7e43b37725557b0c
BLAKE2b-256 f9550f6a0402760d8200f220d8a712f0d82b6e5d6da95aa0e69b14f4462ebe5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for bsp_registry_tools-0.0.1.3.tar.gz:

Publisher: publish.yml on Advantech-EECC/bsp-registry-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bsp_registry_tools-0.0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for bsp_registry_tools-0.0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 65814f436f4924d7a72934abceba9fc12a2deb4f8b230b1225837ba240508707
MD5 32f874ab7e2d98ef6e84f5e4e5e18dc7
BLAKE2b-256 cf1792313f18b0b1a6bd0d0dca5f545b3a24a65ea55979efa49f55ade2d5081e

See more details on using hashes here.

Provenance

The following attestation bundles were made for bsp_registry_tools-0.0.1.3-py3-none-any.whl:

Publisher: publish.yml on Advantech-EECC/bsp-registry-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page