Skip to content

Commit 363fdaa

Browse files
committed
Peer review fixes
1 parent 3eae2f3 commit 363fdaa

File tree

7 files changed

+40
-39
lines changed

7 files changed

+40
-39
lines changed

config/examples/versal_vmk180_sdcard.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ WOLFBOOT_PARTITION_SIZE=0x4000000
9696
WOLFBOOT_SECTOR_SIZE=0x1000
9797

9898
# ============================================================================
99-
# UART Configuration - UART1 for APU console (matches VMK180 board)
99+
# UART Configuration - UART0 for APU console (matches VMK180 board)
100100
# ============================================================================
101101
CFLAGS_EXTRA+=-DDEBUG_UART_NUM=0
102102

docs/Targets.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,10 +2061,10 @@ cp ${PREBUILT_DIR}/bl31.elf .
20612061
cp ${PREBUILT_DIR}/system-default.dtb .
20622062

20632063
source ${VITIS_PATH}/settings64.sh
2064-
bootgen -arch versal -image ./tools/scripts/vmk180/boot_wolfboot.bif -w -o BOOT.BIN
2064+
bootgen -arch versal -image ./tools/scripts/versal_boot.bif -w -o BOOT.BIN
20652065
```
20662066

2067-
The BIF file (`boot_wolfboot.bif`) references files using relative paths in the same directory.
2067+
The BIF file (`versal_boot.bif`) references files using relative paths in the same directory.
20682068

20692069
**Flash QSPI**
20702070

hal/versal.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,8 +1539,11 @@ int ext_flash_erase(uintptr_t address, int len)
15391539
#if defined(DISK_SDCARD) || defined(DISK_EMMC)
15401540
#include "sdhci.h"
15411541

1542-
/* Use SD1 for external SD card slot on VMK180 */
1543-
#define VERSAL_SDHCI_BASE VERSAL_SD1_BASE /* 0xF1050000 */
1542+
/* SD controller base address selection:
1543+
* SD0 (VERSAL_SD0_BASE = 0xF1040000) - internal, typically eMMC
1544+
* SD1 (VERSAL_SD1_BASE = 0xF1050000) - external SD card slot on VMK180
1545+
* Note: VMK180 board does not have eMMC hardware, only SD1 is used. */
1546+
#define VERSAL_SDHCI_BASE VERSAL_SD1_BASE
15441547

15451548
/* ============================================================================
15461549
* Register Translation: Cadence SD4HC -> Standard SDHCI (Arasan)

src/disk.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,6 @@
4747
*/
4848
static struct disk_drive Drives[MAX_DISKS] = {0};
4949

50-
/**
51-
* @brief Opens a disk drive and initializes its partitions.
52-
*
53-
* This function opens a disk drive with the specified drive number, reads its
54-
* MBR (Master Boot Record) to identify GPT partitions, and initializes the
55-
* disk_drive structure for further operations.
56-
*
57-
* @param[in] drv The drive number to open (0 to `MAX_DISKS - 1`).
58-
*
59-
* @return The number of partitions found and initialized on success, or -1 if
60-
* the drive cannot be opened or no valid GPT partition table is found.
61-
*/
6250
/**
6351
* @brief Parse MBR partition table entries.
6452
*
@@ -109,6 +97,18 @@ static int disk_open_mbr(struct disk_drive *drive, const uint8_t *mbr_sector)
10997
return drive->n_parts;
11098
}
11199

100+
/**
101+
* @brief Opens a disk drive and initializes its partitions.
102+
*
103+
* This function opens a disk drive with the specified drive number, reads its
104+
* MBR (Master Boot Record) to identify GPT partitions, and initializes the
105+
* disk_drive structure for further operations.
106+
*
107+
* @param[in] drv The drive number to open (0 to `MAX_DISKS - 1`).
108+
*
109+
* @return The number of partitions found and initialized on success, or -1 if
110+
* the drive cannot be opened or no valid GPT partition table is found.
111+
*/
112112
int disk_open(int drv)
113113
{
114114
int r;

src/sdhci.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,10 +1183,10 @@ static int sdhci_transfer(int dir, uint32_t cmd_index, uint32_t block_addr,
11831183
/* SDMA mode with Host Version 4 enable.
11841184
* HV4E is required for SDMA to use the 64-bit address registers
11851185
* (SRS22/SRS23) instead of the legacy 32-bit register (SRS00).
1186-
* A64S is cleared to use 32-bit DMA addressing. */
1186+
* A64 is cleared in SRS15 to use 32-bit DMA addressing. */
11871187
sdhci_reg_or(SDHCI_SRS10, SDHCI_SRS10_DMA_SDMA);
11881188
sdhci_reg_or(SDHCI_SRS15, SDHCI_SRS15_HV4E);
1189-
sdhci_reg_and(SDHCI_SRS16, ~SDHCI_SRS16_A64S);
1189+
sdhci_reg_and(SDHCI_SRS15, ~SDHCI_SRS15_A64);
11901190
/* Set SDMA address */
11911191
SDHCI_REG_SET(SDHCI_SRS22, (uint32_t)(uintptr_t)buf);
11921192
SDHCI_REG_SET(SDHCI_SRS23, (uint32_t)(((uint64_t)(uintptr_t)buf) >> 32));

src/update_disk.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,13 @@ void RAMFUNCTION wolfBoot_start(void)
382382
BENCHMARK_START();
383383
load_off = 0;
384384
do {
385+
uint32_t chunk = os_image.fw_size - load_off;
386+
if (chunk > DISK_BLOCK_SIZE)
387+
chunk = DISK_BLOCK_SIZE;
385388
ret = disk_part_read(BOOT_DISK, cur_part,
386-
IMAGE_HEADER_SIZE + load_off, DISK_BLOCK_SIZE,
389+
IMAGE_HEADER_SIZE + load_off, chunk,
387390
((uint8_t *)load_address) + load_off);
388-
if (ret < 0)
391+
if (ret <= 0)
389392
break;
390393
load_off += ret;
391394
} while (load_off < os_image.fw_size);

tools/scripts/versal_test.sh

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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
397401
Examples:
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

Comments
 (0)