Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,16 @@ S := $E $E
CFLAGS += -D SEMU_BOOT_TARGET_TIME=10

SMP ?= 1

# Track SMP value changes to force DTB regeneration
.smp_stamp: FORCE
@if [ ! -f .smp_stamp ] || [ "$$(cat .smp_stamp 2>/dev/null)" != "$(SMP)" ]; then \
echo "$(SMP)" > .smp_stamp; \
rm -f riscv-harts.dtsi minimal.dtb; \
fi

.PHONY: riscv-harts.dtsi
riscv-harts.dtsi:
riscv-harts.dtsi: .smp_stamp
$(Q)python3 scripts/gen-hart-dts.py $@ $(SMP) $(CLOCK_FREQ)

minimal.dtb: minimal.dts riscv-harts.dtsi
Expand All @@ -216,6 +224,9 @@ minimal.dtb: minimal.dts riscv-harts.dtsi
$(subst ^,$S,$(filter -D^SEMU_FEATURE_%, $(subst -D$(S)SEMU_FEATURE,-D^SEMU_FEATURE,$(CFLAGS)))) $< \
| $(DTC) - > $@

.PHONY: FORCE
FORCE:

# Rules for downloading prebuilt Linux kernel image
include mk/external.mk

Expand Down Expand Up @@ -245,6 +256,7 @@ clean:
distclean: clean
$(Q)$(RM) riscv-harts.dtsi
$(Q)$(RM) minimal.dtb
$(Q)$(RM) .smp_stamp
$(Q)$(RM) Image rootfs.cpio
$(Q)$(RM) ext4.img

Expand Down
43 changes: 43 additions & 0 deletions scripts/verify-dtb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
# Verify that DTB CPU count matches expected count

DTB_FILE="${1}"
EXPECTED_COUNT="${2}"

if [ -z "$DTB_FILE" ] || [ -z "$EXPECTED_COUNT" ]; then
echo "Usage: $0 <dtb_file> <expected_cpu_count>"
exit 1
fi

if [ ! -f "$DTB_FILE" ]; then
echo "Error: DTB file '$DTB_FILE' not found"
exit 1
fi

# Count CPUs in DTB using dtc
DTC=$(which dtc 2>/dev/null)
if [ -z "$DTC" ]; then
echo "Error: dtc tool not found in PATH"
echo "DTB verification requires the device tree compiler (dtc)"
echo "Please install dtc and try again"
exit 1
fi

CPU_COUNT=$($DTC -I dtb -O dts "$DTB_FILE" 2>/dev/null | grep -c "cpu@")

if [ "$CPU_COUNT" -ne "$EXPECTED_COUNT" ]; then
echo "========================================="
echo "DTB Configuration Mismatch Detected!"
echo "========================================="
echo "DTB file '$DTB_FILE' contains $CPU_COUNT CPU(s)"
echo "But you requested $EXPECTED_COUNT CPU(s)"
echo ""
echo "Solution:"
echo " make SMP=$EXPECTED_COUNT riscv-harts.dtsi minimal.dtb"
echo ""
echo "This will regenerate the DTB with correct CPU count."
echo "========================================="
exit 1
fi

exit 0