diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index 25120562..0875e28e 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -8,9 +8,10 @@ on: type: choice required: true options: - - raspberry-pi64 - - banana-pi-r3 - default: 'raspberry-pi64' + - raspberrypi-rpi64 + - bananapi-bpi-r3 + - friendlyarm-nanopi-r2s + default: 'raspberrypi-rpi64' use_latest_release: description: 'Use latest release artifacts instead of workflow artifacts' type: boolean @@ -52,14 +53,18 @@ jobs: - name: Set bootloader and target based on board run: | case "${{ inputs.board }}" in - raspberry-pi64) + raspberrypi-rpi64) echo "BOOTLOADER=rpi4_boot" >> $GITHUB_ENV echo "TARGET=aarch64" >> $GITHUB_ENV ;; - banana-pi-r3) + bananapi-bpi-r3) echo "BOOTLOADER=mt7986_sd_boot" >> $GITHUB_ENV echo "TARGET=aarch64" >> $GITHUB_ENV ;; + friendlyarm-nanopi-r2s) + echo "BOOTLOADER=nanopi_r2s_boot" >> $GITHUB_ENV + echo "TARGET=aarch64" >> $GITHUB_ENV + ;; *) echo "Error: Unknown board ${{ inputs.board }}" exit 1 @@ -144,19 +149,7 @@ jobs: export BR2_EXTERNAL_INFIX_PATH=$PWD export RELEASE="" export INFIX_ID="infix" - - # Use the standardized mkimage.sh path for the selected board - # BOARD_SCRIPT="src/board/${{ inputs.board }}/mkimage.sh" - BOARD_SCRIPT="src/board/${{ inputs.board }}/mkimage.sh" - - if [ -f "$BOARD_SCRIPT" ]; then - echo "Using board-specific image creation script: $BOARD_SCRIPT" - chmod +x "$BOARD_SCRIPT" - "$BOARD_SCRIPT" - else - echo "Error: Board script $BOARD_SCRIPT not found!" - exit 1 - fi + ./utils/mkimage.sh ${{ inputs.board }} - name: Verify created image run: | @@ -183,7 +176,7 @@ jobs: with: name: sdcard-image-${{ inputs.board }}-${{ env.BOOTLOADER }} path: | - output/images/*-sdcard.img + output/images/*-sdcard.img* retention-days: 30 - name: Create checksums @@ -218,7 +211,7 @@ jobs: **Artifact Source:** ${{ inputs.use_latest_release && 'Latest Release' || 'Latest Workflow Run' }} ## Created Images - $(find output/images/ -name "*.img" -o -name "*.qcow2" -o -name "*.raw" | xargs ls -lh 2>/dev/null | sed 's/^/- /' || echo "- No images found") + $(find output/images/ -name "*.img*" -o -name "*.qcow2" -o -name "*.raw" | xargs ls -lh 2>/dev/null | sed 's/^/- /' || echo "- No images found") ## Download The SD card image is available as a workflow artifact above. diff --git a/board/aarch64/bananapi-bpi-r3/mkimage.sh b/board/aarch64/bananapi-bpi-r3/mkimage.sh deleted file mode 100755 index b61cbabc..00000000 --- a/board/aarch64/bananapi-bpi-r3/mkimage.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -set -e - -TARGET=sd - -BOARD_DIR=$(dirname "$0") -GENIMAGE_CFG="${BUILD_DIR}/genimage.cfg" -GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp" - -sed "s|#VERSION#|${RELEASE}|" "${BOARD_DIR}/genimage.cfg.in" | \ -sed "s|#TARGET#|${TARGET}|" | \ -sed "s|#INFIX_ID#|${INFIX_ID}|" > "${GENIMAGE_CFG}" - -# Create temporary root path -ROOTPATH_TMP=$(mktemp -d) -trap 'rm -rf \"$ROOTPATH_TMP\"' EXIT - -# Clean previous genimage temp directory -rm -rf "${GENIMAGE_TMP}" - -# Generate the SD card image -genimage \ - --rootpath "${ROOTPATH_TMP}" \ - --tmppath "${GENIMAGE_TMP}" \ - --inputpath "${BINARIES_DIR}" \ - --outputpath "${BINARIES_DIR}" \ - --config "${GENIMAGE_CFG}" diff --git a/board/aarch64/friendlyarm-nanopi-r2s/genimage.cfg b/board/aarch64/friendlyarm-nanopi-r2s/genimage.cfg.in similarity index 95% rename from board/aarch64/friendlyarm-nanopi-r2s/genimage.cfg rename to board/aarch64/friendlyarm-nanopi-r2s/genimage.cfg.in index a7513740..6a069181 100644 --- a/board/aarch64/friendlyarm-nanopi-r2s/genimage.cfg +++ b/board/aarch64/friendlyarm-nanopi-r2s/genimage.cfg.in @@ -19,7 +19,7 @@ image var.ext4 { } } -image sdcard.img { +image #INFIX_ID##VERSION#-nanopi-r2s-sdcard.img { hdimage { partition-table-type = "gpt" } diff --git a/board/aarch64/raspberrypi-rpi64/mkimage.sh b/board/aarch64/raspberrypi-rpi64/mkimage.sh deleted file mode 100755 index fafeb593..00000000 --- a/board/aarch64/raspberrypi-rpi64/mkimage.sh +++ /dev/null @@ -1,211 +0,0 @@ -#!/bin/sh -set -e - -usage() -{ - cat <&2 - exit 1 - } - fi - fi - - # Find rootfs if not specified - if [ -z "$ROOT_DIR" ]; then - ROOT_DIR=$(find_build_dir) || { - echo "Error: Could not find rootfs directory. Set O= or use -r option" >&2 - exit 1 - } - fi - - # Set up environment variables (use BOOT_DIR as base) - export BINARIES_DIR="$BOOT_DIR/images" - export BUILD_DIR="$BOOT_DIR/build" - export BR2_EXTERNAL_INFIX_PATH - export RELEASE=${RELEASE:-""} - export INFIX_ID=${INFIX_ID:-"infix"} - - # Add host tools to PATH (for genimage, etc.) - for dir in "$BOOT_DIR" "$ROOT_DIR"; do - if [ -d "$dir/host/bin" ]; then - export PATH="$dir/host/bin:$PATH" - break - fi - done - - # Copy rootfs and partition images to boot directory - mkdir -p "$BINARIES_DIR" - if [ -f "$ROOT_DIR" ]; then - # Direct path to rootfs.squashfs file - echo "Copying rootfs from $ROOT_DIR to $BINARIES_DIR/rootfs.squashfs" - cp "$ROOT_DIR" "$BINARIES_DIR/rootfs.squashfs" - elif [ -f "$ROOT_DIR/images/rootfs.squashfs" ]; then - # Build directory with images/ - copy rootfs and partition images - echo "Copying rootfs and partitions from $ROOT_DIR/images/ to $BINARIES_DIR/" - cp "$ROOT_DIR/images/rootfs.squashfs" "$BINARIES_DIR/" - # Copy partition images (aux.ext4, cfg.ext4, var.ext4) if they exist - for img in aux.ext4 cfg.ext4 var.ext4; do - if [ -f "$ROOT_DIR/images/$img" ]; then - cp "$ROOT_DIR/images/$img" "$BINARIES_DIR/" - fi - done - elif [ -f "$ROOT_DIR/rootfs.squashfs" ]; then - # Directory directly containing rootfs.squashfs - echo "Copying rootfs from $ROOT_DIR/rootfs.squashfs to $BINARIES_DIR/" - cp "$ROOT_DIR/rootfs.squashfs" "$BINARIES_DIR/" - # Copy partition images if they exist in same directory - for img in aux.ext4 cfg.ext4 var.ext4; do - if [ -f "$ROOT_DIR/$img" ]; then - cp "$ROOT_DIR/$img" "$BINARIES_DIR/" - fi - done - else - echo "Error: Could not find rootfs.squashfs in $ROOT_DIR" >&2 - exit 1 - fi -fi - -BOARD_DIR=$(dirname "$0") -GENIMAGE_CFG="${BUILD_DIR}/genimage.cfg" -GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp" - -# We've asked U-Boot previously to build overlays for us: Infix signing -# key and our ixboot scripts. Make sure here they are installed in the -# proper directory so genimage can create the DOS partition the SPL -# reads config.txt from. -find "${BINARIES_DIR}" -type f -name '*.dtbo' ! -path "${BINARIES_DIR}/rpi-firmware/overlays/*" -exec \ - mv '{}' "${BINARIES_DIR}/rpi-firmware/overlays/" \; - -# Create FILES array for the genimage.cfg generation -FILES="" -for f in "${BINARIES_DIR}"/rpi-firmware/*; do - case "$f" in - *~ | *.bak) - continue - ;; - esac - # If already exist it has been added by us. - echo "${FILES}" | grep -q "$(basename "$f")" && continue - FILES="${FILES}\t\t\t\"${f#"${BINARIES_DIR}/"}\",\n" -done - - -FILES="${FILES}\t\t\t\"splash.bmp\",\n" - -KERNEL=$(sed -n 's/^kernel=//p' "${BINARIES_DIR}/rpi-firmware/config.txt") -FILES="${FILES}\t\t\t\"${KERNEL}\"" - -# Create genimage.cfg from template .in -sed "s|#BOOT_FILES#|${FILES}|" "${BOARD_DIR}/genimage.cfg.in" | \ -sed "s|#INFIX_ID#|${INFIX_ID}|" | \ -sed "s|#VERSION#|${RELEASE}|" > "${GENIMAGE_CFG}" - -# Create temporary root path -ROOTPATH_TMP=$(mktemp -d) -trap 'rm -rf \"$ROOTPATH_TMP\"' EXIT - -# Clean previous genimage temp directory -rm -rf "${GENIMAGE_TMP}" - -# Generate the SD card image -genimage \ - --rootpath "${ROOTPATH_TMP}" \ - --tmppath "${GENIMAGE_TMP}" \ - --inputpath "${BINARIES_DIR}" \ - --outputpath "${BINARIES_DIR}" \ - --config "${GENIMAGE_CFG}" - -# Print the resulting image path -if [ "$STANDALONE" -eq 1 ]; then - echo "" - echo "SD card image created successfully:" - for img in "${BINARIES_DIR}"/*-sdcard.img; do - if [ -f "$img" ]; then - # Get relative path from current directory - rel_path=$(realpath --relative-to="$PWD" "$img" 2>/dev/null || echo "$img") - echo " $rel_path" - fi - done -fi diff --git a/configs/mt7986_sd_boot_defconfig b/configs/mt7986_sd_boot_defconfig index 7b76f885..af465dfe 100644 --- a/configs/mt7986_sd_boot_defconfig +++ b/configs/mt7986_sd_boot_defconfig @@ -31,6 +31,7 @@ BR2_TARGET_UBOOT_CONFIG_FRAGMENT_FILES="${BR2_EXTERNAL_INFIX_PATH}/board/common/ BR2_TARGET_UBOOT_NEEDS_DTC=y BR2_TARGET_UBOOT_FORMAT_DTB=y BR2_TARGET_UBOOT_CUSTOM_DTS_PATH="${BR2_EXTERNAL_INFIX_PATH}/src/board/banana-pi-r3/uboot/*.dtsi" +BR2_PACKAGE_HOST_BMAP_TOOLS=y BR2_PACKAGE_HOST_GENIMAGE=y BR2_PACKAGE_HOST_RAUC=y BR2_PACKAGE_HOST_UBOOT_TOOLS=y diff --git a/configs/nanopi_r2s_boot_defconfig b/configs/nanopi_r2s_boot_defconfig index 36bd87e3..2ea68514 100644 --- a/configs/nanopi_r2s_boot_defconfig +++ b/configs/nanopi_r2s_boot_defconfig @@ -37,6 +37,7 @@ BR2_TARGET_UBOOT_FORMAT_CUSTOM_NAME="u-boot.itb" BR2_TARGET_UBOOT_SPL=y BR2_TARGET_UBOOT_SPL_NAME="idbloader.img" BR2_TARGET_UBOOT_CUSTOM_DTS_PATH="$(BR2_EXTERNAL_INFIX_PATH)/board/aarch64/friendlyarm-nanopi-r2s/uboot/r2s-env.dtsi" +BR2_PACKAGE_HOST_BMAP_TOOLS=y BR2_PACKAGE_HOST_GENIMAGE=y BR2_PACKAGE_HOST_RAUC=y BR2_PACKAGE_HOST_UBOOT_TOOLS=y diff --git a/configs/rpi4_boot_defconfig b/configs/rpi4_boot_defconfig index 8bcefb01..e64e1e30 100644 --- a/configs/rpi4_boot_defconfig +++ b/configs/rpi4_boot_defconfig @@ -33,6 +33,7 @@ BR2_TARGET_UBOOT_FORMAT_DTB=y BR2_TARGET_UBOOT_FORMAT_CUSTOM=y BR2_TARGET_UBOOT_FORMAT_CUSTOM_NAME="arch/arm/dts/infix-key.dtbo arch/arm/dts/rpi-env.dtbo" BR2_TARGET_UBOOT_CUSTOM_DTS_PATH="${BR2_EXTERNAL_INFIX_PATH}/src/board/raspberry-pi64/uboot/rpi-env.dtso" +BR2_PACKAGE_HOST_BMAP_TOOLS=y BR2_PACKAGE_HOST_GENIMAGE=y BR2_PACKAGE_HOST_RAUC=y BR2_PACKAGE_HOST_UBOOT_TOOLS=y diff --git a/utils/mkimage.sh b/utils/mkimage.sh new file mode 100755 index 00000000..b2b25519 --- /dev/null +++ b/utils/mkimage.sh @@ -0,0 +1,357 @@ +#!/bin/sh +# Unified SD card image creation script for all boards +# Consolidates logic from board-specific mkimage.sh scripts +set -e + +STANDALONE="" +if [ -z "$BR2_EXTERNAL_INFIX_PATH" ]; then + SCRIPT_DIR=$(dirname "$0") + BR2_EXTERNAL_INFIX_PATH=$(cd "$SCRIPT_DIR/.." && pwd) +fi + +usage() +{ + cat < + +Options: + -h This help text + -l List available boards + -o Override auto-detection of genimage.sh, use host installed version + -b boot-dir Path to bootloader build directory (default: O= or output/) + -r root-dir Path to rootfs build directory or rootfs.squashfs file (default: O= or output/) + +Arguments: + board-name Board identifier (must come after options) + +Description: + When called from Buildroot (no options), uses environment variables: + BINARIES_DIR, BUILD_DIR, BR2_EXTERNAL_INFIX_PATH, RELEASE, INFIX_ID + + When called with -b/-r options, enters standalone mode and combines artifacts + from separate boot and rootfs sources. Useful for CI or manual image creation. + +Output: + SD card image saved to \$BINARIES_DIR/*-sdcard.img + +Examples: + # From Buildroot build: + $0 raspberrypi-rpi64 + + # Standalone with separate boot/rootfs builds: + $0 -b x-boot -r output raspberrypi-rpi64 + + # With downloaded rootfs: + $0 -b x-boot -r ~/Downloads/rootfs.squashfs friendlyarm-nanopi-r2s + +EOF +} + +log() +{ + printf '\033[7m>>> %s\033[0m\n' "$*" +} + +err() +{ + echo "Error: $*" >&2 +} + +die() +{ + err "$*" + exit 1 +} + +# List all supported boards by scanning for genimage.cfg.in files +list_boards() +{ + script_dir=$(dirname "$0") + board_base=$(cd "$script_dir/../board" 2>/dev/null && pwd) + + if [ -z "$board_base" ] || [ ! -d "$board_base" ]; then + echo "Error: Could not find board directory" >&2 + return 1 + fi + + echo "Available boards:" + find "$board_base" -name "genimage.cfg.in" -type f 2>/dev/null | \ + grep -v '/common/' | \ + sed 's|.*/board/\([^/]*\)/\([^/]*\)/.*| \2 (\1)|' | \ + sort -u +} + +# Run genimage directly (fallback when Buildroot wrapper not available) +run_genimage() +{ + genimage_cfg="$1" + genimage_tmp="${BUILD_DIR}/genimage.tmp" + rootpath_tmp=$(mktemp -d) + trap 'rm -rf "$rootpath_tmp"' EXIT + + rm -rf "$genimage_tmp" + + genimage \ + --rootpath "$rootpath_tmp" \ + --tmppath "$genimage_tmp" \ + --inputpath "${BINARIES_DIR}" \ + --outputpath "${BINARIES_DIR}" \ + --config "$genimage_cfg" + + if command -v bmaptool >/dev/null 2>&1; then + for img in "${BINARIES_DIR}"/*-sdcard.img; do + [ -f "$img" ] || continue + log "Generating block map for $(basename "$img")..." + bmaptool create -o "${img}.bmap" "$img" + done + fi +} + +# Validate board argument and find board directory +# Sets BOARD and BOARD_DIR globals or exits with error +validate_board() +{ + BOARD="$1" + if [ -z "$BOARD" ]; then + err "Board name required. Use -h for help." + return 1 + fi + + board_underscore=$(echo "$BOARD" | tr '-' '_') + for arch in aarch64 x86_64 riscv64; do + for variant in "$BOARD" "$board_underscore"; do + candidate="$BR2_EXTERNAL_INFIX_PATH/board/$arch/$variant" + if [ -d "$candidate" ]; then + BOARD_DIR="$candidate" + return 0 + fi + done + done + + err "Board directory not found for: $BOARD" + return 1 +} + +# Find build directory by checking O= or output/ +find_build_dir() +{ + # Check O= environment variable first + if [ -n "$O" ] && [ -f "$O/.config" ]; then + echo "$O" + return 0 + fi + + # Check output/ directory + if [ -f "output/.config" ]; then + echo "output" + return 0 + fi + + return 1 +} + +# Discover boot files for Raspberry Pi boot partition +# Scans rpi-firmware directory and builds file list for genimage +discover_rpi_boot_files() +{ + binaries_dir="$1" + files="" + + # Move any .dtbo overlays to proper location + find "${binaries_dir}" -type f -name '*.dtbo' ! -path "${binaries_dir}/rpi-firmware/overlays/*" -exec \ + mv '{}' "${binaries_dir}/rpi-firmware/overlays/" \; 2>/dev/null || true + + # Scan rpi-firmware directory for boot files + for f in "${binaries_dir}"/rpi-firmware/*; do + [ -e "$f" ] || continue + case "$f" in + *~ | *.bak) + continue + ;; + esac + # Skip if already in list + echo "${files}" | grep -q "$(basename "$f")" && continue + files="${files}\t\t\t\"${f#"${binaries_dir}/"}\",\n" + done + + # Add splash screen + files="${files}\t\t\t\"splash.bmp\",\n" + + # Add kernel (extract name from config.txt) + if [ -f "${binaries_dir}/rpi-firmware/config.txt" ]; then + kernel=$(sed -n 's/^kernel=//p' "${binaries_dir}/rpi-firmware/config.txt") + files="${files}\t\t\t\"${kernel}\"" + fi + + echo "$files" +} + +while getopts "hlob:r:" opt; do + case $opt in + h) + usage + exit 0 + ;; + l) + list_boards + exit 0 + ;; + b) + BOOT_DIR="$OPTARG" + STANDALONE=1 + ;; + o) + OVERRIDE=1 + ;; + r) + ROOT_DIR="$OPTARG" + STANDALONE=1 + ;; + *) + usage + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) + +if ! validate_board "$1"; then + usage + exit 1 +fi + +# Standalone mode: set up environment from build directories +if [ -n "$STANDALONE" ]; then + if [ -z "$BOOT_DIR" ]; then + BOOT_DIR=$(find_build_dir) || die "Could not find boot directory. Use -b option" + fi + + if [ -z "$ROOT_DIR" ]; then + ROOT_DIR=$(find_build_dir) || die "Could not find rootfs directory. Set O= or use -r option" + fi + + # Set up environment variables, some required by genimage.sh + export BINARIES_DIR="$BOOT_DIR/images" + export BUILD_DIR="$BOOT_DIR/build" + export BR2_EXTERNAL_INFIX_PATH + export RELEASE="${RELEASE:-""}" + export INFIX_ID="${INFIX_ID:-"infix"}" + + # Add host tools to PATH (for genimage, bmaptool, etc.) + for dir in "$BOOT_DIR" "$ROOT_DIR"; do + if [ -d "$dir/host/bin" ]; then + export PATH="$dir/host/bin:$PATH" + break + fi + done + + # Copy rootfs and partition images to BINARIES_DIR + mkdir -p "$BINARIES_DIR" + if [ -f "$ROOT_DIR" ]; then + # Direct path to rootfs.squashfs file + log "Copying rootfs from $ROOT_DIR to $BINARIES_DIR/rootfs.squashfs" + cp "$ROOT_DIR" "$BINARIES_DIR/rootfs.squashfs" + elif [ -f "$ROOT_DIR/images/rootfs.squashfs" ]; then + # Build directory with images/ - copy rootfs and partition images + log "Copying artifacts from $ROOT_DIR/images/ to $BINARIES_DIR/" + cp "$ROOT_DIR/images/rootfs.squashfs" "$BINARIES_DIR/" + # Copy partition images if they exist + for img in aux.ext4 cfg.ext4 var.ext4; do + if [ -f "$ROOT_DIR/images/$img" ]; then + cp "$ROOT_DIR/images/$img" "$BINARIES_DIR/" + fi + done + elif [ -f "$ROOT_DIR/rootfs.squashfs" ]; then + # Directory directly containing rootfs.squashfs + log "Copying rootfs from $ROOT_DIR/rootfs.squashfs" + cp "$ROOT_DIR/rootfs.squashfs" "$BINARIES_DIR/" + # Copy partition images if they exist + for img in aux.ext4 cfg.ext4 var.ext4; do + if [ -f "$ROOT_DIR/$img" ]; then + cp "$ROOT_DIR/$img" "$BINARIES_DIR/" + fi + done + else + die "Could not find rootfs.squashfs in $ROOT_DIR" + fi +else + # Export for Buildroot genimage.sh wrapper + export BINARIES_DIR + export BUILD_DIR +fi + +# Validate required environment variables +: "${BINARIES_DIR:?'not set'}" +: "${BUILD_DIR:?'not set'}" +: "${BR2_EXTERNAL_INFIX_PATH:?'not set'}" + +# Set defaults for optional variables +: "${RELEASE:=""}" +: "${INFIX_ID:="infix"}" + +# Template expansion +log "Generating genimage configuration for $BOARD..." + +GENIMAGE_CFG="${BUILD_DIR}/genimage.cfg" +GENIMAGE_TEMPLATE="$BOARD_DIR/genimage.cfg.in" +[ -f "$GENIMAGE_TEMPLATE" ] || die "genimage.cfg.in not found in $BOARD_DIR" + +# Check if board needs special boot file discovery (Raspberry Pi) +if [ "$BOARD" = "raspberrypi-rpi64" ] && grep -q '#BOOT_FILES#' "$GENIMAGE_TEMPLATE"; then + log "Discovering Raspberry Pi boot files..." + BOOT_FILES=$(discover_rpi_boot_files "$BINARIES_DIR") + # Create temp file with interpreted escape sequences + bootfiles_tmp="${BUILD_DIR}/bootfiles.tmp" + printf '%b' "$BOOT_FILES" > "$bootfiles_tmp" + # Use sed to insert content and delete placeholder + sed -e "/#BOOT_FILES#/r $bootfiles_tmp" -e "/#BOOT_FILES#/d" "$GENIMAGE_TEMPLATE" > "${GENIMAGE_CFG}.tmp" + rm -f "$bootfiles_tmp" + GENIMAGE_TEMPLATE="${GENIMAGE_CFG}.tmp" +fi + +# Epxand template variables +sed "s|#VERSION#|${RELEASE}|" "$GENIMAGE_TEMPLATE" | \ +sed "s|#INFIX_ID#|${INFIX_ID}|" | \ +sed "s|#TARGET#|sd|" > "$GENIMAGE_CFG" + +# Clean up temp file if created +rm -f "${GENIMAGE_CFG}.tmp" + +# Find and set up for calling genimage/genimage.sh +if [ -z "$BR2_CONFIG" ]; then + BR2_CONFIG="/dev/null" + if [ -f "${BUILD_DIR}/../.config" ]; then + BR2_CONFIG="$(realpath "${BUILD_DIR}/../.config")" + fi + export BR2_CONFIG + + if [ -f "$BR2_EXTERNAL_INFIX_PATH/../buildroot/support/scripts/genimage.sh" ]; then + GENIMAGE_WRAPPER="$(realpath "$BR2_EXTERNAL_INFIX_PATH/../buildroot/support/scripts/genimage.sh")" + fi +else + GENIMAGE_WRAPPER="support/scripts/genimage.sh" +fi + +if [ -z "$OVERRIDE" ] && command -v "$GENIMAGE_WRAPPER" >/dev/null 2>&1; then + log "Creating SD card image using Buildroot $(basename "$GENIMAGE_WRAPPER") ..." + "$GENIMAGE_WRAPPER" -c "$GENIMAGE_CFG" +else + log "Creating SD card image ..." + run_genimage "$GENIMAGE_CFG" +fi + +log "SD card image created successfully:" +for img in "${BINARIES_DIR}"/*-sdcard.img*; do + if [ -f "$img" ]; then + if [ -n "$STANDALONE" ]; then + # Show relative path in standalone mode + rel_path=$(realpath --relative-to="$PWD" "$img" 2>/dev/null || echo "$img") + echo " $rel_path" + else + echo " $(basename "$img")" + fi + fi +done