@@ -375,7 +375,8 @@ Options:
375375 (none) Full build, flash, and boot wolfBoot
376376 --test-app Full build + flash test app to boot partition
377377 --test-update Full build + flash test app v2 to update partition
378- --linux Build wolfBoot + signed Linux FIT image and boot
378+ --linux Build wolfBoot + signed Linux FIT image and boot (QSPI)
379+ --linux-sdcard Build wolfBoot + signed Linux FIT image for SD card boot
379380 --linux-uboot Build BOOT.BIN with U-Boot and flash Linux FIT image
380381 --sdcard Build wolfBoot with SD card config and create SD card image
381382 --boot-sdcard Test SD card boot mode only (no build/flash)
@@ -389,22 +390,23 @@ Environment Variables:
389390 BOARD_IP Board IP address (default: 10.0.4.90)
390391 TFTP_DIR TFTP directory path (default: /srv/tftp)
391392 VITIS_PATH Xilinx Vitis installation path (default: /opt/Xilinx/Vitis/2024.2)
392- LINUX_IMAGES_DIR Path to PetaLinux images directory (for --linux and --linux-uboot)
393+ LINUX_IMAGES_DIR Path to PetaLinux images directory (for --linux, --linux-sdcard, --linux-uboot)
393394 SDCARD_IMG SD card image output path (default: sdcard.img)
394395 SDCARD_SIZE_MB SD card image size in MB (default: 512)
395396
396397Examples:
397398 $0 --boot-sdcard --skipuart # Reset to SD boot without UART capture
398399 $0 --boot-qspi --skipuart # Reset to QSPI boot without UART capture
399400 $0 --sdcard # Build with SD card config and create SD card image
401+ LINUX_IMAGES_DIR=/path/to/images/linux $0 --linux-sdcard # PetaLinux SD card boot
400402EOF
401403}
402404
403405# Check for --skipuart flag or modes that don't need UART before starting UART capture
404406SKIP_UART= false
405407for arg in " $@ " ; do
406408 case " $arg " in
407- --skipuart|--sdcard) SKIP_UART=true ;;
409+ --skipuart|--sdcard|--linux-sdcard ) SKIP_UART=true ;;
408410 esac
409411done
410412
@@ -510,6 +512,94 @@ case "${1:-}" in
510512 log_ok " Signed FIT size: $( stat -c%s fitImage_v1_signed.bin) bytes"
511513
512514 flash_and_boot " BOOT.BIN:0x0 fitImage_v1_signed.bin:0x800000" 90 " wolfBoot + Linux boot"
515+ exit 0
516+ ;;
517+ --linux-sdcard)
518+ log_info " === Linux SD Card Boot Mode ==="
519+ check_linux_images " plm.elf psmfw.elf bl31.elf Image system-default.dtb" " --linux-sdcard"
520+ command -v mkimage & > /dev/null || { log_error " mkimage not found - install with: sudo apt install u-boot-tools" ; exit 1; }
521+
522+ log_info " Copying Linux boot files..."
523+ for f in plm.elf psmfw.elf bl31.elf Image system-default.dtb; do cp " ${LINUX_IMAGES_DIR} /${f} " . ; done
524+ copy_pdi
525+
526+ # Build wolfBoot with SD card configuration
527+ log_info " Building wolfBoot with SD card config..."
528+ cp config/examples/versal_vmk180_sdcard.config .config
529+ make clean && make || { log_error " Failed to build wolfBoot" ; exit 1; }
530+ [ ! -f " wolfboot.elf" ] && { log_error " wolfboot.elf not found" ; exit 1; }
531+ load_config .config
532+
533+ # Create FIT image from Linux kernel + DTB
534+ log_info " Creating FIT image..."
535+ mkimage -f ./hal/versal.its fitImage || { log_error " mkimage failed" ; exit 1; }
536+ log_ok " FIT image created: fitImage ($( stat -c%s fitImage) bytes)"
537+
538+ # Sign FIT image
539+ log_info " Signing FIT image..."
540+ export IMAGE_HEADER_SIZE IMAGE_SIGNATURE_SIZE
541+ PRIVATE_KEY=" ${PRIVATE_KEY:- wolfboot_signing_private_key.der} "
542+ ./tools/keytools/sign $SIGN_OPTIONS fitImage " $PRIVATE_KEY " 1 || { log_error " Signing v1 failed" ; exit 1; }
543+ ./tools/keytools/sign $SIGN_OPTIONS fitImage " $PRIVATE_KEY " 2 || { log_error " Signing v2 failed" ; exit 1; }
544+ log_ok " Signed FIT images: fitImage_v1_signed.bin, fitImage_v2_signed.bin"
545+
546+ # Create SD card image with MBR partitions
547+ create_sdcard_image " $SDCARD_IMG " " $SDCARD_SIZE_MB " || exit 1
548+
549+ # Write signed FIT images to partitions (OFP_A=2, OFP_B=3)
550+ log_info " Writing signed FIT images to SD card partitions..."
551+ write_to_partition " $SDCARD_IMG " 2 fitImage_v1_signed.bin || exit 1
552+ write_to_partition " $SDCARD_IMG " 3 fitImage_v2_signed.bin || exit 1
553+
554+ # Write rootfs to partition 4 if available
555+ ROOTFS_IMG=" "
556+ if [ -f " ${LINUX_IMAGES_DIR} /rootfs.ext4" ]; then
557+ ROOTFS_IMG=" ${LINUX_IMAGES_DIR} /rootfs.ext4"
558+ elif [ -f " ${LINUX_IMAGES_DIR} /rootfs.cpio.gz" ]; then
559+ ROOTFS_IMG=" ${LINUX_IMAGES_DIR} /rootfs.cpio.gz"
560+ fi
561+ if [ -n " $ROOTFS_IMG " ]; then
562+ log_info " Writing rootfs to partition 4..."
563+ write_to_partition " $SDCARD_IMG " 4 " $ROOTFS_IMG " || exit 1
564+ log_ok " rootfs written ($( stat -c%s " $ROOTFS_IMG " ) bytes)"
565+ else
566+ log_info " No rootfs found in $LINUX_IMAGES_DIR (looked for rootfs.ext4, rootfs.cpio.gz)"
567+ log_info " You can write rootfs to partition 4 manually"
568+ fi
569+
570+ log_ok " SD card image created: $SDCARD_IMG "
571+
572+ # Generate BOOT.BIN
573+ log_info " "
574+ log_info " Generating BOOT.BIN with wolfBoot..."
575+ source " ${VITIS_PATH} /settings64.sh" 2> /dev/null || true
576+ if command -v bootgen & > /dev/null; then
577+ rm -f BOOT.BIN
578+ bootgen -arch versal -image ./tools/scripts/versal_boot.bif -w -o BOOT.BIN || log_error " bootgen failed"
579+ [ -f BOOT.BIN ] && {
580+ log_ok " BOOT.BIN size: $( stat -c%s BOOT.BIN) bytes"
581+ cp BOOT.BIN " ${TFTP_DIR} /" 2> /dev/null && log_ok " BOOT.BIN copied to TFTP"
582+ }
583+ else
584+ log_error " bootgen not found - source Vitis settings or set VITIS_PATH"
585+ fi
586+
587+ log_info " "
588+ log_info " SD Card Partition Layout:"
589+ log_info " Partition 1 (boot): FAT32 - BOOT.BIN (PLM + PSM + BL31 + wolfBoot)"
590+ log_info " Partition 2 (OFP_A): Signed Linux FIT image v1 (primary)"
591+ log_info " Partition 3 (OFP_B): Signed Linux FIT image v2 (update)"
592+ log_info " Partition 4 (rootfs): Linux root filesystem"
593+ log_info " "
594+ log_info " Provision SD card:"
595+ log_info " sudo ./tools/scripts/versal_sdcard_provision.sh /dev/sdX"
596+ log_info " "
597+ log_info " Or manually:"
598+ log_info " sudo dd if=$SDCARD_IMG of=/dev/sdX bs=4M status=progress conv=fsync"
599+ log_info " sync"
600+ log_info " sudo mkfs.vfat -F 32 -n BOOT /dev/sdX1"
601+ log_info " sudo mount /dev/sdX1 /mnt && sudo cp BOOT.BIN /mnt/ && sudo umount /mnt"
602+
513603 exit 0
514604 ;;
515605 --sdcard)
0 commit comments