Skip to content

Commit b9d54f4

Browse files
junjiemao1lijinxia
authored andcommitted
kconfig: support board-specific defconfig
The current defconfigs are BIOS-specific which makes it difficult to maintain multiple defconfigs for boards running the same BIOS. This patch re-organizes the defconfigs to be board-specific. A command line option BOARD is introduced to specify a board on which the current build targets at. The original PLATFORM is kept for backward compatibility which redirects to apl-mrb and nuc6cayh for sbl and uefi, respectively. The getting started guide is also updated accordingly. v1 -> v2: * Rewrite 'up2' to 'UP2'. Tracked-On: #1588 Signed-off-by: Junjie Mao <junjie.mao@intel.com> Reviewed-by: Anthony Xu <anthony.xu@intel.com>
1 parent 8bde372 commit b9d54f4

File tree

8 files changed

+77
-26
lines changed

8 files changed

+77
-26
lines changed

doc/getting-started/apl-nuc.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ partition. Follow these steps:
254254
255255
# systemctl enable weston@cl_sos
256256
# systemctl start weston@cl_sos
257-
257+
258258
#. Reboot and select "The ACRN Service OS" to boot, as shown below:
259259

260260

@@ -537,7 +537,7 @@ The build results are found in the ``build`` directory.
537537
.. note::
538538
if you wish to use a different target folder for the build
539539
artefacts, set the ``O`` (that is capital letter 'O') to the
540-
desired value. Example: ``make O=build-uefi PLATFORM=uefi``.
540+
desired value. Example: ``make O=build-nuc BOARD=nuc6cayh``.
541541

542542
Generating the documentation is decribed in details in the :ref:`acrn_doc`
543543
tutorial.
@@ -551,7 +551,7 @@ and are using it as the current working directory.
551551
.. code-block:: none
552552
553553
$ cd hypervisor
554-
$ make PLATFORM=uefi
554+
$ make BOARD=nuc6cayh
555555
556556
The build results are found in the ``build`` directory.
557557

@@ -578,8 +578,8 @@ Generate the hypervisor configurations
578578
======================================
579579

580580
The ACRN hypervisor leverages Kconfig to manage configurations, powered by
581-
Kconfiglib. A default configuration is generated based on the platform you have
582-
selected via the ``PLATFORM=`` command line parameter. You can make further
581+
Kconfiglib. A default configuration is generated based on the board you have
582+
selected via the ``BOARD=`` command line parameter. You can make further
583583
changes to that default configuration to adjust to your specific
584584
requirements.
585585

@@ -592,9 +592,9 @@ found under the target folder of your build.
592592
.. code-block:: none
593593
594594
$ cd hypervisor
595-
$ make defconfig PLATFORM=uefi
595+
$ make defconfig BOARD=nuc6cayh
596596
597-
The PLATFORM specified is used to select a defconfig under
597+
The BOARD specified is used to select a defconfig under
598598
``arch/x86/configs/``. The other command-line based options (e.g. ``RELEASE``)
599599
take no effects when generating a defconfig.
600600

@@ -611,7 +611,7 @@ the hypervisor using the updated ``.config``.
611611
.. code-block:: none
612612
613613
$ cd hypervisor
614-
$ make defconfig PLATFORM=uefi
614+
$ make defconfig BOARD=nuc6cayh
615615
$ make menuconfig # Modify the configurations per your needs
616616
$ make # Build the hypervisor with the new .config
617617
@@ -628,21 +628,21 @@ Create a new default configuration
628628
==================================
629629

630630
Currently the ACRN hypervisor looks for default configurations under
631-
``hypervisor/arch/x86/configs/<PLATFORM>.config``, where ``<PLATFORM>`` is the
631+
``hypervisor/arch/x86/configs/<BOARD>.config``, where ``<BOARD>`` is the
632632
specified platform. The following steps allow you to create a defconfig for
633633
another platform based on a current one.
634634

635635
.. code-block:: none
636636
637637
$ cd hypervisor
638-
$ make defconfig PLATFORM=uefi
638+
$ make defconfig BOARD=nuc6cayh
639639
$ make menuconfig # Modify the configurations
640640
$ make savedefconfig # The minimized config reside at build/defconfig
641641
$ cp build/defconfig arch/x86/configs/xxx.config
642642
643643
Then you can re-use that configuration by passing the name (``xxx`` in the
644-
example above) to 'PLATFORM=':
644+
example above) to 'BOARD=':
645645

646646
.. code-block:: none
647647
648-
$ make defconfig PLATFORM=xxx
648+
$ make defconfig BOARD=xxx

hypervisor/arch/x86/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ config PLATFORM
4545
default "uefi" if PLATFORM_UEFI
4646
default "sbl" if PLATFORM_SBL
4747

48+
config BOARD
49+
string "Target board"
50+
help
51+
The target board this build runs on top of.
52+
53+
config DEFCONFIG_LIST
54+
string
55+
option defconfig_list
56+
default "arch/x86/configs/$BOARD.config"
57+
4858
config RELEASE
4959
bool "Release build"
5060
default n
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
CONFIG_BOARD="apl-mrb"
12
# CONFIG_PLATFORM_UEFI is not set
23
CONFIG_PLATFORM_SBL=y
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nuc6cayh.config
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_BOARD="NUC6CAYH"
2+
CONFIG_PLATFORM_UEFI=y
3+
# CONFIG_PLATFORM_SBL is not set
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
CONFIG_BOARD="UP2"
12
CONFIG_PLATFORM_UEFI=y
23
# CONFIG_PLATFORM_SBL is not set

hypervisor/scripts/kconfig/kconfig.mk

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,27 @@ endif
3030
endif
3131

3232
-include $(HV_OBJDIR)/$(HV_CONFIG_MK)
33-
$(eval $(call override_config,PLATFORM,sbl))
33+
34+
# Backward-compatibility for PLATFORM=(sbl|uefi)
35+
# * PLATFORM=sbl is equivalent to BOARD=apl-mrb
36+
# * PLATFORM=uefi is equivalent to BOARD=apl-nuc (i.e. NUC6CAYH)
37+
ifndef BOARD
38+
ifeq ($(PLATFORM),sbl)
39+
BOARD=apl-mrb
40+
else ifeq ($(PLATFORM),uefi)
41+
BOARD=apl-nuc
42+
endif
43+
endif
44+
45+
$(eval $(call override_config,BOARD,apl-mrb))
3446
$(eval $(call override_config,RELEASE,n))
3547

48+
ifdef BOARD
49+
TARGET_BOARD=$(BOARD)
50+
else
51+
TARGET_BOARD=$(CONFIG_BOARD)
52+
endif
53+
3654
$(eval $(call check_dep_exec,python3,KCONFIG_DEPS))
3755
$(eval $(call check_dep_py3lib,kconfiglib,KCONFIG_DEPS))
3856

@@ -59,8 +77,8 @@ $(HV_OBJDIR)/$(HV_CONFIG_H): $(HV_OBJDIR)/$(HV_CONFIG)
5977
.PHONY: defconfig
6078
defconfig: $(KCONFIG_DEPS)
6179
@mkdir -p $(HV_OBJDIR)
62-
@python3 $(KCONFIG_DIR)/defconfig.py Kconfig \
63-
arch/x86/configs/$(CONFIG_PLATFORM).config \
80+
@BOARD=$(TARGET_BOARD) \
81+
python3 $(KCONFIG_DIR)/defconfig.py Kconfig \
6482
$(HV_OBJDIR)/$(HV_CONFIG)
6583

6684
# Use silentoldconfig to forcefully update the current .config, or generate a
@@ -73,9 +91,9 @@ defconfig: $(KCONFIG_DEPS)
7391
.PHONY: oldconfig
7492
oldconfig: $(KCONFIG_DEPS)
7593
@mkdir -p $(HV_OBJDIR)
76-
@python3 $(KCONFIG_DIR)/silentoldconfig.py Kconfig \
94+
@BOARD=$(TARGET_BOARD) \
95+
python3 $(KCONFIG_DIR)/silentoldconfig.py Kconfig \
7796
$(HV_OBJDIR)/$(HV_CONFIG) \
78-
PLATFORM_$(shell echo $(PLATFORM) | tr a-z A-Z)=y \
7997
RELEASE=$(RELEASE)
8098

8199
# Minimize the current .config. This target can be used to generate a defconfig

scripts/kconfig/defconfig.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,45 @@
1212
import kconfiglib
1313

1414
def usage():
15-
sys.stdout.write("%s: <Kconfig file> <defconfig> <path to .config>\n" % sys.argv[0])
15+
sys.stdout.write("%s: <Kconfig file> <path to .config>\n" % sys.argv[0])
1616

1717
def main():
18-
if len(sys.argv) < 4:
18+
if len(sys.argv) < 3:
1919
usage()
2020
sys.exit(1)
2121

22+
target_board = os.environ['BOARD']
23+
2224
kconfig_path = sys.argv[1]
2325
if not os.path.isfile(kconfig_path):
2426
sys.stderr.write("Cannot find file %s\n" % kconfig_path)
2527
sys.exit(1)
2628

27-
defconfig_path = sys.argv[2]
28-
if not os.path.isfile(defconfig_path):
29-
sys.stderr.write("Cannot find file %s\n" % defconfig_path)
29+
kconfig = kconfiglib.Kconfig(kconfig_path)
30+
defconfig_path = kconfig.defconfig_filename
31+
if not defconfig_path or not os.path.isfile(defconfig_path):
32+
sys.stderr.write("No defconfig found for board %s.\n" % target_board)
3033
sys.exit(1)
3134

32-
sys.stdout.write("Default configuration based on %s.\n" % defconfig_path)
33-
kconfig = kconfiglib.Kconfig(kconfig_path)
3435
kconfig.load_config(defconfig_path)
35-
kconfig.write_config(sys.argv[3])
36-
sys.stdout.write("Configuration written to %s.\n" % sys.argv[3])
36+
37+
config_path = sys.argv[2]
38+
if os.path.isfile(config_path):
39+
# No need to change .config if it is already equivalent to the specified
40+
# default.
41+
kconfig_current = kconfiglib.Kconfig(kconfig_path)
42+
kconfig_current.load_config(config_path)
43+
same_config = True
44+
for sym in kconfig_current.syms:
45+
if kconfig_current.syms[sym].str_value != kconfig.syms[sym].str_value:
46+
same_config = False
47+
break
48+
if same_config:
49+
sys.exit(0)
50+
51+
sys.stdout.write("Default configuration based on %s.\n" % defconfig_path)
52+
kconfig.write_config(config_path)
53+
sys.stdout.write("Configuration written to %s.\n" % config_path)
3754

3855
if __name__ == "__main__":
3956
main()

0 commit comments

Comments
 (0)