[PATCH 20/32] kconfig: Refactor code into separate writer functions
Simon Glass
sjg at chromium.org
Tue Jan 31 16:26:50 CET 2023
Separate out the code that writes the Makefile and headers so we can
reuse these functions when writing out SPL files.
This makes no functional change.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
scripts/kconfig/confdata.c | 65 ++++++++++++++++++++++----------------
scripts/kconfig/expr.h | 9 ++++++
scripts/kconfig/lkc.h | 9 ++++++
3 files changed, 56 insertions(+), 27 deletions(-)
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index d587b10d7f8..73bf43bcb95 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -509,27 +509,18 @@ int conf_read(const char *name)
return 0;
}
-/*
- * Kconfig configuration printer
- *
- * This printer is used when generating the resulting configuration after
- * kconfig invocation and `defconfig' files. Unset symbol might be omitted by
- * passing a non-NULL argument to the printer.
- *
- */
-static void
-kconfig_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
+/* Print a symbol for a Makefile */
+static void print_makefile_sym(FILE *fp, const char *name,
+ enum symbol_type type, const char *value,
+ bool skip_unset)
{
-
- switch (sym->type) {
+ switch (type) {
case S_BOOLEAN:
case S_TRISTATE:
if (*value == 'n') {
- bool skip_unset = (arg != NULL);
-
if (!skip_unset)
fprintf(fp, "# %s%s is not set\n",
- CONFIG_, sym->name);
+ CONFIG_, name);
return;
}
break;
@@ -537,7 +528,21 @@ kconfig_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
break;
}
- fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, value);
+ fprintf(fp, "%s%s=%s\n", CONFIG_, name, value);
+}
+
+/*
+ * Kconfig configuration printer
+ *
+ * This printer is used when generating the resulting configuration after
+ * kconfig invocation and `defconfig' files. Unset symbol might be omitted by
+ * passing a non-NULL argument to the printer.
+ *
+ */
+static void
+kconfig_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
+{
+ print_makefile_sym(fp, sym->name, sym->type, value, arg != NULL);
}
static void
@@ -566,16 +571,12 @@ static struct conf_printer kconfig_printer_cb =
.print_comment = kconfig_print_comment,
};
-/*
- * Header printer
- *
- * This printer is used when generating the `include/generated/autoconf.h' file.
- */
-static void
-header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
+/* Print a symbol for a header file */
+static void print_header_sym(FILE *fp, const char *name, enum symbol_type type,
+ const char *value)
{
- switch (sym->type) {
+ switch (type) {
case S_BOOLEAN:
case S_TRISTATE: {
const char *suffix = "";
@@ -588,7 +589,7 @@ header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
/* fall through */
default:
fprintf(fp, "#define %s%s%s 1\n",
- CONFIG_, sym->name, suffix);
+ CONFIG_, name, suffix);
}
break;
}
@@ -598,18 +599,28 @@ header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
if (value[0] != '0' || (value[1] != 'x' && value[1] != 'X'))
prefix = "0x";
fprintf(fp, "#define %s%s %s%s\n",
- CONFIG_, sym->name, prefix, value);
+ CONFIG_, name, prefix, value);
break;
}
case S_STRING:
case S_INT:
fprintf(fp, "#define %s%s %s\n",
- CONFIG_, sym->name, value);
+ CONFIG_, name, value);
break;
default:
break;
}
+}
+/*
+ * Header printer
+ *
+ * This printer is used when generating the `include/generated/autoconf.h' file.
+ */
+static void
+header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
+{
+ print_header_sym(fp, sym->name, sym->type, value);
}
static void
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index 7c329e17900..656c87fb4f3 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -158,6 +158,15 @@ struct symbol {
/* Set symbol to y if allnoconfig; used for symbols that hide others */
#define SYMBOL_ALLNOCONFIG_Y 0x200000
+/* U-Boot: Marks an SPL symbol */
+#define SYMBOL_SPL 0x400000
+
+/* U-Boot: Marks a non-SPL symbol that also has an SPL version */
+#define SYMBOL_HAS_SPL 0x800000
+
+/* U-Boot: Marks an-SPL symbol that does not have a non-SPL version */
+#define SYMBOL_SPL_ONLY 0x1000000
+
#define SYMBOL_MAXLENGTH 256
#define SYMBOL_HASHSIZE 9973
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 9eb7c837cd8..dec03cc927a 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -71,6 +71,15 @@ void sym_add_change_count(int count);
bool conf_set_all_new_symbols(enum conf_def_mode mode);
void set_all_choice_values(struct symbol *csym);
+/**
+ * conf_mark_spl_symbols() - Mark SPL symbols
+ *
+ * Symbols which don't start with SPL_ (TPL_, etc.) but have an SPL version
+ * should be marked with the SYMBOL_SPL flag, so we know to avoid writing them
+ * in the SPL autoconf.h files.
+ */
+void conf_mark_spl_symbols(void);
+
/* confdata.c and expr.c */
static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out)
{
--
2.39.1.456.gfc5497dd1b-goog
More information about the U-Boot
mailing list