Skip to content

Commit bce6a3c

Browse files
jsun26intelwenlingz
authored andcommitted
Makefile: support make with external configurations
Customer might have specific folder where stores their own configurations for their customized scenario/board, so add TARGET_DIR parameter to support option that build hyprvisor with specified configurations. So valid usages are: (target = all | hypervisor) 1. make <target> 2. make <target> KCONFIG_FILE=xxx [TARGET_DIR=xxx] 3. make <target> BOARD=xxx SCENARIO=xxx [TARGET_DIR=xxx] 4. make <target> BOARD_FILE=xxx SCENARIO_FILE=xxx [TARGET_DIR=xxx] 5. make <target> KCONFIG_FILE=xxx BOARD_FILE=xxx SCENARIO_FILE=xxx [TARGET_DIR=xxx] If TARGET_DIR parameter is not specified in make command, hypervisor will be built with board configurations under hypervisor/arch/x86/configs/ and scenario configurations under hypervisor/scenarios/. Moreover, the configurations would be overwritten if BOARD/SCENARIO files are specified in make command. If TARGET_DIR parameter is specified in make command, hypervisor will be built with configuration under that folder if no BOARD/SCENARIO files are specified. When BOARD/SCENARIO files are available in make command, the TARGET_DIR is used to store configurations that BOARD/SCENARIO file provided, i.e. Configurations in TARGET_DIR folder will be overwritten. Tracked-On: #4517 Signed-off-by: Victor Sun <victor.sun@intel.com>
1 parent 3774244 commit bce6a3c

File tree

4 files changed

+87
-28
lines changed

4 files changed

+87
-28
lines changed

Makefile

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
# global helper variables
44
T := $(CURDIR)
55

6+
# $(TARGET_DIR) must be relative path under $(T)
7+
TARGET_DIR ?=
8+
69
# BOARD/SCENARIO/BOARD_FILE/SCENARIO_FILE/KCONFIG_FILE parameters sanity check:
710
#
811
# Only below usages are VALID: (target = all | hypervisor)
912
# 1. make <target>
10-
# 2. make <target> KCONFIG_FILE=xxx
11-
# 3. make <target> BOARD=xxx SCENARIO=xxx
12-
# 4. make <target> BOARD_FILE=xxx SCENARIO_FILE=xxx
13-
# 5. make <target> KCONFIG_FILE=xxx BOARD_FILE=xxx SCENARIO_FILE=xxx
13+
# 2. make <target> KCONFIG_FILE=xxx [TARGET_DIR=xxx]
14+
# 3. make <target> BOARD=xxx SCENARIO=xxx [TARGET_DIR=xxx]
15+
# 4. make <target> BOARD_FILE=xxx SCENARIO_FILE=xxx [TARGET_DIR=xxx]
16+
# 5. make <target> KCONFIG_FILE=xxx BOARD_FILE=xxx SCENARIO_FILE=xxx [TARGET_DIR=xxx]
1417
#
1518
# Especially for case 1 that no any parameters are specified:
1619
# a. If hypervisor/build/.config file which generated by "make menuconfig" exist,
@@ -21,6 +24,9 @@ T := $(CURDIR)
2124
# the default BOARD/SCENARIO will be loaded:
2225
# i.e. equal: make <target> BOARD=$(BOARD) SCENARIO=$(SCENARIO)
2326
#
27+
# For case 2/3, configurations are imported from TARGET_DIR when TARGET_DIR is specified;
28+
# For case 4/5, configurations are from XML files and saved to TARGET_DIR if it is specified;
29+
#
2430
# The grep process did not handle corner case when '#' is manually put right after config value as comments,
2531
# i.e. it will be failed in the case of "CONFIG_XXX=y # some comments here "
2632

@@ -39,6 +45,14 @@ ifneq ($(BOARD)$(SCENARIO),)
3945
endif
4046
endif
4147

48+
ifeq ($(BOARD_FILE)$(SCENARIO_FILE),)
49+
ifneq ($(TARGET_DIR),)
50+
ifneq ($(TARGET_DIR), $(wildcard $(TARGET_DIR)))
51+
$(error TARGET_DIR $(TARGET_DIR) does not exist)
52+
endif
53+
endif
54+
endif
55+
4256
ifneq ($(BOARD_FILE)$(SCENARIO_FILE),)
4357
ifneq ($(BOARD_FILE), $(wildcard $(BOARD_FILE)))
4458
$(error BOARD_FILE: $(BOARD_FILE) does not exist)
@@ -99,6 +113,7 @@ BUILD_VERSION ?=
99113
BUILD_TAG ?=
100114
GENED_ACPI_INFO_HEADER = $(T)/hypervisor/arch/x86/configs/$(BOARD)/$(BOARD)_acpi_info.h
101115
HV_CFG_LOG = $(HV_OUT)/cfg.log
116+
DEFAULT_DEFCONFIG_DIR = $(T)/hypervisor/arch/x86/configs
102117

103118
export TOOLS_OUT BOARD SCENARIO FIRMWARE RELEASE
104119

@@ -146,18 +161,19 @@ hypervisor:
146161
&& [ "$(SCENARIO)" != "logical_partition" ] && [ "$(SCENARIO)" != "hybrid" ]; then \
147162
echo "SCENARIO <$(SCENARIO)> is not supported. "; exit 1; \
148163
fi
164+
@if [ "$(BOARD_FILE)" != "" ] && [ -f $(BOARD_FILE) ] && [ "$(SCENARIO_FILE)" != "" ] && [ -f $(SCENARIO_FILE) ] && [ "$(TARGET_DIR)" = "" ]; then \
165+
echo "No TARGET_DIR parameter is specified, the original configuration source is overwritten!";\
166+
fi
149167
$(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT) BOARD_FILE=$(BOARD_FILE) SCENARIO_FILE=$(SCENARIO_FILE) clean;
150-
$(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT) BOARD_FILE=$(BOARD_FILE) SCENARIO_FILE=$(SCENARIO_FILE) defconfig;
151-
@if [ -f $(KCONFIG_FILE) ]; then \
152-
cp $(KCONFIG_FILE) $(HV_OUT)/.config; \
153-
elif [ "$(CONFIG_XML_ENABLED)" != "true" ]; then \
168+
$(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT) BOARD_FILE=$(BOARD_FILE) SCENARIO_FILE=$(SCENARIO_FILE) TARGET_DIR=$(abspath $(TARGET_DIR)) defconfig;
169+
@if [ "$(CONFIG_XML_ENABLED)" != "true" ] && [ ! -f $(KCONFIG_FILE) ]; then \
154170
echo "CONFIG_$(shell echo $(SCENARIO) | tr a-z A-Z)=y" >> $(HV_OUT)/.config; \
155171
if [ "$(SCENARIO)" != "sdc" ]; then \
156172
echo "CONFIG_MAX_KATA_VM_NUM=0" >> $(HV_OUT)/.config; \
157173
fi; \
158174
fi; \
159-
$(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT) BOARD_FILE=$(BOARD_FILE) SCENARIO_FILE=$(SCENARIO_FILE) oldconfig;
160-
$(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT) BOARD_FILE=$(BOARD_FILE) SCENARIO_FILE=$(SCENARIO_FILE)
175+
$(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT) BOARD_FILE=$(BOARD_FILE) SCENARIO_FILE=$(SCENARIO_FILE) TARGET_DIR=$(abspath $(TARGET_DIR)) oldconfig;
176+
$(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT) BOARD_FILE=$(BOARD_FILE) SCENARIO_FILE=$(SCENARIO_FILE) TARGET_DIR=$(abspath $(TARGET_DIR))
161177
#ifeq ($(FIRMWARE),uefi)
162178
@if [ "$(SCENARIO)" != "logical_partition" ] && [ "$(SCENARIO)" != "hybrid" ]; then \
163179
echo "building hypervisor as EFI executable..."; \
@@ -167,17 +183,24 @@ hypervisor:
167183
@echo -e "\n\033[47;30mACRN Configuration Summary:\033[0m \nBOARD = $(BOARD)\t SCENARIO = $(SCENARIO)" > $(HV_CFG_LOG); \
168184
if [ -f $(KCONFIG_FILE) ]; then \
169185
echo -e "Hypervisor configuration is based on:\n\tKconfig file:\t$(KCONFIG_FILE);" >> $(HV_CFG_LOG); \
170-
else \
171-
echo -e "Hypervisor configuration is based on:\n\t$(BOARD) defconfig file:\t$(T)/hypervisor/arch/x86/configs/$(BOARD).config;" \
172-
"\n\tOthers are set by default in:\t$(T)/hypervisor/arch/x86/Kconfig;" >> $(HV_CFG_LOG); \
173186
fi; \
187+
if [ "$(TARGET_DIR)" = "" ]; then \
188+
if [ ! -f $(KCONFIG_FILE) ]; then \
189+
echo -e "Hypervisor configuration is based on:\n\t$(BOARD) " \
190+
"defconfig file:\t$(DEFAULT_DEFCONFIG_DIR)/$(BOARD).config;" >> $(HV_CFG_LOG); \
191+
fi; \
192+
elif [ ! -f $(KCONFIG_FILE) ]; then \
193+
echo -e "Hypervisor configuration is based on:\n\t$(BOARD) " \
194+
"defconfig file:\t$(abspath $(TARGET_DIR))/$(BOARD).config;" >> $(HV_CFG_LOG); \
195+
fi; \
196+
echo -e "\tOthers are set by default in:\t$(T)/hypervisor/arch/x86/Kconfig;" >> $(HV_CFG_LOG); \
174197
if [ "$(CONFIG_XML_ENABLED)" = "true" ]; then \
175198
echo -e "VM configuration is based on:\n\tBOARD File:\t$(BOARD_FILE);" \
176199
"\n\tSCENARIO File:\t$(SCENARIO_FILE);" >> $(HV_CFG_LOG); \
177200
else \
178201
echo "VM configuration is based on current code base;" >> $(HV_CFG_LOG); \
179202
fi; \
180-
if [ -f $(GENED_ACPI_INFO_HEADER) ] && [ "$(CONFIG_XML_ENABLED)" != "true" ]; then \
203+
if [ -f $(GENED_ACPI_INFO_HEADER) ] && [ "$(CONFIG_XML_ENABLED)" != "true" ] && [ "TARGET_DIR" = "" ]; then \
181204
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); \
182205
fi
183206
@cat $(HV_CFG_LOG)
@@ -198,6 +221,7 @@ clean:
198221
$(MAKE) -C $(T)/misc OUT_DIR=$(TOOLS_OUT) clean
199222
$(MAKE) -C $(T)/doc BUILDDIR=$(DOC_OUT) clean
200223
rm -rf $(ROOT_OUT)
224+
rm -rf $(TARGET_DIR)
201225

202226
.PHONY: install
203227
install: hypervisor-install devicemodel-install tools-install

hypervisor/Makefile

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ ifeq ($(SCENARIO),)
7676
endif
7777
endif
7878

79+
ifeq ($(TARGET_DIR),)
80+
BOARD_CFG_DIR := arch/x86/configs/$(BOARD)
81+
SCENARIO_CFG_DIR := scenarios/$(SCENARIO)
82+
else
83+
BOARD_CFG_DIR := $(TARGET_DIR)/$(BOARD)
84+
SCENARIO_CFG_DIR := $(TARGET_DIR)/$(SCENARIO)
85+
endif
86+
7987
LD_IN_TOOL = scripts/genld.sh
8088
BASH = $(shell which bash)
8189

@@ -166,8 +174,8 @@ INCLUDE_PATH += include/hw
166174
INCLUDE_PATH += boot/include
167175
INCLUDE_PATH += boot/include/guest
168176
INCLUDE_PATH += $(HV_OBJDIR)/include
169-
INCLUDE_PATH += arch/x86/configs/$(BOARD)
170-
INCLUDE_PATH += scenarios/$(SCENARIO)
177+
INCLUDE_PATH += $(BOARD_CFG_DIR)
178+
INCLUDE_PATH += $(SCENARIO_CFG_DIR)
171179

172180
CC ?= gcc
173181
AS ?= as
@@ -253,10 +261,10 @@ HW_C_SRCS += common/sched_bvt.c
253261
endif
254262
HW_C_SRCS += hw/pci.c
255263
HW_C_SRCS += arch/x86/configs/vm_config.c
256-
HW_C_SRCS += arch/x86/configs/$(BOARD)/board.c
257-
HW_C_SRCS += scenarios/$(SCENARIO)/vm_configurations.c
258-
ifneq (,$(wildcard scenarios/$(SCENARIO)/pci_dev.c))
259-
HW_C_SRCS += scenarios/$(SCENARIO)/pci_dev.c
264+
HW_C_SRCS += $(BOARD_CFG_DIR)/board.c
265+
HW_C_SRCS += $(SCENARIO_CFG_DIR)/vm_configurations.c
266+
ifneq (,$(wildcard $(SCENARIO_CFG_DIR)/pci_dev.c))
267+
HW_C_SRCS += $(SCENARIO_CFG_DIR)/pci_dev.c
260268
endif
261269
HW_C_SRCS += boot/acpi_base.c
262270
HW_C_SRCS += boot/cmdline.c
@@ -371,7 +379,7 @@ VERSION := $(HV_OBJDIR)/include/version.h
371379
# Create platform_acpi_info.h
372380
TEMPLATE_ACPI_INFO_HEADER := arch/x86/configs/platform_acpi_info.h
373381
BOARDTEMPLATE_ACPI_INFO_HEADER := arch/x86/configs/$(BOARD)/platform_acpi_info.h
374-
SOURCE_ACPI_INFO_HEADER := arch/x86/configs/$(BOARD)/$(BOARD)_acpi_info.h
382+
SOURCE_ACPI_INFO_HEADER := $(BOARD_CFG_DIR)/$(BOARD)_acpi_info.h
375383
TARGET_ACPI_INFO_HEADER := $(HV_OBJDIR)/include/platform_acpi_info.h
376384

377385
$(TARGET_ACPI_INFO_HEADER): $(HV_OBJDIR)/$(HV_CONFIG)
@@ -381,7 +389,7 @@ ifeq ($(CONFIG_ENFORCE_VALIDATED_ACPI_INFO),y)
381389
echo "Expected ACPI info header at $(SOURCE_ACPI_INFO_HEADER)" && \
382390
echo "" && \
383391
echo "The ACPI info header for this board is not available. Please use" && \
384-
echo "acrn-config tool for the target board to generate a validated one." \
392+
echo "acrn-config tool for the target board to generate a validated one." && \
385393
echo "If you want to build the hypervisor with the template ACPI info," && \
386394
echo "unset ENFORCE_VALIDATED_ACPI_INFO using 'make menuconfig'." && \
387395
false; \
@@ -499,6 +507,16 @@ distclean:
499507
PHONY: (VERSION)
500508
$(VERSION):
501509
@echo "SCENARIO <$(SCENARIO)> for BOARD <$(BOARD)> is specified."
510+
@if [ ! -d $(BOARD_CFG_DIR) ]; then \
511+
echo "Configurations for BOARD $(BOARD) is not found."; exit 1; \
512+
else \
513+
echo "Found BOARD configurations under $(BOARD_CFG_DIR)"; \
514+
fi;
515+
@if [ ! -d $(SCENARIO_CFG_DIR) ]; then \
516+
echo "Configurations for SCENARIO $(SCENARIO) is not found."; exit 1; \
517+
else \
518+
echo "Found SCENARIO configurations under $(SCENARIO_CFG_DIR)"; \
519+
fi;
502520
touch $(VERSION)
503521
@COMMIT=`git rev-parse --verify --short HEAD 2>/dev/null`;\
504522
DIRTY=`git diff-index --name-only HEAD`;\

hypervisor/scripts/makefile/cfg_update.mk

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@ update_config:
3737
ifeq ($(CONFIG_XML_ENABLED),true)
3838
@if [ ! -f $(UPDATE_RESULT) ]; then \
3939
mkdir -p $(dir $(UPDATE_RESULT));\
40-
python3 ../misc/acrn-config/board_config/board_cfg_gen.py --board $(BOARD_FILE) --scenario $(SCENARIO_FILE) > $(UPDATE_RESULT);\
40+
if [ "$(TARGET_DIR)" = "" ]; then \
41+
python3 ../misc/acrn-config/board_config/board_cfg_gen.py --board $(BOARD_FILE) --scenario $(SCENARIO_FILE) > $(UPDATE_RESULT);\
42+
else \
43+
python3 ../misc/acrn-config/board_config/board_cfg_gen.py --board $(BOARD_FILE) --scenario $(SCENARIO_FILE) --out $(TARGET_DIR) > $(UPDATE_RESULT);\
44+
fi;\
4145
cat $(UPDATE_RESULT);\
4246
if [ "`sed -n /successfully/p $(UPDATE_RESULT)`" = "" ]; then rm -f $(UPDATE_RESULT); exit 1; fi;\
43-
python3 ../misc/acrn-config/scenario_config/scenario_cfg_gen.py --board $(BOARD_FILE) --scenario $(SCENARIO_FILE) > $(UPDATE_RESULT);\
47+
if [ "$(TARGET_DIR)" = "" ]; then \
48+
python3 ../misc/acrn-config/scenario_config/scenario_cfg_gen.py --board $(BOARD_FILE) --scenario $(SCENARIO_FILE) > $(UPDATE_RESULT);\
49+
else \
50+
python3 ../misc/acrn-config/scenario_config/scenario_cfg_gen.py --board $(BOARD_FILE) --scenario $(SCENARIO_FILE) --out $(TARGET_DIR) > $(UPDATE_RESULT);\
51+
fi;\
4452
cat $(UPDATE_RESULT);\
4553
if [ "`sed -n /successfully/p $(UPDATE_RESULT)`" = "" ]; then rm -f $(UPDATE_RESULT); exit 1; fi;\
4654
echo "Import hypervisor Board/VM configuration from XMLs, configurations in source code has been overwritten!";\

hypervisor/scripts/makefile/kconfig.mk

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,18 @@ $(HV_OBJDIR)/$(HV_CONFIG_H): $(HV_OBJDIR)/$(HV_CONFIG)
7272
.PHONY: defconfig
7373
defconfig: $(KCONFIG_DEPS)
7474
@mkdir -p $(HV_OBJDIR)
75-
@BOARD=$(TARGET_BOARD) \
76-
python3 $(KCONFIG_DIR)/defconfig.py Kconfig \
77-
$(HV_OBJDIR)/$(HV_CONFIG)
75+
@if [ ! -f $(KCONFIG_FILE) ] && [ "$(CONFIG_XML_ENABLED)" != "true" ]; then \
76+
BOARD=$(TARGET_BOARD) python3 $(KCONFIG_DIR)/defconfig.py Kconfig $(HV_OBJDIR)/$(HV_CONFIG); \
77+
else \
78+
if [ "$(KCONFIG_FILE)" != "" ] && [ -f $(KCONFIG_FILE) ]; then \
79+
echo "Writing $(HV_OBJDIR)/$(HV_CONFIG) with $(KCONFIG_FILE)"; \
80+
cp $(KCONFIG_FILE) $(HV_OBJDIR)/$(HV_CONFIG); \
81+
elif [ "$(CONFIG_XML_ENABLED)" = "true" ] && [ "$(TARGET_DIR)" != "" ] && [ -d $(TARGET_DIR) ]; then \
82+
echo "Writing $(HV_OBJDIR)/$(HV_CONFIG) with $(TARGET_DIR)/$(BOARD).config"; \
83+
cp $(TARGET_DIR)/$(BOARD).config $(HV_OBJDIR)/$(HV_CONFIG); \
84+
fi; \
85+
python3 $(KCONFIG_DIR)/silentoldconfig.py Kconfig $(HV_OBJDIR)/$(HV_CONFIG) RELEASE=$(RELEASE); \
86+
fi
7887

7988
# Use silentoldconfig to forcefully update the current .config, or generate a
8089
# new one if no previous .config exists. This target can be used as a
@@ -98,7 +107,7 @@ savedefconfig: $(HV_OBJDIR)/$(HV_CONFIG)
98107

99108
$(eval $(call check_dep_exec,menuconfig,MENUCONFIG_DEPS))
100109
export KCONFIG_CONFIG := $(HV_OBJDIR)/$(HV_CONFIG)
101-
menuconfig: $(MENUCONFIG_DEPS) $(HV_OBJDIR)/$(HV_CONFIG)
110+
menuconfig: $(MENUCONFIG_DEPS) defconfig
102111
@python3 $(shell which menuconfig) Kconfig
103112

104113
CFLAGS += -include $(HV_OBJDIR)/$(HV_CONFIG_H)

0 commit comments

Comments
 (0)