@@ -220,7 +220,7 @@ get_partition_offset() {
220220 local img=" $1 " part=" $2 "
221221 local sector
222222 # Parse sfdisk dump for partition start sector
223- sector=$( sfdisk -d " $img " 2> /dev/null | grep " ^${img}${part} " | sed ' s/.*start=\s *\([0-9]*\).*/\1/' )
223+ sector=$( sfdisk -d " $img " 2> /dev/null | grep " ^${img}${part} " | sed ' s/.*start=[[:space:]] *\([0-9]*\).*/\1/' )
224224 if [ -z " $sector " ]; then
225225 # Fallback: parse fdisk output
226226 sector=$( fdisk -l " $img " 2> /dev/null | grep " ^${img}${part} " | awk ' {print $2}' )
@@ -245,6 +245,10 @@ write_to_partition() {
245245 return 1
246246 fi
247247
248+ local file_size=$( stat -c%s " $file " )
249+ local part_size=$( sfdisk -d " $img " 2> /dev/null | grep " ^${img}${part} " | sed ' s/.*size=[[:space:]]*\([0-9]*\).*/\1/' )
250+ [ -n " $part_size " ] && [ " $file_size " -gt $(( part_size * 512 )) ] && { log_error " File $file (${file_size} B) exceeds partition $part size ($(( part_size * 512 )) B)" ; return 1; }
251+
248252 log_info " Writing $file to partition $part (offset: ${offset_bytes} bytes, sector: ${offset_blocks} )"
249253 dd if=" $file " of=" $img " bs=512 seek=" $offset_blocks " conv=notrunc status=progress 2> /dev/null || {
250254 log_error " Failed to write $file to partition $part "
@@ -392,7 +396,7 @@ Environment Variables:
392396 VITIS_PATH Xilinx Vitis installation path (default: /opt/Xilinx/Vitis/2024.2)
393397 LINUX_IMAGES_DIR Path to PetaLinux images directory (for --linux, --linux-sdcard, --linux-uboot)
394398 SDCARD_IMG SD card image output path (default: sdcard.img)
395- SDCARD_SIZE_MB SD card image size in MB (default: 512 )
399+ SDCARD_SIZE_MB SD card image size in MB (default: 1024 )
396400
397401Examples:
398402 $0 --boot-sdcard --skipuart # Reset to SD boot without UART capture
@@ -551,20 +555,14 @@ case "${1:-}" in
551555 write_to_partition " $SDCARD_IMG " 2 fitImage_v1_signed.bin || exit 1
552556 write_to_partition " $SDCARD_IMG " 3 fitImage_v2_signed.bin || exit 1
553557
554- # Write rootfs to partition 4 if available
555- ROOTFS_IMG=" "
558+ # Write rootfs filesystem image to partition 4 if available
556559 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
562560 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)"
561+ write_to_partition " $SDCARD_IMG " 4 " ${LINUX_IMAGES_DIR} /rootfs.ext4 " || exit 1
562+ log_ok " rootfs written ($( stat -c%s " ${LINUX_IMAGES_DIR} /rootfs.ext4 " ) bytes)"
565563 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"
564+ log_info " No rootfs.ext4 found in $LINUX_IMAGES_DIR "
565+ log_info " You can write a rootfs filesystem image to partition 4 manually"
568566 fi
569567
570568 log_ok " SD card image created: $SDCARD_IMG "
@@ -591,10 +589,7 @@ case "${1:-}" in
591589 log_info " Partition 3 (OFP_B): Signed Linux FIT image v2 (update)"
592590 log_info " Partition 4 (rootfs): Linux root filesystem"
593591 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:"
592+ log_info " Provision SD card manually:"
598593 log_info " sudo dd if=$SDCARD_IMG of=/dev/sdX bs=4M status=progress conv=fsync"
599594 log_info " sync"
600595 log_info " sudo mkfs.vfat -F 32 -n BOOT /dev/sdX1"
@@ -621,7 +616,7 @@ case "${1:-}" in
621616 ./tools/keytools/sign $SIGN_OPTIONS test-app/image.bin " $PRIVATE_KEY " 2 || { log_error " Signing v2 failed" ; exit 1; }
622617 log_ok " Signed test applications: image_v1_signed.bin, image_v2_signed.bin"
623618
624- # Create SD card image with GPT partitions
619+ # Create SD card image with MBR (DOS) partition table
625620 create_sdcard_image " $SDCARD_IMG " " $SDCARD_SIZE_MB " || exit 1
626621
627622 # Write signed images to partitions (OFP_A=2, OFP_B=3)
0 commit comments