diff --git a/Makefile b/Makefile index 529f43f1..610add28 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 @@ -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 diff --git a/scripts/verify-dtb.sh b/scripts/verify-dtb.sh new file mode 100755 index 00000000..5996a327 --- /dev/null +++ b/scripts/verify-dtb.sh @@ -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 " + 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