Skip to content

Commit aaba142

Browse files
committed
Tested PetaLinux boot from SDCard
1 parent 08b36ac commit aaba142

File tree

3 files changed

+102
-4
lines changed

3 files changed

+102
-4
lines changed

config/examples/versal_vmk180_sdcard.config

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ CFLAGS_EXTRA+=-DDISK_BLOCK_SIZE=0x80000
7777
# boundary crossings via SRS22/SRS23 writes (Cadence-specific behavior).
7878
CFLAGS_EXTRA+=-DSDHCI_SDMA_DISABLED
7979

80+
# Linux rootfs is on partition 4 (default is /dev/mmcblk0p2 for QSPI boot)
81+
CFLAGS_EXTRA+=-DLINUX_BOOTARGS_ROOT=\"/dev/mmcblk0p4\"
82+
8083
# ============================================================================
8184
# Boot Memory Layout
8285
# ============================================================================
@@ -87,7 +90,8 @@ WOLFBOOT_ORIGIN=0x8000000
8790
WOLFBOOT_LOAD_ADDRESS?=0x10000000
8891

8992
# DTS (Device Tree) load address
90-
WOLFBOOT_LOAD_DTS_ADDRESS?=0x8A000000
93+
# Must be in DDR low (0x0-0x7FFFFFFF) - matches QSPI config and FIT ITS load address
94+
WOLFBOOT_LOAD_DTS_ADDRESS?=0x1000
9195

9296
# ============================================================================
9397
# Required for test-app (even with WOLFBOOT_NO_PARTITIONS=1)

src/sdhci.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ void sdhci_irq_handler(void)
116116

117117
/* Clear DMA interrupt status before restarting */
118118
SDHCI_REG_SET(SDHCI_SRS12, SDHCI_SRS12_DMAINT);
119+
#ifdef __riscv
120+
asm volatile("fence rw, rw" ::: "memory");
121+
#else
119122
asm volatile("dsb sy" ::: "memory");
123+
#endif
120124

121125
/* Write SDMA address to resume transfer.
122126
* Per SDHCI v4 spec: write high 32 bits first, then low 32 bits.

tools/scripts/versal_test.sh

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
396397
Examples:
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
400402
EOF
401403
}
402404

403405
# Check for --skipuart flag or modes that don't need UART before starting UART capture
404406
SKIP_UART=false
405407
for arg in "$@"; do
406408
case "$arg" in
407-
--skipuart|--sdcard) SKIP_UART=true ;;
409+
--skipuart|--sdcard|--linux-sdcard) SKIP_UART=true ;;
408410
esac
409411
done
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

Comments
 (0)