Просмотр исходного кода

SoC/evalsoc: Refactor build system by modularizing configuration files

- Move CPU configuration options (XLCFG_xxx) from runmode.mk to new cpuconfig.mk
- Move QEMU emulation options from build.mk to new qemu.mk
- Move XLModel emulation options from build.mk to new xlmodel.mk
- Update build.mk to include the new modularized makefiles
- Update documentation to reflect the refactored build system structure

This refactoring improves modularity by separating different configuration
aspects into dedicated makefiles, making the build system easier to
maintain and extend.

Signed-off-by: Huaqi Fang <578567190@qq.com>
Huaqi Fang 2 недель назад
Родитель
Сommit
b72236bc9c

+ 17 - 54
SoC/evalsoc/build.mk

@@ -93,8 +93,6 @@ ifeq ($(wildcard $(LINKER_SCRIPT)),)
 $(warning The link script file $(LINKER_SCRIPT) for $(SOC) doesn't exist, please check!)
 endif
 
--include $(NUCLEI_SDK_SOC)/runmode.mk
-
 # Add extra cflags for SoC related
 ifeq ($(DOWNLOAD), flash)
 COMMON_FLAGS += -DVECTOR_TABLE_REMAPPED
@@ -104,13 +102,6 @@ ifneq ($(SYSCLK),)
 COMMON_FLAGS += -DSYSTEM_CLOCK=$(SYSCLK)
 endif
 
-## QEMU/XLSPIKE options
-ifeq ($(XLCFG_PLIC),1)
-QEMU_ELF_OPT := -bios
-else
-QEMU_ELF_OPT := -kernel
-endif
-
 ifneq ($(SMP),)
 $(call assert,$(call gt,$(SMP),1),SMP must be a integer number >= 2)
 ifneq ($(BOOT_HARTID),)
@@ -138,20 +129,11 @@ ifneq ($(SPLITMODE),)
 OPENOCD_CMD_ARGS += set SPLITMODE $(SPLITMODE);
 endif
 
-
 # If HARTID_OFS is not empty
 ifneq ($(HARTID_OFS),)
 COMMON_FLAGS += -D__HARTID_OFFSET=$(HARTID_OFS)
 endif
 
-ifneq ($(CPU_CNT),)
-QEMU_OPT += -smp $(CPU_CNT)
-endif
-## xlspike is only valid for nuclei demosoc/evalsoc
-ifneq ($(CPU_CNT),)
-XLSPIKE_OPT += -p$(CPU_CNT)
-endif
-
 # Set RISCV_ARCH and RISCV_ABI
 CORE_UPPER := $(call uc, $(CORE))
 include $(NUCLEI_SDK_BUILD)/Makefile.core
@@ -183,42 +165,6 @@ endif
 RISCV_ABI ?= $(word 2, $(CORE_ARCH_ABI))
 RISCV_TUNE ?= $(word 3, $(CORE_ARCH_ABI))
 
-# Handle QEMU Emulation
-# - QEMU_MC_EXTOPT is used to pass extra options to qemu -M machine options for evalsoc,
-#   please dont pass any extra , to this make variable, you can pass such
-#   as QEMU_MC_EXTOPT=debug=1 but not pass QEMU_MC_EXTOPT=,debug=1
-# - QEMU_CPU_EXTOPT is used to pass extra options to qemu -cpu cpu options for evalsoc,
-#   please dont pass any extra , to this make variable, you can pass such
-#   as QEMU_CPU_EXTOPT=vlen=512 but not pass QEMU_CPU_EXTOPT=,vlen=512
-QEMU_MACHINE ?= nuclei_evalsoc,download=$(DOWNLOAD)
-# You can pass customized soc configuration here
-ifneq ($(QEMU_SOCCFG),)
-QEMU_MACHINE := $(QEMU_MACHINE),soc-cfg=$(NUCLEI_SDK_SOC)/$(QEMU_SOCCFG)
-endif
-ifneq ($(QEMU_MC_EXTOPT),)
-QEMU_MACHINE := $(QEMU_MACHINE),$(QEMU_MC_EXTOPT)
-endif
-
-QEMU_ARCHEXT ?= ${ARCH_EXT}
-QEMU_CPU ?= nuclei-$(CORE),ext=$(QEMU_ARCHEXT)
-ifneq ($(QEMU_CPU_EXTOPT),)
-QEMU_CPU := $(QEMU_CPU),$(QEMU_CPU_EXTOPT)
-endif
-
-ifneq ($(SEMIHOST),)
-QEMU_OPT += -semihosting
-endif
-
-# Handle XLModel Emulation
-XLMODEL_OPT += -M nuclei_evalsoc
-XLMODEL_OPT += --cpu=$(CORE) --download=$(DOWNLOAD)
-ifneq ($(ARCH_EXT),)
-XLMODEL_OPT += --ext=$(ARCH_EXT)
-endif
-ifneq ($(CPU_CNT),)
-XLMODEL_OPT += --smp=$(CPU_CNT)
-endif
-
 ifneq ($(CODESIZE),)
 COMMON_FLAGS += -DCODESIZE=$(CODESIZE)
 endif
@@ -258,3 +204,20 @@ ifneq ($(VALID_NUCLEI_SDK_SOC_BOARD),)
 INCDIRS += $(VALID_NUCLEI_SDK_SOC_BOARD)/Include
 C_SRCDIRS += $(VALID_NUCLEI_SDK_SOC_BOARD)/Source
 endif
+
+# NOTE: runmode.mk is mainly used by nuclei sdk for evalsoc to control ILM/DLM/ICACHE/DCACHE enable or disable
+# during `_premain_init`, which is only useful for internal usage
+-include $(NUCLEI_SDK_SOC)/runmode.mk
+# NOTE: When cpufeature.mk and cpufeature.h are generated by nuclei_gen
+# then CPU_CONFIG_MK will be defined as 1 in cpufeature.mk
+# And then cpuconfig.mk will not be included
+ifneq ($(CPU_CONFIG_MK),1)
+# NOTE: this is useful for nuclei sdk for evalsoc to dynamic control which cpu config to be enabled
+# eg. XLCFG_PLIC=1 will enable plic and will define CFG_HAS_PLIC
+-include $(NUCLEI_SDK_SOC)/cpuconfig.mk
+endif
+
+# NOTE: include nuclei qemu run options
+-include $(NUCLEI_SDK_SOC)/qemu.mk
+# NOTE: include nuclei near cycle model run options
+-include $(NUCLEI_SDK_SOC)/xlmodel.mk

+ 89 - 0
SoC/evalsoc/cpuconfig.mk

@@ -0,0 +1,89 @@
+# NOTE: This cpuconfig.mk is only valid when cpufeature.mk is not generated by nuclei_gen
+# NOTE: extra XLCFG_xxx make variables to control
+# cpu feature present or not which is only internally used by Nuclei(XinLai)
+# This will affect the cpufeature.h and evalsoc.h
+XLCFG_SPMP ?=
+ifeq ($(XLCFG_SPMP),1)
+XLCFG_TEE := 1
+COMMON_FLAGS += -DCFG_HAS_SPMP
+endif
+
+XLCFG_SMPU ?=
+ifeq ($(XLCFG_SMPU),1)
+XLCFG_TEE := 1
+COMMON_FLAGS += -DCFG_HAS_SMPU
+endif
+
+XLCFG_TEE ?=
+ifeq ($(XLCFG_TEE),1)
+COMMON_FLAGS += -DCFG_HAS_TEE
+endif
+
+XLCFG_PMP ?=
+ifeq ($(XLCFG_PMP),1)
+COMMON_FLAGS += -DCFG_HAS_PMP
+else ifeq ($(XLCFG_PMP),0)
+COMMON_FLAGS += -DUNDEF_CFG_HAS_PMP
+endif
+
+XLCFG_CCM ?=
+ifeq ($(XLCFG_CCM),1)
+COMMON_FLAGS += -DCFG_HAS_IOCC
+endif
+
+XLCFG_ECLIC ?=
+ifeq ($(XLCFG_ECLIC),1)
+COMMON_FLAGS += -DCFG_HAS_CLIC
+else ifeq ($(XLCFG_ECLIC),2)
+COMMON_FLAGS += -DCFG_HAS_ECLICV2 -DCFG_HAS_CLIC
+else ifeq ($(XLCFG_ECLIC),0)
+COMMON_FLAGS += -DUNDEF_CFG_HAS_CLIC
+endif
+
+XLCFG_PLIC ?=
+ifeq ($(XLCFG_PLIC),1)
+COMMON_FLAGS += -DCFG_HAS_PLIC
+endif
+
+XLCFG_SYSTIMER ?=
+ifeq ($(XLCFG_SYSTIMER),1)
+COMMON_FLAGS += -DCFG_TMR_PRIVATE
+else ifeq ($(XLCFG_SYSTIMER),0)
+COMMON_FLAGS += -DUNDEF_CFG_TMR_PRIVATE
+endif
+
+XLCFG_SSTC ?=
+ifeq ($(XLCFG_SSTC),1)
+COMMON_FLAGS += -DCFG_HAS_ISA_SSTC
+endif
+
+XLCFG_SMODE ?=
+ifeq ($(XLCFG_SMODE),1)
+COMMON_FLAGS += -DCFG_HAS_SMODE
+endif
+
+XLCFG_CIDU ?=
+ifeq ($(XLCFG_CIDU),1)
+COMMON_FLAGS += -DCFG_HAS_IDU
+endif
+
+XLCFG_HPM ?=
+ifeq ($(XLCFG_HPM),1)
+COMMON_FLAGS += -DCFG_HAS_HPM
+endif
+
+XLCFG_SMPCC ?=
+ifeq ($(XLCFG_SMPCC),1)
+COMMON_FLAGS += -DCFG_HAS_SMP
+else ifeq ($(XLCFG_SMPCC),0)
+COMMON_FLAGS += -DUNDEF_CFG_HAS_SMP
+endif
+
+XLCFG_ECC ?=
+ifeq ($(XLCFG_ECC),1)
+COMMON_FLAGS += -DCFG_HAS_ECC
+else ifeq ($(XLCFG_ECC),2)
+COMMON_FLAGS += -DCFG_HAS_ECC -DCFG_ECC_CODE_XOR
+else ifeq ($(XLCFG_ECC),0)
+COMMON_FLAGS += -DUNDEF_CFG_HAS_ECC
+endif

+ 42 - 0
SoC/evalsoc/qemu.mk

@@ -0,0 +1,42 @@
+# NOTE: options control how to run qemu
+## QEMU/XLSPIKE options
+ifeq ($(XLCFG_PLIC),1)
+QEMU_ELF_OPT := -bios
+else
+QEMU_ELF_OPT := -kernel
+endif
+
+ifneq ($(CPU_CNT),)
+QEMU_OPT += -smp $(CPU_CNT)
+endif
+## xlspike is only valid for nuclei demosoc/evalsoc
+ifneq ($(CPU_CNT),)
+XLSPIKE_OPT += -p$(CPU_CNT)
+endif
+
+# Handle QEMU Emulation
+# - QEMU_MC_EXTOPT is used to pass extra options to qemu -M machine options for evalsoc,
+#   please dont pass any extra , to this make variable, you can pass such
+#   as QEMU_MC_EXTOPT=debug=1 but not pass QEMU_MC_EXTOPT=,debug=1
+# - QEMU_CPU_EXTOPT is used to pass extra options to qemu -cpu cpu options for evalsoc,
+#   please dont pass any extra , to this make variable, you can pass such
+#   as QEMU_CPU_EXTOPT=vlen=512 but not pass QEMU_CPU_EXTOPT=,vlen=512
+QEMU_MACHINE ?= nuclei_evalsoc,download=$(DOWNLOAD)
+# You can pass customized soc configuration here
+ifneq ($(QEMU_SOCCFG),)
+QEMU_MACHINE := $(QEMU_MACHINE),soc-cfg=$(NUCLEI_SDK_SOC)/$(QEMU_SOCCFG)
+endif
+ifneq ($(QEMU_MC_EXTOPT),)
+QEMU_MACHINE := $(QEMU_MACHINE),$(QEMU_MC_EXTOPT)
+endif
+
+QEMU_ARCHEXT ?= ${ARCH_EXT}
+QEMU_CPU ?= nuclei-$(CORE),ext=$(QEMU_ARCHEXT)
+ifneq ($(QEMU_CPU_EXTOPT),)
+QEMU_CPU := $(QEMU_CPU),$(QEMU_CPU_EXTOPT)
+endif
+
+ifneq ($(SEMIHOST),)
+QEMU_OPT += -semihosting
+endif
+

+ 1 - 84
SoC/evalsoc/runmode.mk

@@ -1,4 +1,4 @@
-# RUN Mode, to control ILM/DLM/ICACHE/DCACHE enable or disable
+# NOTE: RUN Mode, to control ILM/DLM/ICACHE/DCACHE enable or disable
 # Combined with ILM_EN/DLM_EN/IC_EN/DC_EN/CCM_EN
 # only works in evalsoc
 RUNMODE ?=
@@ -105,86 +105,3 @@ ifneq ($(ECC_EN),)
 COMMON_FLAGS += -DRUNMODE_ECC_EN=$(ECC_EN)
 endif
 
-# NOTE: extra XLCFG_xxx make variables to control
-# cpu feature present or not which is only internally used by Nuclei(XinLai)
-# This will affect the cpufeature.h and evalsoc.h
-XLCFG_SPMP ?=
-ifeq ($(XLCFG_SPMP),1)
-XLCFG_TEE := 1
-COMMON_FLAGS += -DCFG_HAS_SPMP
-endif
-
-XLCFG_SMPU ?=
-ifeq ($(XLCFG_SMPU),1)
-XLCFG_TEE := 1
-COMMON_FLAGS += -DCFG_HAS_SMPU
-endif
-
-XLCFG_TEE ?=
-ifeq ($(XLCFG_TEE),1)
-COMMON_FLAGS += -DCFG_HAS_TEE
-endif
-
-XLCFG_PMP ?=
-ifeq ($(XLCFG_PMP),1)
-COMMON_FLAGS += -DCFG_HAS_PMP
-else ifeq ($(XLCFG_PMP),0)
-COMMON_FLAGS += -DUNDEF_CFG_HAS_PMP
-endif
-
-XLCFG_CCM ?=
-ifeq ($(XLCFG_CCM),1)
-COMMON_FLAGS += -DCFG_HAS_IOCC
-endif
-
-XLCFG_ECLIC ?=
-ifeq ($(XLCFG_ECLIC),1)
-COMMON_FLAGS += -DCFG_HAS_CLIC
-else ifeq ($(XLCFG_ECLIC),2)
-COMMON_FLAGS += -DCFG_HAS_ECLICV2 -DCFG_HAS_CLIC
-else ifeq ($(XLCFG_ECLIC),0)
-COMMON_FLAGS += -DUNDEF_CFG_HAS_CLIC
-endif
-
-XLCFG_PLIC ?=
-ifeq ($(XLCFG_PLIC),1)
-COMMON_FLAGS += -DCFG_HAS_PLIC
-endif
-
-XLCFG_SYSTIMER ?=
-ifeq ($(XLCFG_SYSTIMER),1)
-COMMON_FLAGS += -DCFG_TMR_PRIVATE
-else ifeq ($(XLCFG_SYSTIMER),0)
-COMMON_FLAGS += -DUNDEF_CFG_TMR_PRIVATE
-endif
-
-XLCFG_SSTC ?=
-ifeq ($(XLCFG_SSTC),1)
-COMMON_FLAGS += -DCFG_HAS_ISA_SSTC
-endif
-
-XLCFG_CIDU ?=
-ifeq ($(XLCFG_CIDU),1)
-COMMON_FLAGS += -DCFG_HAS_IDU
-endif
-
-XLCFG_HPM ?=
-ifeq ($(XLCFG_HPM),1)
-COMMON_FLAGS += -DCFG_HAS_HPM
-endif
-
-XLCFG_SMPCC ?=
-ifeq ($(XLCFG_SMPCC),1)
-COMMON_FLAGS += -DCFG_HAS_SMP
-else ifeq ($(XLCFG_SMPCC),0)
-COMMON_FLAGS += -DUNDEF_CFG_HAS_SMP
-endif
-
-XLCFG_ECC ?=
-ifeq ($(XLCFG_ECC),1)
-COMMON_FLAGS += -DCFG_HAS_ECC
-else ifeq ($(XLCFG_ECC),2)
-COMMON_FLAGS += -DCFG_HAS_ECC -DCFG_ECC_CODE_XOR
-else ifeq ($(XLCFG_ECC),0)
-COMMON_FLAGS += -DUNDEF_CFG_HAS_ECC
-endif

+ 11 - 0
SoC/evalsoc/xlmodel.mk

@@ -0,0 +1,11 @@
+# NOTE: options control how to run xlmodel
+# Handle XLModel Emulation
+XLMODEL_OPT += -M nuclei_evalsoc
+XLMODEL_OPT += --cpu=$(CORE) --download=$(DOWNLOAD)
+ifneq ($(ARCH_EXT),)
+XLMODEL_OPT += --ext=$(ARCH_EXT)
+endif
+ifneq ($(CPU_CNT),)
+XLMODEL_OPT += --smp=$(CPU_CNT)
+endif
+

+ 2 - 0
doc/source/changelog.rst

@@ -103,6 +103,8 @@ This is release version of ``0.9.0`` of Nuclei SDK, which is still under develop
   - Must pass ``-fomit-frame-pointer`` when using ``Zc`` extension to generate push/pop instructions, see https://github.com/riscvarchive/riscv-code-size-reduction/issues/194
   - Toolchain Terapines ZCC support is updated to match latest ZCC 4.1.7 release which is integrated with Nuclei Studio 2025.10
   - Nuclei **N100 series** CPU Core with **ECLIC** configured are supported, see :ref:`N100 support limitation <n100_support_limitation>`
+  - Refactor evalsoc build system by moving CPU configuration options(``XLCFG_xxx``) from ``runmode.mk`` to ``cpuconfig.mk``, QEMU options from ``build.mk`` to ``qemu.mk``, and xlmodel options from ``build.mk`` to ``xlmodel.mk`` for better modularity
+  - ``XLCFG_xxx`` for evalsoc will not be effective when ``cpufeature.mk`` are generated by ``nuclei_gen``, this is mainly used internally to quickly enable/disable certain cpu feature via make options
 
 * SoC
 

+ 1 - 1
doc/source/design/soc/evalsoc.rst

@@ -92,7 +92,6 @@ Extra make variables supported only in this SoC and used internally only by Nucl
   * **LDSPEC_EN**: it is used internally by Nuclei, used to control load speculative enable or disable, introduced in 0.6.0 release.
   * **BPU_EN**: it is used internally by Nuclei, used to control branch prediction unit enable or disable, introduced in 0.6.0 release.
   * **ECC_EN**: it is used internally by Nuclei, used to control (ilm/dlm/L1 I/Dcache)ecc unit enable or disable, introduced in 0.7.0 release.
-  * **XLCFG_xxx** make variables such as **XLCFG_CIDU**, **XLCFG_CCM**, **XLCFG_TEE** and **XLCFG_SMPU** which are used to overwrite default macros defined in ``cpufeature.h`` which will affect **XXX_PRESENT** macros in ``evalsoc.h``, introduced in 0.7.0 release.
   * **CODESIZE**: it is used to control whether remove all template routine code for interrupt and exception and banner print code to measure basic code size requirement for evalsoc when ``CODESIZE=1``
   * **SYSCLK**: it is used together with ``CODESIZE=1`` to overwrite default ``SYSTEM_CLOCK`` macro value for different bitstream, eg. ``SYSCLK=50000000 CODESIZE=1``, it will set default SYSTEM_CLOCK to 50000000.
   * **QEMU_MC_EXTOPT** is used to pass extra options to Nuclei Qemu ``-M`` machine options for evalsoc,
@@ -100,6 +99,7 @@ Extra make variables supported only in this SoC and used internally only by Nucl
   * **QEMU_CPU_EXTOPT** is used to pass extra options to Nuclei Qemu ``-cpu`` cpu options for evalsoc,
     please dont pass any extra ``,`` to this make variable, you can pass such as ``QEMU_CPU_EXTOPT=vlen=512`` but
     not pass ``QEMU_CPU_EXTOPT=,vlen=512``
+  * **XLCFG_xxx** make variables such as **XLCFG_CIDU**, **XLCFG_CCM**, **XLCFG_TEE** and **XLCFG_SMPU** which are used to overwrite default macros defined in ``cpufeature.h`` which will affect **XXX_PRESENT** macros in ``evalsoc.h``, introduced in 0.7.0 release, and these variables now moved from ``runmode.mk`` to a new ``cpuconfig.mk`` and if ``cpufeature.mk`` is generated by ``nuclei_gen``, then it will not be effective from 0.9.0 release.
   * **XLCFG_ECLIC**: it is used to control ECLIC configuration, when ``XLCFG_ECLIC=0`` it will undefine ``CFG_HAS_CLIC``, when ``XLCFG_ECLIC=1`` it will define ``CFG_HAS_CLIC``, and when ``XLCFG_ECLIC=2`` it will define both ``CFG_HAS_ECLICV2`` and ``CFG_HAS_CLIC`` for ECLICv2 support, introduced in 0.9.0 release.
   * **ECLIC_HWCTX**: it is used to enable ECLIC hardware context auto-save feature, when ``ECLIC_HWCTX=1`` it will define ``ECLIC_HW_CTX_AUTO`` macro, introduced in 0.9.0 release.