Skip to content

Commit 3774244

Browse files
jsun26intelwenlingz
authored andcommitted
Makefile: parameters check for board and scenario
When user use make parameters to specify BOARD and SCENARIO, there might be some conflict because parameter of KCONFIG_FILE/BOARD_FILE/SCENARIO_FILE also includes BOARD/SCENARIO info. To simplify, we only alow below valid usages: 1. make <target> 2. make <target> KCONFIG_FILE=xxx 3. make <target> BOARD=xxx SCENARIO=xxx 4. make <target> BOARD_FILE=xxx SCENARIO_FILE=xxx 5. make <target> KCONFIG_FILE=xxx BOARD_FILE=xxx SCENARIO_FILE=xxx Especially for case 1 that no any parameters are specified: a. If hypervisor/build/.config file which generated by "make menuconfig" exist, the .config file will be loaded as KCONFIG_FILE: i.e. equal: make <target> KCONFIG_FILE=hypervisor/build/.config b. If hypervisor/build/.config file does not exist, the default BOARD/SCENARIO will be loaded: i.e. equal: make <target> BOARD=$(BOARD) SCENARIO=$(SCENARIO) Tracked-On: #4517 Signed-off-by: Victor Sun <victor.sun@intel.com>
1 parent 82e93b7 commit 3774244

File tree

3 files changed

+113
-68
lines changed

3 files changed

+113
-68
lines changed

Makefile

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

6+
# BOARD/SCENARIO/BOARD_FILE/SCENARIO_FILE/KCONFIG_FILE parameters sanity check:
7+
#
8+
# Only below usages are VALID: (target = all | hypervisor)
9+
# 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
14+
#
15+
# Especially for case 1 that no any parameters are specified:
16+
# a. If hypervisor/build/.config file which generated by "make menuconfig" exist,
17+
# the .config file will be loaded as KCONFIG_FILE:
18+
# i.e. equal: make <target> KCONFIG_FILE=hypervisor/build/.config
19+
#
20+
# b. If hypervisor/build/.config file does not exist,
21+
# the default BOARD/SCENARIO will be loaded:
22+
# i.e. equal: make <target> BOARD=$(BOARD) SCENARIO=$(SCENARIO)
23+
#
24+
# The grep process did not handle corner case when '#' is manually put right after config value as comments,
25+
# i.e. it will be failed in the case of "CONFIG_XXX=y # some comments here "
26+
627
ifneq ($(KCONFIG_FILE),)
728
ifneq ($(KCONFIG_FILE), $(wildcard $(KCONFIG_FILE)))
829
$(error KCONFIG_FILE: $(KCONFIG_FILE) does not exist)
@@ -12,6 +33,50 @@ else
1233
override KCONFIG_FILE := $(T)/hypervisor/build/.config
1334
endif
1435

36+
ifneq ($(BOARD)$(SCENARIO),)
37+
ifneq ($(BOARD_FILE)$(SCENARIO_FILE),)
38+
$(error BOARD/SCENARIO parameter could not coexist with BOARD_FILE/SCENARIO_FILE)
39+
endif
40+
endif
41+
42+
ifneq ($(BOARD_FILE)$(SCENARIO_FILE),)
43+
ifneq ($(BOARD_FILE), $(wildcard $(BOARD_FILE)))
44+
$(error BOARD_FILE: $(BOARD_FILE) does not exist)
45+
endif
46+
ifneq ($(SCENARIO_FILE), $(wildcard $(SCENARIO_FILE)))
47+
$(error SCENARIO_FILE: $(SCENARIO_FILE) does not exist)
48+
endif
49+
50+
override BOARD_FILE := $(realpath $(BOARD_FILE))
51+
override SCENARIO_FILE := $(realpath $(SCENARIO_FILE))
52+
endif
53+
54+
ifeq ($(KCONFIG_FILE), $(wildcard $(KCONFIG_FILE)))
55+
ifneq ($(BOARD)$(SCENARIO),)
56+
$(error BOARD/SCENARIO parameter could not coexist with KCONFIG_FILE)
57+
endif
58+
59+
BOARD_IN_KCONFIG := $(shell grep CONFIG_BOARD= $(KCONFIG_FILE) | grep -v '\#' | awk -F '"' '{print $$2}')
60+
ifeq ($(BOARD_IN_KCONFIG),)
61+
$(error no BOARD info in KCONFIG_FILE: $(KCONFIG_FILE))
62+
endif
63+
64+
SCENARIO_IN_KCONFIG := $(shell grep -E "SDC=y|SDC2=y|INDUSTRY=y|LOGICAL_PARTITION=y|HYBRID=y" \
65+
$(KCONFIG_FILE) | grep -v '\#' | awk -F "=" '{print $$1}' | cut -d '_' -f 2- | tr A-Z a-z)
66+
ifeq ($(SCENARIO_IN_KCONFIG),)
67+
$(error no SCENARIO info in KCONFIG_FILE: $(KCONFIG_FILE))
68+
endif
69+
70+
override BOARD := $(BOARD_IN_KCONFIG)
71+
override SCENARIO := $(SCENARIO_IN_KCONFIG)
72+
73+
RELEASE := $(shell grep CONFIG_RELEASE=y $(KCONFIG_FILE) | grep -v '\#')
74+
ifneq ($(RELEASE),)
75+
override RELEASE := 1
76+
endif
77+
78+
endif
79+
1580
BOARD ?= kbl-nuc-i7
1681

1782
ifneq (,$(filter $(BOARD),apl-mrb))
@@ -35,13 +100,6 @@ BUILD_TAG ?=
35100
GENED_ACPI_INFO_HEADER = $(T)/hypervisor/arch/x86/configs/$(BOARD)/$(BOARD)_acpi_info.h
36101
HV_CFG_LOG = $(HV_OUT)/cfg.log
37102

38-
ifneq ($(BOARD_FILE),)
39-
override BOARD_FILE := $(shell if [ -f $(BOARD_FILE) ]; then realpath $(BOARD_FILE); fi)
40-
endif
41-
ifneq ($(SCENARIO_FILE),)
42-
override SCENARIO_FILE := $(shell if [ -f $(SCENARIO_FILE) ]; then realpath $(SCENARIO_FILE); fi)
43-
endif
44-
45103
export TOOLS_OUT BOARD SCENARIO FIRMWARE RELEASE
46104

47105
.PHONY: all hypervisor devicemodel tools doc
@@ -54,40 +112,8 @@ else ifeq ($(BOARD), kbl-nuc-i7)
54112
override BOARD := nuc7i7dnb
55113
endif
56114

57-
#BOARD and SCENARIO definition priority:
58-
# If we do menuconfig in advance, the menuconfig will define
59-
# BOARD
60-
# SCENARIO
61-
# else if we have board/scenario file avaiable, BOARD and SCENARIO will be
62-
# extracted from files.
63-
# else if make comand has BORAD/SCENARIO parameters, BOARD and SCENARIO will
64-
# be gotten from parameters
65-
# else
66-
# default value defined in this make file will be used
67-
#
68-
69115
include $(T)/hypervisor/scripts/makefile/cfg_update.mk
70116

71-
ifeq ($(KCONFIG_FILE), $(wildcard $(KCONFIG_FILE)))
72-
BOARD_IN_KCONFIG := $(shell grep CONFIG_BOARD= $(KCONFIG_FILE) | awk -F '"' '{print $$2}')
73-
SCENARIO_IN_KCONFIG := $(shell grep -E "SDC=y|SDC2=y|INDUSTRY=y|LOGICAL_PARTITION=y|HYBRID=y" \
74-
$(KCONFIG_FILE) | awk -F "=" '{print $$1}' | cut -d '_' -f 2- | tr A-Z a-z)
75-
76-
RELEASE := $(shell grep CONFIG_RELEASE=y $(KCONFIG_FILE))
77-
ifneq ($(RELEASE),)
78-
override RELEASE := 1
79-
endif
80-
81-
ifneq ($(BOARD_IN_KCONFIG),$(BOARD))
82-
override BOARD := $(BOARD_IN_KCONFIG)
83-
endif
84-
85-
ifneq ($(SCENARIO_IN_KCONFIG),$(SCENARIO))
86-
override SCENARIO := $(SCENARIO_IN_KCONFIG)
87-
endif
88-
89-
endif
90-
91117
#help functions to build acrn and install acrn/acrn symbols
92118
define build_acrn
93119
$(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT)-$(1)/$(2) BOARD=$(2) FIRMWARE=$(1) SCENARIO=$(4) RELEASE=$(RELEASE) clean

hypervisor/Makefile

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# ACRN Hypervisor
2+
# acrn-hypervisor/hypervisor/Makefile
33
#
44

55
include ../VERSION
@@ -50,17 +50,30 @@ include scripts/makefile/deps.mk
5050

5151
include scripts/makefile/kconfig.mk
5252

53-
#initialize scenarios name
53+
#initialize BOARD if it is not specified
54+
ifeq ($(BOARD),)
55+
override BOARD := $(CONFIG_BOARD)
56+
endif
57+
5458
ifeq ($(CONFIG_SDC),y)
55-
SCENARIO_NAME := sdc
59+
KCONFIG_SCENARIO := sdc
5660
else ifeq ($(CONFIG_SDC2),y)
57-
SCENARIO_NAME := sdc2
61+
KCONFIG_SCENARIO := sdc2
5862
else ifeq ($(CONFIG_LOGICAL_PARTITION),y)
59-
SCENARIO_NAME := logical_partition
63+
KCONFIG_SCENARIO := logical_partition
6064
else ifeq ($(CONFIG_INDUSTRY),y)
61-
SCENARIO_NAME := industry
65+
KCONFIG_SCENARIO := industry
6266
else ifeq ($(CONFIG_HYBRID),y)
63-
SCENARIO_NAME := hybrid
67+
KCONFIG_SCENARIO := hybrid
68+
endif
69+
70+
#initialize SCENARIO if it is not specified
71+
ifeq ($(SCENARIO),)
72+
ifeq ($(KCONFIG_SCENARIO),)
73+
override SCENARIO := sdc
74+
else
75+
override SCENARIO := $(KCONFIG_SCENARIO)
76+
endif
6477
endif
6578

6679
LD_IN_TOOL = scripts/genld.sh
@@ -153,8 +166,8 @@ INCLUDE_PATH += include/hw
153166
INCLUDE_PATH += boot/include
154167
INCLUDE_PATH += boot/include/guest
155168
INCLUDE_PATH += $(HV_OBJDIR)/include
156-
INCLUDE_PATH += arch/x86/configs/$(CONFIG_BOARD)
157-
INCLUDE_PATH += scenarios/$(SCENARIO_NAME)
169+
INCLUDE_PATH += arch/x86/configs/$(BOARD)
170+
INCLUDE_PATH += scenarios/$(SCENARIO)
158171

159172
CC ?= gcc
160173
AS ?= as
@@ -240,10 +253,10 @@ HW_C_SRCS += common/sched_bvt.c
240253
endif
241254
HW_C_SRCS += hw/pci.c
242255
HW_C_SRCS += arch/x86/configs/vm_config.c
243-
HW_C_SRCS += arch/x86/configs/$(CONFIG_BOARD)/board.c
244-
HW_C_SRCS += scenarios/$(SCENARIO_NAME)/vm_configurations.c
245-
ifneq (,$(wildcard scenarios/$(SCENARIO_NAME)/pci_dev.c))
246-
HW_C_SRCS += scenarios/$(SCENARIO_NAME)/pci_dev.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
247260
endif
248261
HW_C_SRCS += boot/acpi_base.c
249262
HW_C_SRCS += boot/cmdline.c
@@ -357,8 +370,8 @@ VERSION := $(HV_OBJDIR)/include/version.h
357370

358371
# Create platform_acpi_info.h
359372
TEMPLATE_ACPI_INFO_HEADER := arch/x86/configs/platform_acpi_info.h
360-
BOARDTEMPLATE_ACPI_INFO_HEADER := arch/x86/configs/$(CONFIG_BOARD)/platform_acpi_info.h
361-
SOURCE_ACPI_INFO_HEADER := arch/x86/configs/$(CONFIG_BOARD)/$(CONFIG_BOARD)_acpi_info.h
373+
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
362375
TARGET_ACPI_INFO_HEADER := $(HV_OBJDIR)/include/platform_acpi_info.h
363376

364377
$(TARGET_ACPI_INFO_HEADER): $(HV_OBJDIR)/$(HV_CONFIG)
@@ -393,11 +406,11 @@ endif
393406
all: pre_build $(HV_OBJDIR)/$(HV_FILE).32.out $(HV_OBJDIR)/$(HV_FILE).bin
394407

395408
install: $(HV_OBJDIR)/$(HV_FILE).32.out
396-
install -D $(HV_OBJDIR)/$(HV_FILE).32.out $(DESTDIR)/usr/lib/acrn/$(HV_FILE).$(BOARD).$(FIRMWARE).$(SCENARIO_NAME).32.out
409+
install -D $(HV_OBJDIR)/$(HV_FILE).32.out $(DESTDIR)/usr/lib/acrn/$(HV_FILE).$(BOARD).$(FIRMWARE).$(SCENARIO).32.out
397410

398411
install-debug: $(HV_OBJDIR)/$(HV_FILE).map $(HV_OBJDIR)/$(HV_FILE).out
399-
install -D $(HV_OBJDIR)/$(HV_FILE).out $(DESTDIR)/usr/lib/acrn/$(HV_FILE).$(BOARD).$(FIRMWARE).$(SCENARIO_NAME).out
400-
install -D $(HV_OBJDIR)/$(HV_FILE).map $(DESTDIR)/usr/lib/acrn/$(HV_FILE).$(BOARD).$(FIRMWARE).$(SCENARIO_NAME).map
412+
install -D $(HV_OBJDIR)/$(HV_FILE).out $(DESTDIR)/usr/lib/acrn/$(HV_FILE).$(BOARD).$(FIRMWARE).$(SCENARIO).out
413+
install -D $(HV_OBJDIR)/$(HV_FILE).map $(DESTDIR)/usr/lib/acrn/$(HV_FILE).$(BOARD).$(FIRMWARE).$(SCENARIO).map
401414

402415
.PHONY: pre_build
403416
pre_build: $(PRE_BUILD_OBJS)
@@ -485,10 +498,7 @@ distclean:
485498

486499
PHONY: (VERSION)
487500
$(VERSION):
488-
@echo "SCENARIO <$(SCENARIO_NAME)> for BOARD <$(BOARD)> is specified."
489-
@if [ "$(CONFIG_XML_ENABLED)" = "true" ] && [ "$(SCENARIO_NAME)" != "$(SCENARIO_IN_XML)" ]; then \
490-
echo "SCENARIO in XML <$(SCENARIO_IN_XML)> does not match SCENARIO in Kconfig <$(SCENARIO_NAME)> !" ; exit 1; \
491-
fi
501+
@echo "SCENARIO <$(SCENARIO)> for BOARD <$(BOARD)> is specified."
492502
touch $(VERSION)
493503
@COMMIT=`git rev-parse --verify --short HEAD 2>/dev/null`;\
494504
DIRTY=`git diff-index --name-only HEAD`;\

hypervisor/scripts/makefile/cfg_update.mk

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,27 @@ ifneq ($$(BOARD_IN_XML),)
1212
endif
1313
endif
1414

15-
ifeq ($$(CONFIG_XML_ENABLED),true)
16-
override BOARD := $$(BOARD_IN_XML)
17-
override SCENARIO := $$(SCENARIO_IN_XML)
18-
endif
19-
20-
2115
endef
2216

23-
ifeq ($(CONFIG_XML_ENALBED),)
17+
ifeq ($(CONFIG_XML_ENABLED),)
2418
$(eval $(call check_xml_enabled,$(BOARD_FILE),$(SCENARIO_FILE)))
2519
endif
2620

21+
ifeq ($(CONFIG_XML_ENABLED),true)
22+
ifneq ($(BOARD_IN_KCONFIG),)
23+
ifneq ($(BOARD_IN_XML),$(BOARD_IN_KCONFIG))
24+
$(error BOARD $(BOARD_IN_XML) in $(BOARD_FILE) does not match BOARD $(BOARD_IN_KCONFIG) in $(KCONFIG_FILE))
25+
endif
26+
endif
27+
ifneq ($(SCENARIO_IN_KCONFIG),)
28+
ifneq ($(SCENARIO_IN_XML),$(SCENARIO_IN_KCONFIG))
29+
$(error SCENARIO $(SCENARIO_IN_XML) in $(SCENARIO_FILE) does not match SCENARIO $(SCENARIO_IN_KCONFIG) in $(KCONFIG_FILE))
30+
endif
31+
endif
32+
override BOARD := $(BOARD_IN_XML)
33+
override SCENARIO := $(SCENARIO_IN_XML)
34+
endif
35+
2736
update_config:
2837
ifeq ($(CONFIG_XML_ENABLED),true)
2938
@if [ ! -f $(UPDATE_RESULT) ]; then \

0 commit comments

Comments
 (0)