diff --git a/Makefile b/Makefile index 36f345914..bae8d3373 100644 --- a/Makefile +++ b/Makefile @@ -3,14 +3,17 @@ # global helper variables T := $(CURDIR) +# $(TARGET_DIR) must be relative path under $(T) +TARGET_DIR ?= + # BOARD/SCENARIO/BOARD_FILE/SCENARIO_FILE/KCONFIG_FILE parameters sanity check: # # Only below usages are VALID: (target = all | hypervisor) # 1. make -# 2. make KCONFIG_FILE=xxx -# 3. make BOARD=xxx SCENARIO=xxx -# 4. make BOARD_FILE=xxx SCENARIO_FILE=xxx -# 5. make KCONFIG_FILE=xxx BOARD_FILE=xxx SCENARIO_FILE=xxx +# 2. make KCONFIG_FILE=xxx [TARGET_DIR=xxx] +# 3. make BOARD=xxx SCENARIO=xxx [TARGET_DIR=xxx] +# 4. make BOARD_FILE=xxx SCENARIO_FILE=xxx [TARGET_DIR=xxx] +# 5. make KCONFIG_FILE=xxx BOARD_FILE=xxx SCENARIO_FILE=xxx [TARGET_DIR=xxx] # # Especially for case 1 that no any parameters are specified: # a. If hypervisor/build/.config file which generated by "make menuconfig" exist, @@ -21,6 +24,9 @@ T := $(CURDIR) # the default BOARD/SCENARIO will be loaded: # i.e. equal: make BOARD=$(BOARD) SCENARIO=$(SCENARIO) # +# For case 2/3, configurations are imported from TARGET_DIR when TARGET_DIR is specified; +# For case 4/5, configurations are from XML files and saved to TARGET_DIR if it is specified; +# # The grep process did not handle corner case when '#' is manually put right after config value as comments, # i.e. it will be failed in the case of "CONFIG_XXX=y # some comments here " @@ -39,6 +45,14 @@ ifneq ($(BOARD)$(SCENARIO),) endif endif +ifeq ($(BOARD_FILE)$(SCENARIO_FILE),) + ifneq ($(TARGET_DIR),) + ifneq ($(TARGET_DIR), $(wildcard $(TARGET_DIR))) + $(error TARGET_DIR $(TARGET_DIR) does not exist) + endif + endif +endif + ifneq ($(BOARD_FILE)$(SCENARIO_FILE),) ifneq ($(BOARD_FILE), $(wildcard $(BOARD_FILE))) $(error BOARD_FILE: $(BOARD_FILE) does not exist) @@ -99,6 +113,7 @@ BUILD_VERSION ?= BUILD_TAG ?= GENED_ACPI_INFO_HEADER = $(T)/hypervisor/arch/x86/configs/$(BOARD)/$(BOARD)_acpi_info.h HV_CFG_LOG = $(HV_OUT)/cfg.log +DEFAULT_DEFCONFIG_DIR = $(T)/hypervisor/arch/x86/configs export TOOLS_OUT BOARD SCENARIO FIRMWARE RELEASE @@ -146,18 +161,19 @@ hypervisor: && [ "$(SCENARIO)" != "logical_partition" ] && [ "$(SCENARIO)" != "hybrid" ]; then \ echo "SCENARIO <$(SCENARIO)> is not supported. "; exit 1; \ fi + @if [ "$(BOARD_FILE)" != "" ] && [ -f $(BOARD_FILE) ] && [ "$(SCENARIO_FILE)" != "" ] && [ -f $(SCENARIO_FILE) ] && [ "$(TARGET_DIR)" = "" ]; then \ + echo "No TARGET_DIR parameter is specified, the original configuration source is overwritten!";\ + fi $(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT) BOARD_FILE=$(BOARD_FILE) SCENARIO_FILE=$(SCENARIO_FILE) clean; - $(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT) BOARD_FILE=$(BOARD_FILE) SCENARIO_FILE=$(SCENARIO_FILE) defconfig; - @if [ -f $(KCONFIG_FILE) ]; then \ - cp $(KCONFIG_FILE) $(HV_OUT)/.config; \ - elif [ "$(CONFIG_XML_ENABLED)" != "true" ]; then \ + $(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT) BOARD_FILE=$(BOARD_FILE) SCENARIO_FILE=$(SCENARIO_FILE) TARGET_DIR=$(abspath $(TARGET_DIR)) defconfig; + @if [ "$(CONFIG_XML_ENABLED)" != "true" ] && [ ! -f $(KCONFIG_FILE) ]; then \ echo "CONFIG_$(shell echo $(SCENARIO) | tr a-z A-Z)=y" >> $(HV_OUT)/.config; \ if [ "$(SCENARIO)" != "sdc" ]; then \ echo "CONFIG_MAX_KATA_VM_NUM=0" >> $(HV_OUT)/.config; \ fi; \ fi; \ - $(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT) BOARD_FILE=$(BOARD_FILE) SCENARIO_FILE=$(SCENARIO_FILE) oldconfig; - $(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT) BOARD_FILE=$(BOARD_FILE) SCENARIO_FILE=$(SCENARIO_FILE) + $(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT) BOARD_FILE=$(BOARD_FILE) SCENARIO_FILE=$(SCENARIO_FILE) TARGET_DIR=$(abspath $(TARGET_DIR)) oldconfig; + $(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT) BOARD_FILE=$(BOARD_FILE) SCENARIO_FILE=$(SCENARIO_FILE) TARGET_DIR=$(abspath $(TARGET_DIR)) #ifeq ($(FIRMWARE),uefi) @if [ "$(SCENARIO)" != "logical_partition" ] && [ "$(SCENARIO)" != "hybrid" ]; then \ echo "building hypervisor as EFI executable..."; \ @@ -167,17 +183,24 @@ hypervisor: @echo -e "\n\033[47;30mACRN Configuration Summary:\033[0m \nBOARD = $(BOARD)\t SCENARIO = $(SCENARIO)" > $(HV_CFG_LOG); \ if [ -f $(KCONFIG_FILE) ]; then \ echo -e "Hypervisor configuration is based on:\n\tKconfig file:\t$(KCONFIG_FILE);" >> $(HV_CFG_LOG); \ - else \ - echo -e "Hypervisor configuration is based on:\n\t$(BOARD) defconfig file:\t$(T)/hypervisor/arch/x86/configs/$(BOARD).config;" \ - "\n\tOthers are set by default in:\t$(T)/hypervisor/arch/x86/Kconfig;" >> $(HV_CFG_LOG); \ fi; \ + if [ "$(TARGET_DIR)" = "" ]; then \ + if [ ! -f $(KCONFIG_FILE) ]; then \ + echo -e "Hypervisor configuration is based on:\n\t$(BOARD) " \ + "defconfig file:\t$(DEFAULT_DEFCONFIG_DIR)/$(BOARD).config;" >> $(HV_CFG_LOG); \ + fi; \ + elif [ ! -f $(KCONFIG_FILE) ]; then \ + echo -e "Hypervisor configuration is based on:\n\t$(BOARD) " \ + "defconfig file:\t$(abspath $(TARGET_DIR))/$(BOARD).config;" >> $(HV_CFG_LOG); \ + fi; \ + echo -e "\tOthers are set by default in:\t$(T)/hypervisor/arch/x86/Kconfig;" >> $(HV_CFG_LOG); \ if [ "$(CONFIG_XML_ENABLED)" = "true" ]; then \ echo -e "VM configuration is based on:\n\tBOARD File:\t$(BOARD_FILE);" \ "\n\tSCENARIO File:\t$(SCENARIO_FILE);" >> $(HV_CFG_LOG); \ else \ echo "VM configuration is based on current code base;" >> $(HV_CFG_LOG); \ fi; \ - if [ -f $(GENED_ACPI_INFO_HEADER) ] && [ "$(CONFIG_XML_ENABLED)" != "true" ]; then \ + if [ -f $(GENED_ACPI_INFO_HEADER) ] && [ "$(CONFIG_XML_ENABLED)" != "true" ] && [ "TARGET_DIR" = "" ]; then \ echo -e "\033[33mWarning: The platform ACPI info is based on acrn-config generated $(GENED_ACPI_INFO_HEADER), please make sure its validity.\033[0m" >> $(HV_CFG_LOG); \ fi @cat $(HV_CFG_LOG) @@ -198,6 +221,7 @@ clean: $(MAKE) -C $(T)/misc OUT_DIR=$(TOOLS_OUT) clean $(MAKE) -C $(T)/doc BUILDDIR=$(DOC_OUT) clean rm -rf $(ROOT_OUT) + rm -rf $(TARGET_DIR) .PHONY: install install: hypervisor-install devicemodel-install tools-install diff --git a/hypervisor/Makefile b/hypervisor/Makefile index d3f5471bc..b876f54aa 100644 --- a/hypervisor/Makefile +++ b/hypervisor/Makefile @@ -76,6 +76,14 @@ ifeq ($(SCENARIO),) endif endif +ifeq ($(TARGET_DIR),) + BOARD_CFG_DIR := arch/x86/configs/$(BOARD) + SCENARIO_CFG_DIR := scenarios/$(SCENARIO) +else + BOARD_CFG_DIR := $(TARGET_DIR)/$(BOARD) + SCENARIO_CFG_DIR := $(TARGET_DIR)/$(SCENARIO) +endif + LD_IN_TOOL = scripts/genld.sh BASH = $(shell which bash) @@ -170,8 +178,8 @@ INCLUDE_PATH += include/hw INCLUDE_PATH += boot/include INCLUDE_PATH += boot/include/guest INCLUDE_PATH += $(HV_OBJDIR)/include -INCLUDE_PATH += arch/x86/configs/$(BOARD) -INCLUDE_PATH += scenarios/$(SCENARIO) +INCLUDE_PATH += $(BOARD_CFG_DIR) +INCLUDE_PATH += $(SCENARIO_CFG_DIR) CC ?= gcc AS ?= as @@ -257,10 +265,10 @@ HW_C_SRCS += common/sched_bvt.c endif HW_C_SRCS += hw/pci.c HW_C_SRCS += arch/x86/configs/vm_config.c -HW_C_SRCS += arch/x86/configs/$(BOARD)/board.c -HW_C_SRCS += scenarios/$(SCENARIO)/vm_configurations.c -ifneq (,$(wildcard scenarios/$(SCENARIO)/pci_dev.c)) -HW_C_SRCS += scenarios/$(SCENARIO)/pci_dev.c +HW_C_SRCS += $(BOARD_CFG_DIR)/board.c +HW_C_SRCS += $(SCENARIO_CFG_DIR)/vm_configurations.c +ifneq (,$(wildcard $(SCENARIO_CFG_DIR)/pci_dev.c)) +HW_C_SRCS += $(SCENARIO_CFG_DIR)/pci_dev.c endif HW_C_SRCS += boot/acpi_base.c HW_C_SRCS += boot/cmdline.c @@ -378,7 +386,7 @@ VERSION := $(HV_OBJDIR)/include/version.h # Create platform_acpi_info.h TEMPLATE_ACPI_INFO_HEADER := arch/x86/configs/platform_acpi_info.h BOARDTEMPLATE_ACPI_INFO_HEADER := arch/x86/configs/$(BOARD)/platform_acpi_info.h -SOURCE_ACPI_INFO_HEADER := arch/x86/configs/$(BOARD)/$(BOARD)_acpi_info.h +SOURCE_ACPI_INFO_HEADER := $(BOARD_CFG_DIR)/$(BOARD)_acpi_info.h TARGET_ACPI_INFO_HEADER := $(HV_OBJDIR)/include/platform_acpi_info.h $(TARGET_ACPI_INFO_HEADER): $(HV_OBJDIR)/$(HV_CONFIG) @@ -388,7 +396,7 @@ ifeq ($(CONFIG_ENFORCE_VALIDATED_ACPI_INFO),y) echo "Expected ACPI info header at $(SOURCE_ACPI_INFO_HEADER)" && \ echo "" && \ echo "The ACPI info header for this board is not available. Please use" && \ - echo "acrn-config tool for the target board to generate a validated one." \ + echo "acrn-config tool for the target board to generate a validated one." && \ echo "If you want to build the hypervisor with the template ACPI info," && \ echo "unset ENFORCE_VALIDATED_ACPI_INFO using 'make menuconfig'." && \ false; \ @@ -506,6 +514,16 @@ distclean: PHONY: (VERSION) $(VERSION): @echo "SCENARIO <$(SCENARIO)> for BOARD <$(BOARD)> is specified." + @if [ ! -d $(BOARD_CFG_DIR) ]; then \ + echo "Configurations for BOARD $(BOARD) is not found."; exit 1; \ + else \ + echo "Found BOARD configurations under $(BOARD_CFG_DIR)"; \ + fi; + @if [ ! -d $(SCENARIO_CFG_DIR) ]; then \ + echo "Configurations for SCENARIO $(SCENARIO) is not found."; exit 1; \ + else \ + echo "Found SCENARIO configurations under $(SCENARIO_CFG_DIR)"; \ + fi; touch $(VERSION) @COMMIT=`git rev-parse --verify --short HEAD 2>/dev/null`;\ DIRTY=`git diff-index --name-only HEAD`;\ diff --git a/hypervisor/scripts/makefile/cfg_update.mk b/hypervisor/scripts/makefile/cfg_update.mk index 6f03501b3..5b8c60b30 100644 --- a/hypervisor/scripts/makefile/cfg_update.mk +++ b/hypervisor/scripts/makefile/cfg_update.mk @@ -37,10 +37,18 @@ update_config: ifeq ($(CONFIG_XML_ENABLED),true) @if [ ! -f $(UPDATE_RESULT) ]; then \ mkdir -p $(dir $(UPDATE_RESULT));\ - python3 ../misc/acrn-config/board_config/board_cfg_gen.py --board $(BOARD_FILE) --scenario $(SCENARIO_FILE) > $(UPDATE_RESULT);\ + if [ "$(TARGET_DIR)" = "" ]; then \ + python3 ../misc/acrn-config/board_config/board_cfg_gen.py --board $(BOARD_FILE) --scenario $(SCENARIO_FILE) > $(UPDATE_RESULT);\ + else \ + python3 ../misc/acrn-config/board_config/board_cfg_gen.py --board $(BOARD_FILE) --scenario $(SCENARIO_FILE) --out $(TARGET_DIR) > $(UPDATE_RESULT);\ + fi;\ cat $(UPDATE_RESULT);\ if [ "`sed -n /successfully/p $(UPDATE_RESULT)`" = "" ]; then rm -f $(UPDATE_RESULT); exit 1; fi;\ - python3 ../misc/acrn-config/scenario_config/scenario_cfg_gen.py --board $(BOARD_FILE) --scenario $(SCENARIO_FILE) > $(UPDATE_RESULT);\ + if [ "$(TARGET_DIR)" = "" ]; then \ + python3 ../misc/acrn-config/scenario_config/scenario_cfg_gen.py --board $(BOARD_FILE) --scenario $(SCENARIO_FILE) > $(UPDATE_RESULT);\ + else \ + python3 ../misc/acrn-config/scenario_config/scenario_cfg_gen.py --board $(BOARD_FILE) --scenario $(SCENARIO_FILE) --out $(TARGET_DIR) > $(UPDATE_RESULT);\ + fi;\ cat $(UPDATE_RESULT);\ if [ "`sed -n /successfully/p $(UPDATE_RESULT)`" = "" ]; then rm -f $(UPDATE_RESULT); exit 1; fi;\ echo "Import hypervisor Board/VM configuration from XMLs, configurations in source code has been overwritten!";\ diff --git a/hypervisor/scripts/makefile/kconfig.mk b/hypervisor/scripts/makefile/kconfig.mk index 05ee4d8a3..b1047111a 100644 --- a/hypervisor/scripts/makefile/kconfig.mk +++ b/hypervisor/scripts/makefile/kconfig.mk @@ -72,9 +72,18 @@ $(HV_OBJDIR)/$(HV_CONFIG_H): $(HV_OBJDIR)/$(HV_CONFIG) .PHONY: defconfig defconfig: $(KCONFIG_DEPS) @mkdir -p $(HV_OBJDIR) - @BOARD=$(TARGET_BOARD) \ - python3 $(KCONFIG_DIR)/defconfig.py Kconfig \ - $(HV_OBJDIR)/$(HV_CONFIG) + @if [ ! -f $(KCONFIG_FILE) ] && [ "$(CONFIG_XML_ENABLED)" != "true" ]; then \ + BOARD=$(TARGET_BOARD) python3 $(KCONFIG_DIR)/defconfig.py Kconfig $(HV_OBJDIR)/$(HV_CONFIG); \ + else \ + if [ "$(KCONFIG_FILE)" != "" ] && [ -f $(KCONFIG_FILE) ]; then \ + echo "Writing $(HV_OBJDIR)/$(HV_CONFIG) with $(KCONFIG_FILE)"; \ + cp $(KCONFIG_FILE) $(HV_OBJDIR)/$(HV_CONFIG); \ + elif [ "$(CONFIG_XML_ENABLED)" = "true" ] && [ "$(TARGET_DIR)" != "" ] && [ -d $(TARGET_DIR) ]; then \ + echo "Writing $(HV_OBJDIR)/$(HV_CONFIG) with $(TARGET_DIR)/$(BOARD).config"; \ + cp $(TARGET_DIR)/$(BOARD).config $(HV_OBJDIR)/$(HV_CONFIG); \ + fi; \ + python3 $(KCONFIG_DIR)/silentoldconfig.py Kconfig $(HV_OBJDIR)/$(HV_CONFIG) RELEASE=$(RELEASE); \ + fi # Use silentoldconfig to forcefully update the current .config, or generate a # new one if no previous .config exists. This target can be used as a @@ -98,7 +107,7 @@ savedefconfig: $(HV_OBJDIR)/$(HV_CONFIG) $(eval $(call check_dep_exec,menuconfig,MENUCONFIG_DEPS)) export KCONFIG_CONFIG := $(HV_OBJDIR)/$(HV_CONFIG) -menuconfig: $(MENUCONFIG_DEPS) $(HV_OBJDIR)/$(HV_CONFIG) +menuconfig: $(MENUCONFIG_DEPS) defconfig @python3 $(shell which menuconfig) Kconfig CFLAGS += -include $(HV_OBJDIR)/$(HV_CONFIG_H)