1212usage ()
1313{
1414 cat << EOF
15- Create SD card image from build artifacts for any supported board.
15+ Create SD card/eMMC image from build artifacts for any supported board.
1616
1717Usage:
1818 $0 [OPTIONS] <board-name>
1919
2020Options:
2121 -b boot-dir Path to bootloader build directory (default: O= or output/)
22+ -B Boot-only image (no rootfs, for bootloader testing)
2223 -d Download bootloader files from latest-boot release
2324 -f Force re-download of bootloader even if cached
2425 -h This help text
@@ -56,6 +57,9 @@ Examples:
5657 # Create eMMC image instead of SD card:
5758 $0 -t emmc bananapi-bpi-r3
5859
60+ # Create boot-only image for bootloader testing:
61+ $0 -B -b build-boot microchip-sama7g54-ek
62+
5963EOF
6064}
6165
@@ -293,12 +297,41 @@ discover_rpi_boot_files()
293297 echo " $files "
294298}
295299
296- while getopts " hldfob:r:t:" opt; do
300+ # Filter genimage.cfg.in for boot-only image
301+ # Removes rootfs-related blocks: image cfg.ext4, image var.ext4,
302+ # and partitions: aux, primary, secondary, cfg, var
303+ filter_bootonly_genimage ()
304+ {
305+ awk '
306+ BEGIN { skip=0; depth=0 }
307+ /^image cfg\.ext4/ || /^image var\.ext4/ {
308+ skip=1; depth=1; next
309+ }
310+ /^[[:space:]]*partition (aux|primary|secondary|cfg|var)[[:space:]]*\{/ {
311+ skip=1; depth=1; next
312+ }
313+ skip==1 {
314+ # Count braces on this line to track nesting depth
315+ n = gsub(/{/, "{")
316+ m = gsub(/}/, "}")
317+ depth = depth + n - m
318+ if (depth <= 0) { skip=0; depth=0 }
319+ next
320+ }
321+ { print }
322+ '
323+ }
324+
325+ while getopts " hldfoBb:r:t:" opt; do
297326 case $opt in
298327 b)
299328 BOOT_DIR=" $OPTARG "
300329 STANDALONE=1
301330 ;;
331+ B)
332+ BOOT_ONLY=1
333+ STANDALONE=1
334+ ;;
302335 d)
303336 DOWNLOAD_BOOT=1
304337 STANDALONE=1
@@ -360,6 +393,11 @@ if [ -n "$STANDALONE" ]; then
360393 default_dir=$( find_build_dir) || die " Could not find build directory. Set O= or use -b/-r option"
361394 : " ${BOOT_DIR:= $default_dir } "
362395 : " ${ROOT_DIR:= $default_dir } "
396+ elif [ -n " $BOOT_ONLY " ]; then
397+ # Boot-only mode: only need bootloader directory
398+ if [ -z " $BOOT_DIR " ]; then
399+ BOOT_DIR=$( find_build_dir) || die " Could not find boot directory. Use -b option"
400+ fi
363401 else
364402 if [ -z " $BOOT_DIR " ]; then
365403 BOOT_DIR=$( find_build_dir) || die " Could not find boot directory. Use -b option"
@@ -379,51 +417,54 @@ if [ -n "$STANDALONE" ]; then
379417
380418 # Add host tools to PATH (for genimage, bmaptool, etc.)
381419 for dir in " $BOOT_DIR " " $ROOT_DIR " ; do
420+ [ -n " $dir " ] || continue
382421 if [ -d " $dir /host/bin" ]; then
383422 export PATH=" $dir /host/bin:$PATH "
384423 break
385424 fi
386425 done
387426
388- # Copy rootfs and partition images to BINARIES_DIR (skip if same directory )
427+ # Copy rootfs and partition images to BINARIES_DIR (skip in boot-only mode )
389428 mkdir -p " $BINARIES_DIR "
390429
391- # Normalize paths for comparison
392- boot_images=$( cd " $BOOT_DIR " && pwd) /images
393- root_images=" "
394-
395- if [ -f " $ROOT_DIR " ]; then
396- # Direct path to rootfs.squashfs file
397- log " Copying rootfs from $ROOT_DIR to $BINARIES_DIR /rootfs.squashfs"
398- cp " $ROOT_DIR " " $BINARIES_DIR /rootfs.squashfs"
399- elif [ -f " $ROOT_DIR /images/rootfs.squashfs" ]; then
400- root_images=$( cd " $ROOT_DIR " && pwd) /images
401- # Only copy if different directories
402- if [ " $boot_images " != " $root_images " ]; then
403- # Build directory with images/ - copy rootfs and partition images
404- log " Copying artifacts from $ROOT_DIR /images/ to $BINARIES_DIR /"
405- cp " $ROOT_DIR /images/rootfs.squashfs" " $BINARIES_DIR /"
430+ if [ -z " $BOOT_ONLY " ]; then
431+ # Normalize paths for comparison
432+ boot_images=$( cd " $BOOT_DIR " && pwd) /images
433+ root_images=" "
434+
435+ if [ -f " $ROOT_DIR " ]; then
436+ # Direct path to rootfs.squashfs file
437+ log " Copying rootfs from $ROOT_DIR to $BINARIES_DIR /rootfs.squashfs"
438+ cp " $ROOT_DIR " " $BINARIES_DIR /rootfs.squashfs"
439+ elif [ -f " $ROOT_DIR /images/rootfs.squashfs" ]; then
440+ root_images=$( cd " $ROOT_DIR " && pwd) /images
441+ # Only copy if different directories
442+ if [ " $boot_images " != " $root_images " ]; then
443+ # Build directory with images/ - copy rootfs and partition images
444+ log " Copying artifacts from $ROOT_DIR /images/ to $BINARIES_DIR /"
445+ cp " $ROOT_DIR /images/rootfs.squashfs" " $BINARIES_DIR /"
446+ # Copy partition images if they exist
447+ for img in aux.ext4 cfg.ext4 var.ext4; do
448+ if [ -f " $ROOT_DIR /images/$img " ]; then
449+ cp " $ROOT_DIR /images/$img " " $BINARIES_DIR /"
450+ fi
451+ done
452+ else
453+ log " Rootfs already in place at $BINARIES_DIR /"
454+ fi
455+ elif [ -f " $ROOT_DIR /rootfs.squashfs" ]; then
456+ # Directory directly containing rootfs.squashfs
457+ log " Copying rootfs from $ROOT_DIR /rootfs.squashfs"
458+ cp " $ROOT_DIR /rootfs.squashfs" " $BINARIES_DIR /"
406459 # Copy partition images if they exist
407460 for img in aux.ext4 cfg.ext4 var.ext4; do
408- if [ -f " $ROOT_DIR /images/ $img " ]; then
409- cp " $ROOT_DIR /images/ $img " " $BINARIES_DIR /"
461+ if [ -f " $ROOT_DIR /$img " ]; then
462+ cp " $ROOT_DIR /$img " " $BINARIES_DIR /"
410463 fi
411464 done
412465 else
413- log " Rootfs already in place at $BINARIES_DIR / "
466+ die " Could not find rootfs.squashfs in $ROOT_DIR "
414467 fi
415- elif [ -f " $ROOT_DIR /rootfs.squashfs" ]; then
416- # Directory directly containing rootfs.squashfs
417- log " Copying rootfs from $ROOT_DIR /rootfs.squashfs"
418- cp " $ROOT_DIR /rootfs.squashfs" " $BINARIES_DIR /"
419- # Copy partition images if they exist
420- for img in aux.ext4 cfg.ext4 var.ext4; do
421- if [ -f " $ROOT_DIR /$img " ]; then
422- cp " $ROOT_DIR /$img " " $BINARIES_DIR /"
423- fi
424- done
425- else
426- die " Could not find rootfs.squashfs in $ROOT_DIR "
427468 fi
428469else
429470 # Export for Buildroot genimage.sh wrapper
@@ -450,29 +491,31 @@ if [ -n "$DOWNLOAD_BOOT" ]; then
450491 # Now use the temporary directory for composition
451492 BINARIES_DIR=" $SDCARD_TEMP_DIR "
452493
453- log " Linking rootfs files to $BINARIES_DIR ..."
454- # Link rootfs and partition images to temp directory
455- if [ -f " $ROOT_DIR " ]; then
456- # Direct path to rootfs.squashfs file
457- ln -sf " $( realpath " $ROOT_DIR " ) " " $BINARIES_DIR /rootfs.squashfs"
458- elif [ -f " $ROOT_DIR /images/rootfs.squashfs" ]; then
459- ln -sf " $( realpath " $ROOT_DIR /images/rootfs.squashfs" ) " " $BINARIES_DIR /rootfs.squashfs"
460- # Link partition images if they exist
461- for img in aux.ext4 cfg.ext4 var.ext4; do
462- if [ -f " $ROOT_DIR /images/$img " ]; then
463- ln -sf " $( realpath " $ROOT_DIR /images/$img " ) " " $BINARIES_DIR /$img "
464- fi
465- done
466- elif [ -f " $ROOT_DIR /rootfs.squashfs" ]; then
467- ln -sf " $( realpath " $ROOT_DIR /rootfs.squashfs" ) " " $BINARIES_DIR /rootfs.squashfs"
468- # Link partition images if they exist
469- for img in aux.ext4 cfg.ext4 var.ext4; do
470- if [ -f " $ROOT_DIR /$img " ]; then
471- ln -sf " $( realpath " $ROOT_DIR /$img " ) " " $BINARIES_DIR /$img "
472- fi
473- done
474- else
475- die " Could not find rootfs.squashfs in $ROOT_DIR "
494+ # Link rootfs and partition images to temp directory (skip in boot-only mode)
495+ if [ -z " $BOOT_ONLY " ]; then
496+ log " Linking rootfs files to $BINARIES_DIR ..."
497+ if [ -f " $ROOT_DIR " ]; then
498+ # Direct path to rootfs.squashfs file
499+ ln -sf " $( realpath " $ROOT_DIR " ) " " $BINARIES_DIR /rootfs.squashfs"
500+ elif [ -f " $ROOT_DIR /images/rootfs.squashfs" ]; then
501+ ln -sf " $( realpath " $ROOT_DIR /images/rootfs.squashfs" ) " " $BINARIES_DIR /rootfs.squashfs"
502+ # Link partition images if they exist
503+ for img in aux.ext4 cfg.ext4 var.ext4; do
504+ if [ -f " $ROOT_DIR /images/$img " ]; then
505+ ln -sf " $( realpath " $ROOT_DIR /images/$img " ) " " $BINARIES_DIR /$img "
506+ fi
507+ done
508+ elif [ -f " $ROOT_DIR /rootfs.squashfs" ]; then
509+ ln -sf " $( realpath " $ROOT_DIR /rootfs.squashfs" ) " " $BINARIES_DIR /rootfs.squashfs"
510+ # Link partition images if they exist
511+ for img in aux.ext4 cfg.ext4 var.ext4; do
512+ if [ -f " $ROOT_DIR /$img " ]; then
513+ ln -sf " $( realpath " $ROOT_DIR /$img " ) " " $BINARIES_DIR /$img "
514+ fi
515+ done
516+ else
517+ die " Could not find rootfs.squashfs in $ROOT_DIR "
518+ fi
476519 fi
477520fi
478521
@@ -496,13 +539,28 @@ if { [ "$BOARD" = "raspberrypi-rpi2" ] || [ "$BOARD" = "raspberrypi-rpi64" ]; }
496539 GENIMAGE_TEMPLATE=" ${GENIMAGE_CFG} .tmp"
497540fi
498541
499- # Epxand template variables
500- sed " s|#VERSION#|${RELEASE} |" " $GENIMAGE_TEMPLATE " | \
501- sed " s|#INFIX_ID#|${INFIX_ID} |" | \
502- sed " s|#TARGET#|${TARGET} |" > " $GENIMAGE_CFG "
542+ # Filter for boot-only mode if requested
543+ if [ -n " $BOOT_ONLY " ]; then
544+ log " Filtering genimage config for boot-only image..."
545+ filter_bootonly_genimage < " $GENIMAGE_TEMPLATE " > " ${GENIMAGE_CFG} .filtered"
546+ GENIMAGE_TEMPLATE=" ${GENIMAGE_CFG} .filtered"
547+ fi
548+
549+ # Expand template variables
550+ # For boot-only mode, append "-boot" to the target name in the image filename
551+ if [ -n " $BOOT_ONLY " ]; then
552+ sed " s|#VERSION#|${RELEASE} |" " $GENIMAGE_TEMPLATE " | \
553+ sed " s|#INFIX_ID#|${INFIX_ID} |" | \
554+ sed " s|#TARGET#|${TARGET} |" | \
555+ sed " s|-${TARGET} \.img|-${TARGET} -boot.img|" > " $GENIMAGE_CFG "
556+ else
557+ sed " s|#VERSION#|${RELEASE} |" " $GENIMAGE_TEMPLATE " | \
558+ sed " s|#INFIX_ID#|${INFIX_ID} |" | \
559+ sed " s|#TARGET#|${TARGET} |" > " $GENIMAGE_CFG "
560+ fi
503561
504- # Clean up temp file if created
505- rm -f " ${GENIMAGE_CFG} .tmp"
562+ # Clean up temp files if created
563+ # rm -f "${GENIMAGE_CFG}.tmp" "${GENIMAGE_CFG}.filtered "
506564
507565# Find and set up for calling genimage/genimage.sh
508566if [ -z " $BR2_CONFIG " ]; then
@@ -546,8 +604,12 @@ if [ -n "$DOWNLOAD_BOOT" ]; then
546604 BINARIES_DIR=" $ORIGINAL_BINARIES_DIR "
547605fi
548606
549- log " $TARGET image created successfully:"
550- for img in " ${BINARIES_DIR} " /* -sdcard.img* " ${BINARIES_DIR} " /* -emmc.img* ; do
607+ if [ -n " $BOOT_ONLY " ]; then
608+ log " $TARGET boot-only image created successfully:"
609+ else
610+ log " $TARGET image created successfully:"
611+ fi
612+ for img in " ${BINARIES_DIR} " /* -sdcard* .img* " ${BINARIES_DIR} " /* -emmc* .img* ; do
551613 if [ -f " $img " ]; then
552614 if [ -n " $STANDALONE " ]; then
553615 # Show relative path in standalone mode
0 commit comments