[coreboot-gerrit] New patch to review for coreboot: coreinfo: Use IS_ENABLED() to query Kconfig variables

Stefan Reinauer (stefan.reinauer@coreboot.org) gerrit at coreboot.org
Tue Jun 30 01:47:27 CEST 2015


Stefan Reinauer (stefan.reinauer at coreboot.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10713

-gerrit

commit a2b4075ec6ad66f49a43ef1d269b53beeb4103bc
Author: Stefan Reinauer <stefan.reinauer at coreboot.org>
Date:   Mon Jun 29 16:08:39 2015 -0700

    coreinfo: Use IS_ENABLED() to query Kconfig variables
    
    This will make the code work with the different styles
    of Kconfig (emit unset bools vs don't emit unset bools)
    
    Roughly, the patch does this, and a little bit of fixing up:
    
    perl -pi -e 's,ifdef (CONFIG_.+?)\b,if IS_ENABLED\($1\),g' `find . -name *.[ch]`
    perl -pi -e 's,ifndef (CONFIG_.+?)\b,if !IS_ENABLED\($1\),g' `find . -name *.[ch]`
    
    Change-Id: Ia461a33541f58ff39e984119c44ece7e6c05608a
    Signed-off-by: Stefan Reinauer <stefan.reinauer at coreboot.org>
---
 payloads/coreinfo/Makefile           |  2 +-
 payloads/coreinfo/bootlog_module.c   |  2 +-
 payloads/coreinfo/cbfs_module.c      |  2 +-
 payloads/coreinfo/coreboot_module.c  |  2 +-
 payloads/coreinfo/coreinfo.c         | 26 +++++++++++++-------------
 payloads/coreinfo/cpuinfo_module.c   |  2 +-
 payloads/coreinfo/kconfig.h          | 21 +++++++++++++++++++++
 payloads/coreinfo/lar_module.c       |  2 +-
 payloads/coreinfo/multiboot_module.c |  2 +-
 payloads/coreinfo/nvram_module.c     |  2 +-
 payloads/coreinfo/pci_module.c       |  2 +-
 payloads/coreinfo/ramdump_module.c   |  2 +-
 12 files changed, 44 insertions(+), 23 deletions(-)

diff --git a/payloads/coreinfo/Makefile b/payloads/coreinfo/Makefile
index a0e82d9..669c46e 100644
--- a/payloads/coreinfo/Makefile
+++ b/payloads/coreinfo/Makefile
@@ -53,7 +53,7 @@ HAVE_LIBPAYLOAD := $(wildcard $(LIBPAYLOAD_DIR)/libpayload/lib/libpayload.a)
 LIB_CONFIG ?= defconfig
 OBJCOPY ?= objcopy
 
-INCLUDES = -I$(obj)
+INCLUDES = -I$(obj) -include kconfig.h
 CFLAGS := -Wall -Werror -Os $(INCLUDES)
 OBJECTS = cpuinfo_module.o cpuid.S.o pci_module.o coreboot_module.o \
 	  nvram_module.o bootlog_module.o ramdump_module.o lar_module.o \
diff --git a/payloads/coreinfo/bootlog_module.c b/payloads/coreinfo/bootlog_module.c
index ca5b040..791446b 100644
--- a/payloads/coreinfo/bootlog_module.c
+++ b/payloads/coreinfo/bootlog_module.c
@@ -19,7 +19,7 @@
 
 #include "coreinfo.h"
 
-#ifdef CONFIG_MODULE_BOOTLOG
+#if IS_ENABLED(CONFIG_MODULE_BOOTLOG)
 
 #define CONFIG_COREBOOT_PRINTK_BUFFER_ADDR 0x90000
 #define CONFIG_COREBOOT_PRINTK_BUFFER_SIZE 65536
diff --git a/payloads/coreinfo/cbfs_module.c b/payloads/coreinfo/cbfs_module.c
index 98b6160..2e6db28 100644
--- a/payloads/coreinfo/cbfs_module.c
+++ b/payloads/coreinfo/cbfs_module.c
@@ -20,7 +20,7 @@
 #include "coreinfo.h"
 #include "endian.h"
 
-#ifdef CONFIG_MODULE_CBFS
+#if IS_ENABLED(CONFIG_MODULE_CBFS)
 
 #define ALIGN(_v, _a) (((_v) + ((_a) - 1)) & ~((_a) - 1))
 
diff --git a/payloads/coreinfo/coreboot_module.c b/payloads/coreinfo/coreboot_module.c
index f232d6b..00b6faf 100644
--- a/payloads/coreinfo/coreboot_module.c
+++ b/payloads/coreinfo/coreboot_module.c
@@ -20,7 +20,7 @@
 #include "coreinfo.h"
 #include <coreboot_tables.h>
 
-#ifdef CONFIG_MODULE_COREBOOT
+#if IS_ENABLED(CONFIG_MODULE_COREBOOT)
 
 #define MAX_MEMORY_COUNT 5
 
diff --git a/payloads/coreinfo/coreinfo.c b/payloads/coreinfo/coreinfo.c
index 5766be4..5bd1068 100644
--- a/payloads/coreinfo/coreinfo.c
+++ b/payloads/coreinfo/coreinfo.c
@@ -35,34 +35,34 @@ extern struct coreinfo_module lar_module;
 extern struct coreinfo_module cbfs_module;
 
 struct coreinfo_module *system_modules[] = {
-#ifdef CONFIG_MODULE_CPUINFO
+#if IS_ENABLED(CONFIG_MODULE_CPUINFO)
 	&cpuinfo_module,
 #endif
-#ifdef CONFIG_MODULE_PCI
+#if IS_ENABLED(CONFIG_MODULE_PCI)
 	&pci_module,
 #endif
-#ifdef CONFIG_MODULE_NVRAM
+#if IS_ENABLED(CONFIG_MODULE_NVRAM)
 	&nvram_module,
 #endif
-#ifdef CONFIG_MODULE_RAMDUMP
+#if IS_ENABLED(CONFIG_MODULE_RAMDUMP)
 	&ramdump_module,
 #endif
 };
 
 struct coreinfo_module *firmware_modules[] = {
-#ifdef CONFIG_MODULE_COREBOOT
+#if IS_ENABLED(CONFIG_MODULE_COREBOOT)
 	&coreboot_module,
 #endif
-#ifdef CONFIG_MODULE_MULTIBOOT
+#if IS_ENABLED(CONFIG_MODULE_MULTIBOOT)
 	&multiboot_module,
 #endif
-#ifdef CONFIG_MODULE_BOOTLOG
+#if IS_ENABLED(CONFIG_MODULE_BOOTLOG)
 	&bootlog_module,
 #endif
-#ifdef CONFIG_MODULE_LAR
+#if IS_ENABLED(CONFIG_MODULE_LAR)
 	&lar_module,
 #endif
-#ifdef CONFIG_MODULE_CBFS
+#if IS_ENABLED(CONFIG_MODULE_CBFS)
 	&cbfs_module,
 #endif
 };
@@ -121,7 +121,7 @@ static void print_submenu(struct coreinfo_cat *cat)
 	mvwprintw(menuwin, 0, 0, menu);
 }
 
-#ifdef CONFIG_SHOW_DATE_TIME
+#if IS_ENABLED(CONFIG_SHOW_DATE_TIME)
 static void print_time_and_date(void)
 {
 	struct tm tm;
@@ -156,7 +156,7 @@ static void print_menu(void)
 
 	mvwprintw(menuwin, 1, 0, menu);
 
-#ifdef CONFIG_SHOW_DATE_TIME
+#if IS_ENABLED(CONFIG_SHOW_DATE_TIME)
 	print_time_and_date();
 #endif
 }
@@ -234,7 +234,7 @@ static void loop(void)
 	halfdelay(10);
 
 	while (1) {
-#ifdef CONFIG_SHOW_DATE_TIME
+#if IS_ENABLED(CONFIG_SHOW_DATE_TIME)
 		print_time_and_date();
 		wrefresh(menuwin);
 #endif
@@ -271,7 +271,7 @@ int main(void)
 {
 	int i, j;
 
-#if defined(CONFIG_USB)
+#if IS_ENABLED(CONFIG_LP_USB)
 	usb_initialize();
 #endif
 
diff --git a/payloads/coreinfo/cpuinfo_module.c b/payloads/coreinfo/cpuinfo_module.c
index cd42eb3..a209141 100644
--- a/payloads/coreinfo/cpuinfo_module.c
+++ b/payloads/coreinfo/cpuinfo_module.c
@@ -22,7 +22,7 @@
 
 #include "coreinfo.h"
 
-#ifdef CONFIG_MODULE_CPUINFO
+#if IS_ENABLED(CONFIG_MODULE_CPUINFO)
 #include <arch/rdtsc.h>
 
 #define VENDOR_INTEL 0x756e6547
diff --git a/payloads/coreinfo/kconfig.h b/payloads/coreinfo/kconfig.h
new file mode 100644
index 0000000..73106e9
--- /dev/null
+++ b/payloads/coreinfo/kconfig.h
@@ -0,0 +1,21 @@
+#ifndef __KCONFIG_H__
+#define __KCONFIG_H__
+
+#include <config.h>
+
+/*
+ * Getting something that works in C and CPP for an arg that may or may
+ * not be defined is tricky.  Here, if we have "#define CONFIG_BOOGER 1"
+ * we match on the placeholder define, insert the "0," for arg1 and generate
+ * the triplet (0, 1, 0).  Then the last step cherry picks the 2nd arg (a one).
+ * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
+ * the last step cherry picks the 2nd arg, we get a zero.
+ */
+#define __ARG_PLACEHOLDER_1 0,
+#define config_enabled(cfg) _config_enabled(cfg)
+#define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value)
+#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0, 0)
+#define ___config_enabled(__ignored, val, ...) val
+
+#define IS_ENABLED(option) config_enabled(option)
+#endif
diff --git a/payloads/coreinfo/lar_module.c b/payloads/coreinfo/lar_module.c
index 8404efa..e50d98f 100644
--- a/payloads/coreinfo/lar_module.c
+++ b/payloads/coreinfo/lar_module.c
@@ -19,7 +19,7 @@
 
 #include "coreinfo.h"
 
-#ifdef CONFIG_MODULE_LAR
+#if IS_ENABLED(CONFIG_MODULE_LAR)
 
 static struct LAR *lar;
 static int lcount, selected;
diff --git a/payloads/coreinfo/multiboot_module.c b/payloads/coreinfo/multiboot_module.c
index 86206c2..225b401 100644
--- a/payloads/coreinfo/multiboot_module.c
+++ b/payloads/coreinfo/multiboot_module.c
@@ -20,7 +20,7 @@
 #include <multiboot_tables.h>
 #include "coreinfo.h"
 
-#ifdef CONFIG_MODULE_MULTIBOOT
+#if IS_ENABLED(CONFIG_MODULE_MULTIBOOT)
 
 #define MAX_MEMORY_COUNT  10
 
diff --git a/payloads/coreinfo/nvram_module.c b/payloads/coreinfo/nvram_module.c
index 50cc3e6..8d9eefe 100644
--- a/payloads/coreinfo/nvram_module.c
+++ b/payloads/coreinfo/nvram_module.c
@@ -19,7 +19,7 @@
 
 #include "coreinfo.h"
 
-#ifdef CONFIG_MODULE_NVRAM
+#if IS_ENABLED(CONFIG_MODULE_NVRAM)
 
 /**
  * Dump 256 bytes of NVRAM.
diff --git a/payloads/coreinfo/pci_module.c b/payloads/coreinfo/pci_module.c
index b864d1a..d3d037c 100644
--- a/payloads/coreinfo/pci_module.c
+++ b/payloads/coreinfo/pci_module.c
@@ -22,7 +22,7 @@
 #include <libpayload.h>
 #include "coreinfo.h"
 
-#ifdef CONFIG_MODULE_PCI
+#if IS_ENABLED(CONFIG_MODULE_PCI)
 
 struct pci_devices {
 	pcidev_t device;
diff --git a/payloads/coreinfo/ramdump_module.c b/payloads/coreinfo/ramdump_module.c
index f1ac043..6a691b3 100644
--- a/payloads/coreinfo/ramdump_module.c
+++ b/payloads/coreinfo/ramdump_module.c
@@ -19,7 +19,7 @@
 
 #include "coreinfo.h"
 
-#ifdef CONFIG_MODULE_RAMDUMP
+#if IS_ENABLED(CONFIG_MODULE_RAMDUMP)
 
 static s64 cursor = 0;
 static s64 cursor_max = (1 * 1024 * 1024 * 1024); /* Max. 1 GB RAM for now. */



More information about the coreboot-gerrit mailing list