Scriptsο
This document provides comprehensive analysis of the Python, Bash, and PowerShell scripts found in the directories .github/, Examples/.github/, Utilities/Scripts/ including environment tools.
Script Usage Overviewο
Script |
Where/When/Who Calls It |
Purpose |
|---|---|---|
CMake post-build in |
Merges app service/GUI binaries with icons/resources into a final app package during build or manually. |
|
CMake post-build in |
Packages ELF binaries with assets and version into .uapp containers in post-build steps. |
|
No external callers found in searched files; self-documented examples for manual use |
Converts input PNG images from RGBA to ABGR2222 byte arrays and generates C header files. |
|
Manual Windows SDK setup ( |
Exports STM32 tools during manual Windows environment setup. |
|
Sourced by |
Initializes UNA version and build metadata environment variables for Cube builds. |
|
Sourced by |
Locates STM32 CubeIDE installation and sets environment variables. |
|
Called in GitHub Actions apps-ci.yml |
Builds specified CubeIDE projects using prepared environment. |
|
Used in |
Prepares environment for CubeIDE builds by sourcing dependency scripts. |
|
GitHub Actions |
Generates list of tutorial apps in JSON format for CI workflows. |
|
generate-app-list.py |
GitHub Actions apps-ci.yml (runs to list projects and filter by app) |
Generates list of example app projects for CI build matrix. |
Script: Utilities/Scripts/app_merging/app_merging.py {#script-utilities-scripts-app_merging-app_merging-py}ο
Overviewο
This Python script merges service and GUI ELF binaries into a unified UAPP format, incorporating icon conversion, version management, and CRC integrity checks.
Purposeο
To create deployable application packages for the UNA Watch platform by combining service and GUI components with metadata, icons, and integrity verification.
Functionalityο
The script performs comprehensive app packaging:
ELF binary validation and loading
Icon conversion from PNG to ABGR2222 format
Version parsing and metadata inclusion
Header construction with app identification
CRC calculation for integrity verification
Optional C header generation for embedded use
How It Worksο
Input Discovery: Scans output directory for newest .srv and .gui files
Icon Processing: Converts 30x30 and 60x60 PNG icons to ABGR2222 format with 90-degree rotation
Version Resolution: Parses semantic versions and determines LibC compatibility
Header Construction: Builds extended header with app ID, version, and metadata
Binary Merging: Combines service, GUI, icons, and header into single blob
Integrity Check: Appends CRC32 for verification
Output Generation: Creates .uapp file and optional .h header
Key Parametersο
-name: Application name for output file naming-autostart: Sets autostart flag in app metadata-glance_capable: Marks app as Glance-compatible-type: App type (Activity, Utility, Glance, Clockface)-out: Custom output directory-header: Generate C header file-normal_icon: Path to 60x60 icon PNG-small_icon: Path to 30x30 icon PNG-appid: 16-hex AppID-appver: App version in A.B.C format-scripts: Path to SDK Scripts directory
Dependenciesο
Python 3 with PIL (Pillow) for image processing
zlib for CRC32 calculation
pathlib and struct for file and binary operations
argparse for command-line parsing
Usage Examplesο
Basic app merging:
python app_merging.py -name MyApp -type Activity -out Output -normal_icon icon60.png -small_icon icon30.png -appid 0123456789ABCDEF -appver 1.0.0 -scripts /path/to/Scripts
Creates MyApp_1.0.0.uapp with merged binaries and icons.
With autostart and header:
python app_merging.py -name MyApp -autostart -header -type Utility -out Output -normal_icon icon60.png -small_icon icon30.png -appid 0123456789ABCDEF -appver 1.1.0 -scripts /path/to/Scripts
Generates both .uapp and .h files with autostart capability.
Error Handlingο
Validates icon dimensions and formats
Ensures required binaries exist in output directory
Verifies CRC integrity of input files
Checks app ID format and version syntax
Validates linker script and LibC version parsing
Integration Contextο
Core component of the app build pipeline, transforming compiled binaries into deployable packages. Used after separate service and GUI builds to create unified applications for the watch platform.
Script: Utilities/Scripts/app_packer/app_packer.py {#script-utilities-scripts-app_packer-app_packer-py}ο
Overviewο
This Python script converts ELF binaries into custom UAPP format packages, incorporating relocation handling, section padding, and optional C header generation for embedded deployment.
Purposeο
To package ARM ELF binaries into a self-contained format suitable for loading on embedded targets, with support for dynamic relocation and memory layout management.
Functionalityο
The script provides comprehensive ELF processing:
ELF file parsing and section analysis
Relocation table generation for runtime linking
Section padding and memory layout calculation
Header construction with metadata
CRC integrity verification
Flexible output naming with custom extensions
How It Worksο
ELF Analysis: Parses sections, identifies loadable segments, and calculates padding
Relocation Processing: Extracts ARM relocation information for runtime application
Memory Layout: Assembles sections with proper alignment and padding patterns
Header Generation: Creates UAPP header with size and relocation metadata
Binary Assembly: Combines header, relocation table, and section data
Integrity Check: Appends CRC32 for verification
Output Creation: Generates .uapp file (or custom extension) and optional C header
Key Parametersο
-e, --elf: Path to input ELF file (required)-o, --out: Output directory (required)-v, --version: Version in major.minor format (default: 1.0)-header: Generate C header alongside binary-ext: Custom file extension (changes output filename to <elf_basename>.)
Dependenciesο
Python 3 runtime environment
pyelftools: For ELF file parsing and analysis
zlib: For CRC32 calculation
argparse and struct: For command-line and binary operations
Usage Examplesο
Standard UAPP generation:
python app_packer.py -e app.elf -o Output -v 1.2
Creates userapp_1.2.uapp from app.elf
With custom extension and header:
python app_packer.py -e firmware.elf -o Output -v 2.1 -ext bin -header
Generates firmware.bin and firmware.h
Error Handlingο
Validates ELF file structure and section sizes
Ensures sections are 4-byte aligned
Checks for unhandled section types
Reports missing or oversized sections
Verifies version format
Integration Contextο
Used in post-build processing to convert standard ELF outputs into custom embedded formats. Supports different deployment scenarios through flexible naming and header generation options.
Script: Utilities/Scripts/png2abgr2222/png2abgr2222.py {#script-utilities-scripts-png2abgr2222-png2abgr2222-py}ο
Overviewο
This Python script converts RGBA PNG images to ABGR2222 compressed format, generating C headers with embedded byte arrays and metadata macros for embedded graphics.
Purposeο
To provide compressed icon data for embedded systems, converting standard PNG files into a compact 2-bit-per-channel format suitable for limited-color displays.
Functionalityο
The script offers comprehensive image conversion:
PNG loading and validation (square images required)
90-degree rotation for proper orientation
Color reduction to 2 bits per channel (ABGR2222)
C header generation with arrays and macros
Support for multiple input files in single header
How It Worksο
Image Loading: Opens PNG files and validates square dimensions
Transformation: Rotates 90 degrees clockwise and converts to ABGR2222
Color Processing: Reduces each RGBA channel to 2 bits, packs into single byte
Symbol Generation: Creates valid C identifiers from filenames
Header Creation: Generates pragma-once header with arrays and size macros
Key Parametersο
--inputs: One or more input PNG files (required)-o, --out: Output header file path (default: derived from first input)--name: Base symbol name for single-input files--prefix: Optional prefix for generated symbols
Dependenciesο
Python 3 with PIL (Pillow) library
pathlib and argparse for file and argument handling
Usage Examplesο
Single icon conversion:
python png2abgr2222.py --inputs icon.png -o icon.h
Creates icon.h with ABGR2222 data and macros
Multiple icons with custom prefix:
python png2abgr2222.py --inputs icon1.png icon2.png -o icons.h --prefix APP_
Generates icons.h with APP_ICON1 and APP_ICON2 symbols
Custom symbol name:
python png2abgr2222.py --inputs battery.png --name BATTERY_ICON -o battery.h
Error Handlingο
Validates input files exist and are PNG format
Ensures images are square (width == height)
Checks for valid symbol name generation
Reports conversion progress and output location
Integration Contextο
Essential for embedded GUI development, converting designer-provided PNG assets into compressed formats suitable for watch displays. Integrates with build systems to generate headers for static icon inclusion.
Script: Utilities/Scripts/export-stm32-tools.ps1 {#script-utilities-scripts-export-stm32-tools-ps1}ο
Overviewο
This PowerShell script automates the detection and configuration of essential STM32 development tools on Windows systems. It locates common toolchains and utilities (arm-none-eabi-gcc, make, cmake, python), adds their directories to the user PATH permanently, and sets the UNA_SDK environment variable pointing to the SDK root directory.
Purposeο
The primary purpose is to simplify environment setup for UNA Watch SDK development on Windows. By automatically discovering installed tools in standard locations and updating the PATH, it eliminates manual configuration steps required for building STM32-based applications using CMake, Make, and the ARM GCC toolchain.
Functionalityο
The script provides:
Tool Discovery: Searches PATH first, then common installation directories for required executables
PATH Management: Identifies unique tool directories not already in user PATH and appends them permanently
Environment Setup: Permanently sets UNA_SDK environment variable with forward-slashed SDK root path
Dry-Run Preview: Optional mode to preview changes without applying them
How It Worksο
SDK Root Calculation: Determines SDK root by navigating three parent directories from script location using
Split-PathTool Definition: Maps tool names to descriptions (arm-none-eabi-gcc β STM32 Toolchain GCC, etc.)
Search Strategy:
Attempts
Get-Commandfor each toolFalls back to recursive search in base directories:
%USERPROFILE%\AppData\Local\Programs,C:\Program Files (x86),C:\Program Files,C:\ST
Path Deduplication: Collects unique directories, filters those absent from current user PATH
Execution Modes:
DryRun: Outputs preview of paths to add and new PATH/UNA_SDK values
Normal: Updates user PATH via
[Environment]::SetEnvironmentVariableand sets UNA_SDK with forward slashes
Key Parametersο
-DryRun: Switch enabling preview mode; displays changes without modification
Dependenciesο
PowerShell: Native Windows PowerShell environment
Target Tools:
arm-none-eabi-gcc (STM32 ARM GCC toolchain)
make (GNU Make)
cmake (CMake build system)
python (Python interpreter)
Installation Locations: Tools must be in PATH or standard directories like Program Files or C:\ST
Usage Examplesο
Preview changes (dry run):
powershell.exe -ExecutionPolicy Bypass -File "Utilities/Scripts/export-stm32-tools.ps1" -DryRun
Output shows paths to add and UNA_SDK value.
Apply environment setup:
powershell.exe -ExecutionPolicy Bypass -File "Utilities/Scripts/export-stm32-tools.ps1"
Permanently updates PATH and sets UNA_SDK.
Run from PowerShell directly:
& "Utilities/Scripts/export-stm32-tools.ps1"
Error Handlingο
Uses
try-catchblocks aroundGet-Commandto handle missing tools gracefullyContinues processing even if individual tools are not found, warning via
Write-HostNo script termination on missing tools; focuses on configuring available ones
Silently handles inaccessible search directories with
-ErrorAction SilentlyContinue
Integration Contextο
Designed as a one-time setup script for Windows developers working with the UNA Watch SDK. It prepares the environment for cross-platform build tools (CMake, Make) and STM32-specific toolchain, enabling seamless building of examples and applications. Typically run after tool installation (STM32CubeIDE, MSYS2, etc.) and before using CMake-based workflows or STM32CubeIDE projects.
Script: Utilities/Scripts/build-cube/una-version.sh {#script-utilities-scripts-build-cube-una-version-sh}ο
Overviewο
This comprehensive Bash script determines the build version for UNA Watch projects based on Git repository state, supporting semantic versioning, tags, and dirty state detection.
Purposeο
To provide accurate version information for builds, enabling proper versioning of binaries and documentation of build provenance in CI/CD environments.
Functionalityο
The script implements sophisticated version detection:
Git repository state analysis
Semantic version parsing from tags
Dirty state detection for uncommitted changes
Safe directory configuration for Docker environments
Fallback to default version when Git is unavailable
How It Worksο
Git Availability Check: Verifies git command availability, falls back to default version if unavailable
Build Version Override: Uses existing BUILD_VERSION if already set
Directory Setup: Changes to specified or current directory for Git operations
Safe Directory Config: Configures Git safe.directory for containerized environments
Repository Analysis: Determines if in a Git repository, extracts version from tags or commit hashes
Version Construction: Builds version string based on tags, commits, and dirty state
Key Parametersο
$1: Optional directory path to use for version detection (defaults to current directory)
Dependenciesο
Git: Primary version detection mechanism
Standard Bash utilities: For string manipulation and file operations
Usage Examplesο
Get version for current directory:
./una-version.sh echo $BUILD_VERSION
Output: Version string like β1.2.3β, β1.2.3-abc1234β, or β1.2.3-abc1234-dirtyβ
Get version for specific directory:
./una-version.sh /path/to/repo
Error Handlingο
Gracefully handles non-Git environments with default version
Manages Git dubious ownership issues in Docker
Logs detailed information about version detection process
Exits early if version already set or Git unavailable
Integration Contextο
Critical component of build systems, ensuring that all built artifacts include accurate version metadata. Supports CI/CD by providing consistent versioning across different build environments.
Script: Utilities/Scripts/build-cube/find-cube.sh {#script-utilities-scripts-build-cube-find-cube-sh}ο
Overviewο
This Bash script locates and configures the STM32CubeIDE environment, including setting up necessary paths and installing system dependencies for headless builds.
Purposeο
To automate the detection and setup of STM32CubeIDE installation and required build tools in headless Linux environments, ensuring consistent build environments across different systems.
Functionalityο
The script performs:
Installation of system dependencies (Python, Git, PIL)
Detection of STM32CubeIDE installation directory
Verification of arm-none-eabi-objcopy tool availability
Environment variable setup for build tools
How It Worksο
Dependency Installation: Uses apt to install required packages for build processes
Path Configuration: Sets PATH to include tool directories
IDE Detection: Scans /opt/st/ for STM32CubeIDE installations, selecting the latest version
Tool Verification: Checks for presence and executability of arm-none-eabi-objcopy
Environment Setup: Exports PATH and reports tool locations
Key Parametersο
No command-line parameters. All operations are automatic based on system state.
Dependenciesο
apt package manager: For system dependency installation
STM32CubeIDE: Must be installed in /opt/st/stm32cubeide_*/ directory structure
System packages: python3, python3-bincopy, python3-git, python3-pil, python-is-python3
Usage Examplesο
Setup build environment:
source ./find-cube.sh
This installs dependencies, locates CubeIDE, and sets up PATH for subsequent build operations.
Error Handlingο
Exits with error if STM32CubeIDE is not found in expected locations
Exits with error if arm-none-eabi-objcopy is missing
Lists available STM32CubeIDE installations for debugging if not found
Integration Contextο
Used as part of the build setup process in CI/CD pipelines. The script ensures that all necessary tools are available and properly configured before attempting CubeIDE builds.
Script: Utilities/Scripts/build-cube/build-cube.sh {#script-utilities-scripts-build-cube-build-cube-sh}ο
Overviewο
This Bash script provides automated headless building of STM32CubeIDE projects with integrated version management and preference patching capabilities.
Purposeο
To enable reliable, automated builds of STM32CubeIDE projects in headless environments (such as CI/CD systems) while automatically injecting build version information.
Functionalityο
The script handles:
Version detection from Git repository state
Patching of Eclipse project preferences with build version
Execution of headless STM32CubeIDE build process
Proper error handling and status reporting
How It Worksο
Version Sourcing: Sources the
una-version.shscript to determine BUILD_VERSIONPath Derivation: Extracts project name from IMPORT_PATH and sets up build data directory
Preference Patching: Locates and modifies the projectβs Eclipse preferences file to inject BUILD_VERSION
Headless Build: Executes STM32CubeIDE with headless build parameters
Status Reporting: Captures and reports build exit codes
Key Parametersο
IMPORT_PATH: Required path to the STM32CubeIDE project directory to be built
Dependenciesο
STM32CubeIDE: Must be installed and accessible via PATH or /opt/st/
Git: For version detection and repository state checking
una-version.sh: Companion script for version determination
Eclipse project structure: Expects standard CubeIDE project layout with .settings/org.eclipse.cdt.core.prefs
Usage Examplesο
Build a specific CubeIDE project:
./build-cube.sh /path/to/MyProjectThis will build the project, patching version information and storing build artifacts.
Integration in CI/CD:
export UNA_WORKSPACE=/path/to/sdk ./build-cube.sh $UNA_WORKSPACE/Examples/Apps/MyApp/Software/Apps/MyApp-CubeIDE
Error Handlingο
Exits with error code if IMPORT_PATH is not provided
Continues without version patching if BUILD_VERSION is not set
Reports build failure exit codes from STM32CubeIDE
Warns if preferences file is not found but continues build
Integration Contextο
Designed for use in automated build environments. The version patching ensures that built binaries include proper version metadata, while the headless build capability allows integration with continuous integration systems that donβt have graphical interfaces.
Script: Utilities/Scripts/build-cube/setup-environment.sh {#script-utilities-scripts-build-cube-setup-environment-sh}ο
Overviewο
This Bash script serves as a high-level setup script that coordinates the environment preparation for STM32CubeIDE builds by sourcing dependent setup scripts.
Purposeο
To provide a single entry point for setting up the complete STM32CubeIDE build environment, including tool detection and version management.
Functionalityο
The script orchestrates the setup process by:
Displaying setup progress messages
Updating PATH with build-cube script directory
Sourcing the find-cube.sh script for tool detection
Sourcing the una-version.sh script with optional version parameter
How It Worksο
Path Setup: Adds the build-cube directory to PATH for script accessibility
Tool Detection: Sources find-cube.sh to locate and configure STM32CubeIDE
Version Detection: Sources una-version.sh to determine build version, optionally passing a directory parameter
Key Parametersο
$1: Optional directory parameter passed to una-version.sh for version detection context
Dependenciesο
find-cube.sh: For STM32CubeIDE tool detection and setup
una-version.sh: For build version determination
UNA_SDK environment variable: Expected to point to SDK root directory
Usage Examplesο
Setup environment for current directory:
./setup-environment.sh
Setup with specific directory for version detection:
./setup-environment.sh /path/to/project
Error Handlingο
Inherits error handling from sourced scripts
Displays setup progress and completion messages
Integration Contextο
Acts as a coordinator script in build pipelines, ensuring all prerequisites are met before proceeding with STM32CubeIDE builds. Commonly used in automated build environments.
Script: .github/scripts/generate-tutorials-app-list.py {#script-github-scripts-generate-tutorials-app-list-py}ο
Overviewο
This Python script is designed to generate a list of CMake-based application projects within the tutorials directory structure. It traverses the Docs/Tutorials directory to identify and catalog CMake projects, while providing flexibility to exclude certain applications and generate project-specific lists.
Purposeο
The primary purpose of this script is to automate the discovery and listing of tutorial applications that use CMake build systems. It supports CI/CD workflows by providing a programmatic way to enumerate buildable tutorial projects, with built-in exclusion capabilities for managing which applications should be included in builds or deployments.
Functionalityο
The script operates in two main modes:
General mode: Scans the entire tutorials directory and outputs a JSON object containing all discovered CMake applications
App-specific mode: When called with the
--appflag, it lists the specific CMake project directories for a given application name
How It Worksο
Directory Traversal: Uses
os.walk()to recursively traverse theDocs/TutorialsdirectoryDirectory Filtering: Applies exclusion rules to skip hidden directories, build artifacts, and other irrelevant folders
Project Discovery: Identifies directories ending with
-CMakeas valid project directoriesApp Name Extraction: Derives application names from the directory structure relative to the tutorials base path
Exclusion Handling: Reads the
APPS_EXCLUDEDenvironment variable to filter out specified applicationsOutput Generation: Produces either a newline-separated list of project paths (app-specific mode) or JSON output (general mode)
Key Parametersο
--app <app_name>: Optional command-line argument to generate project list for a specific applicationAPPS_EXCLUDED: Environment variable containing newline-separated list of application names to exclude
Dependenciesο
Python 3: The script uses Python 3 features and syntax
Standard Library Modules:
os: For file system operations and path manipulationjson: For generating JSON output in general modesys: For command-line argument processing and error output
Usage Examplesο
Generate complete app list:
python3 .github/scripts/generate-tutorials-app-list.pyOutput:
{"cmake_apps": ["Buttons", "Display", "Touch"]}
Generate projects for specific app:
python3 .github/scripts/generate-tutorials-app-list.py --app Buttons
Output:
/path/to/Docs/Tutorials/Buttons/Software/Buttons-CMake
Exclude specific apps via environment:
APPS_EXCLUDED="OldTutorial DeprecatedApp" python3 .github/scripts/generate-tutorials-app-list.py
Error Handlingο
Validates the presence of app name when
--appflag is usedGracefully handles cases where excluded apps are requested
Uses standard error output for error messages
Integration Contextο
This script appears to be part of a GitHub Actions workflow system, likely used in CI/CD pipelines to dynamically determine which tutorial projects need to be built or tested. The exclusion mechanism allows for flexible project management without code changes.
Script: Examples/.github/scripts/generate-app-list.py {#script-examples-github-scripts-generate-app-list-py}ο
Overviewο
This Python script serves as a discovery tool for application projects in the examples directory, supporting both CMake and CubeIDE build systems. It provides comprehensive project enumeration capabilities with exclusion support, designed for automated build and deployment workflows.
Purposeο
The script facilitates automated discovery and categorization of example applications across different IDE and build system configurations. It enables CI/CD systems to programmatically identify buildable projects while maintaining flexibility through exclusion mechanisms.
Functionalityο
The script operates in two primary modes:
General mode: Performs a comprehensive scan of the examples directory, categorizing applications by build system (CMake vs CubeIDE)
App-specific mode: Generates a list of project directories for a specific application across all supported build systems
How It Worksο
Directory Scanning: Recursively walks through the
Examples/Appsdirectory usingos.walk()Exclusion Filtering: Applies predefined rules to skip irrelevant directories (hidden, generated, build artifacts)
Project Classification: Identifies project directories by examining naming patterns:
-CMakesuffix indicates CMake-based projects-CubeIDEsuffix indicates STM32CubeIDE projects
Application Grouping: Extracts application names from the directory hierarchy relative to the Apps base path
Exclusion Processing: Filters applications based on the
APPS_EXCLUDEDenvironment variableOutput Formatting: Produces either newline-separated project paths (app-specific mode) or structured JSON (general mode)
Key Parametersο
--app <app_name>: Command-line flag to generate project list for a specific applicationAPPS_EXCLUDED: Environment variable with newline-separated application names to exclude from processing
Dependenciesο
Python 3: Requires Python 3 runtime environment
Standard Library Modules:
os: Handles file system navigation and path operationsjson: Enables JSON output generation for structured datasys: Manages command-line arguments and error reporting
Usage Examplesο
Generate complete categorized app list:
python3 Examples/.github/scripts/generate-app-list.pyOutput:
{ "cmake_apps": ["Alarm", "Cycling", "Fitness"], "cubeide_apps": ["Alarm", "Cycling"] }
List projects for specific application:
python3 Examples/.github/scripts/generate-app-list.py --app Alarm
Output:
/path/to/Examples/Apps/Alarm/Software/Apps/Alarm-CMake /path/to/Examples/Apps/Alarm/Software/Apps/AlarmGUI-CubeIDE /path/to/Examples/Apps/Alarm/Software/Apps/AlarmService-CubeIDE
Exclude applications during processing:
APPS_EXCLUDED="BetaApp Prototype" python3 Examples/.github/scripts/generate-app-list.py
Error Handlingο
Enforces required app name argument when using
--appflagSilently handles requests for excluded applications by producing no output
Directs error messages to standard error stream
Integration Contextο
This script is likely a component of GitHub Actions workflows for example project CI/CD. It supports multi-platform build automation by distinguishing between CMake (cross-platform) and CubeIDE (STM32-specific) projects, enabling targeted build strategies for different development environments.