util/kconfig: Uprev to Linux 5.17's kconfig

Another upstream refactoring, another local patch gone!

TEST=`util/abuild/abuild -C` output (build.h and build.conf) remains
the same

Change-Id: I0f99dcbd8ecc7256551f0a6e2c83c060cb1999b6
Signed-off-by: Patrick Georgi <patrick@coreboot.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/66046
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Elyes Haouas <ehaouas@noos.fr>
This commit is contained in:
Patrick Georgi 2022-10-28 01:00:26 +02:00 committed by Patrick Georgi
parent 4c9b9e9709
commit 7eb03cb657
13 changed files with 57 additions and 81 deletions

View File

@ -69,7 +69,7 @@ localyesconfig localmodconfig: $(obj)/conf
# deprecated for external use # deprecated for external use
simple-targets := oldconfig allnoconfig allyesconfig allmodconfig \ simple-targets := oldconfig allnoconfig allyesconfig allmodconfig \
alldefconfig randconfig listnewconfig olddefconfig syncconfig \ alldefconfig randconfig listnewconfig olddefconfig syncconfig \
helpnewconfig yes2modconfig mod2yesconfig helpnewconfig yes2modconfig mod2yesconfig mod2noconfig
PHONY += $(simple-targets) PHONY += $(simple-targets)
@ -134,6 +134,7 @@ help:
@echo ' randconfig - New config with random answer to all options' @echo ' randconfig - New config with random answer to all options'
@echo ' yes2modconfig - Change answers from yes to mod if possible' @echo ' yes2modconfig - Change answers from yes to mod if possible'
@echo ' mod2yesconfig - Change answers from mod to yes if possible' @echo ' mod2yesconfig - Change answers from mod to yes if possible'
@echo ' mod2noconfig - Change answers from mod to no if possible'
@echo ' listnewconfig - List new options' @echo ' listnewconfig - List new options'
@echo ' helpnewconfig - List new options and help text' @echo ' helpnewconfig - List new options and help text'
@echo ' olddefconfig - Same as oldconfig but sets new symbols to their' @echo ' olddefconfig - Same as oldconfig but sets new symbols to their'

View File

@ -37,6 +37,7 @@ enum input_mode {
olddefconfig, olddefconfig,
yes2modconfig, yes2modconfig,
mod2yesconfig, mod2yesconfig,
mod2noconfig,
}; };
static enum input_mode input_mode = oldaskconfig; static enum input_mode input_mode = oldaskconfig;
static int input_mode_opt; static int input_mode_opt;
@ -165,8 +166,6 @@ enum conf_def_mode {
def_default, def_default,
def_yes, def_yes,
def_mod, def_mod,
def_y2m,
def_m2y,
def_no, def_no,
def_random def_random
}; };
@ -304,12 +303,10 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode)
return has_changed; return has_changed;
} }
static void conf_rewrite_mod_or_yes(enum conf_def_mode mode) static void conf_rewrite_tristates(tristate old_val, tristate new_val)
{ {
struct symbol *sym; struct symbol *sym;
int i; int i;
tristate old_val = (mode == def_y2m) ? yes : mod;
tristate new_val = (mode == def_y2m) ? mod : yes;
for_all_symbols(i, sym) { for_all_symbols(i, sym) {
if (sym_get_type(sym) == S_TRISTATE && if (sym_get_type(sym) == S_TRISTATE &&
@ -687,6 +684,7 @@ static const struct option long_opts[] = {
{"olddefconfig", no_argument, &input_mode_opt, olddefconfig}, {"olddefconfig", no_argument, &input_mode_opt, olddefconfig},
{"yes2modconfig", no_argument, &input_mode_opt, yes2modconfig}, {"yes2modconfig", no_argument, &input_mode_opt, yes2modconfig},
{"mod2yesconfig", no_argument, &input_mode_opt, mod2yesconfig}, {"mod2yesconfig", no_argument, &input_mode_opt, mod2yesconfig},
{"mod2noconfig", no_argument, &input_mode_opt, mod2noconfig},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
@ -715,6 +713,7 @@ static void conf_usage(const char *progname)
printf(" --randconfig New config with random answer to all options\n"); printf(" --randconfig New config with random answer to all options\n");
printf(" --yes2modconfig Change answers from yes to mod if possible\n"); printf(" --yes2modconfig Change answers from yes to mod if possible\n");
printf(" --mod2yesconfig Change answers from mod to yes if possible\n"); printf(" --mod2yesconfig Change answers from mod to yes if possible\n");
printf(" --mod2noconfig Change answers from mod to no if possible\n");
printf(" (If none of the above is given, --oldaskconfig is the default)\n"); printf(" (If none of the above is given, --oldaskconfig is the default)\n");
} }
@ -791,6 +790,7 @@ int main(int ac, char **av)
case olddefconfig: case olddefconfig:
case yes2modconfig: case yes2modconfig:
case mod2yesconfig: case mod2yesconfig:
case mod2noconfig:
conf_read(NULL); conf_read(NULL);
break; break;
case allnoconfig: case allnoconfig:
@ -872,10 +872,13 @@ int main(int ac, char **av)
case savedefconfig: case savedefconfig:
break; break;
case yes2modconfig: case yes2modconfig:
conf_rewrite_mod_or_yes(def_y2m); conf_rewrite_tristates(yes, mod);
break; break;
case mod2yesconfig: case mod2yesconfig:
conf_rewrite_mod_or_yes(def_m2y); conf_rewrite_tristates(mod, yes);
break;
case mod2noconfig:
conf_rewrite_tristates(mod, no);
break; break;
case oldaskconfig: case oldaskconfig:
rootEntry = &rootmenu; rootEntry = &rootmenu;

View File

@ -230,13 +230,6 @@ static const char *conf_get_autoheader_name(void)
return name ? name : "include/generated/autoconf.h"; return name ? name : "include/generated/autoconf.h";
} }
static const char *conf_get_autobase_name(void)
{
char *name = getenv("KCONFIG_SPLITCONFIG");
return name ? name : "include/config/";
}
static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
{ {
char *p2; char *p2;
@ -265,6 +258,8 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
p, sym->name); p, sym->name);
return 1; return 1;
case S_STRING: case S_STRING:
/* No escaping for S_DEF_AUTO (include/config/auto.conf) */
if (def != S_DEF_AUTO) {
if (*p++ != '"') if (*p++ != '"')
break; break;
for (p2 = p; (p2 = strpbrk(p2, "\"\\")); p2++) { for (p2 = p; (p2 = strpbrk(p2, "\"\\")); p2++) {
@ -275,10 +270,10 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
memmove(p2, p2 + 1, strlen(p2)); memmove(p2, p2 + 1, strlen(p2));
} }
if (!p2) { if (!p2) {
if (def != S_DEF_AUTO)
conf_warning("invalid string found"); conf_warning("invalid string found");
return 1; return 1;
} }
}
/* fall through */ /* fall through */
case S_INT: case S_INT:
case S_HEX: case S_HEX:
@ -732,7 +727,7 @@ static void print_symbol_for_autoconf(FILE *fp, struct symbol *sym)
if (print_negatives) { if (print_negatives) {
out = OUTPUT_N; out = OUTPUT_N;
} }
__print_symbol(fp, sym, out, true); __print_symbol(fp, sym, out, false);
} }
void print_symbol_for_listconfig(struct symbol *sym) void print_symbol_for_listconfig(struct symbol *sym)
@ -1019,10 +1014,10 @@ static int conf_write_autoconf_cmd(const char *autoconf_name)
fprintf(out, "\n$(deps_config): ;\n"); fprintf(out, "\n$(deps_config): ;\n");
if (ferror(out)) /* error check for all fprintf() calls */ ret = ferror(out); /* error check for all fprintf() calls */
return -1;
fclose(out); fclose(out);
if (ret)
return -1;
if (rename(tmp, name)) { if (rename(tmp, name)) {
perror("rename"); perror("rename");
@ -1034,14 +1029,19 @@ static int conf_write_autoconf_cmd(const char *autoconf_name)
static int conf_touch_deps(void) static int conf_touch_deps(void)
{ {
const char *name; const char *name, *tmp;
struct symbol *sym; struct symbol *sym;
int res, i; int res, i;
strcpy(depfile_path, conf_get_autobase_name());
depfile_prefix_len = strlen(depfile_path);
name = conf_get_autoconfig_name(); name = conf_get_autoconfig_name();
tmp = strrchr(name, '/');
depfile_prefix_len = tmp ? tmp - name + 1 : 0;
if (depfile_prefix_len + 1 > sizeof(depfile_path))
return -1;
strncpy(depfile_path, name, depfile_prefix_len);
depfile_path[depfile_prefix_len] = 0;
conf_read_simple(name, S_DEF_AUTO); conf_read_simple(name, S_DEF_AUTO);
sym_calc_value(modules_sym); sym_calc_value(modules_sym);
@ -1134,10 +1134,10 @@ static int __conf_write_autoconf(const char *filename,
print_symbol(file, sym); print_symbol(file, sym);
/* check possible errors in conf_write_heading() and print_symbol() */ /* check possible errors in conf_write_heading() and print_symbol() */
if (ferror(file)) ret = ferror(file);
return -1;
fclose(file); fclose(file);
if (ret)
return -1;
if (rename(tmp, filename)) { if (rename(tmp, filename)) {
perror("rename"); perror("rename");

View File

@ -19,7 +19,7 @@ Index: kconfig/confdata.c
=================================================================== ===================================================================
--- kconfig.orig/confdata.c --- kconfig.orig/confdata.c
+++ kconfig/confdata.c +++ kconfig/confdata.c
@@ -428,6 +428,7 @@ load: @@ -430,6 +430,7 @@ load:
if (def == S_DEF_USER) { if (def == S_DEF_USER) {
sym = sym_find(line + 2 + strlen(CONFIG_)); sym = sym_find(line + 2 + strlen(CONFIG_));
if (!sym) { if (!sym) {
@ -27,7 +27,7 @@ Index: kconfig/confdata.c
conf_set_changed(true); conf_set_changed(true);
continue; continue;
} }
@@ -510,6 +511,13 @@ load: @@ -512,6 +513,13 @@ load:
} }
free(line); free(line);
fclose(in); fclose(in);

View File

@ -40,7 +40,7 @@ Index: kconfig/confdata.c
static void conf_default_message_callback(const char *s) static void conf_default_message_callback(const char *s)
{ {
printf("#\n# "); printf("#\n# ");
@@ -438,7 +448,7 @@ load: @@ -440,7 +450,7 @@ load:
sym->type = S_BOOLEAN; sym->type = S_BOOLEAN;
} }
if (sym->flags & def_flags) { if (sym->flags & def_flags) {
@ -49,7 +49,7 @@ Index: kconfig/confdata.c
} }
switch (sym->type) { switch (sym->type) {
case S_BOOLEAN: case S_BOOLEAN:
@@ -477,7 +487,7 @@ load: @@ -479,7 +489,7 @@ load:
} }
if (sym->flags & def_flags) { if (sym->flags & def_flags) {
@ -58,7 +58,7 @@ Index: kconfig/confdata.c
} }
if (conf_set_sym_val(sym, def, def_flags, p)) if (conf_set_sym_val(sym, def, def_flags, p))
continue; continue;
@@ -502,7 +512,7 @@ load: @@ -504,7 +514,7 @@ load:
break; break;
case yes: case yes:
if (cs->def[def].tri != no) if (cs->def[def].tri != no)

View File

@ -14,7 +14,7 @@ Index: kconfig/conf.c
=================================================================== ===================================================================
--- kconfig.orig/conf.c --- kconfig.orig/conf.c
+++ kconfig/conf.c +++ kconfig/conf.c
@@ -889,7 +889,7 @@ int main(int ac, char **av) @@ -892,7 +892,7 @@ int main(int ac, char **av)
if (input_mode == savedefconfig) { if (input_mode == savedefconfig) {
if (conf_write_defconfig(defconfig_file)) { if (conf_write_defconfig(defconfig_file)) {

View File

@ -24,7 +24,7 @@ Index: kconfig/confdata.c
=================================================================== ===================================================================
--- kconfig.orig/confdata.c --- kconfig.orig/confdata.c
+++ kconfig/confdata.c +++ kconfig/confdata.c
@@ -438,7 +438,9 @@ load: @@ -440,7 +440,9 @@ load:
if (def == S_DEF_USER) { if (def == S_DEF_USER) {
sym = sym_find(line + 2 + strlen(CONFIG_)); sym = sym_find(line + 2 + strlen(CONFIG_));
if (!sym) { if (!sym) {

View File

@ -36,7 +36,7 @@ Index: kconfig/conf.c
static void conf(struct menu *menu); static void conf(struct menu *menu);
static void check_conf(struct menu *menu); static void check_conf(struct menu *menu);
@@ -721,6 +723,7 @@ int main(int ac, char **av) @@ -720,6 +722,7 @@ int main(int ac, char **av)
const char *progname = av[0]; const char *progname = av[0];
int opt; int opt;
const char *name, *defconfig_file = NULL /* gcc uninit */; const char *name, *defconfig_file = NULL /* gcc uninit */;
@ -62,7 +62,7 @@ Index: kconfig/confdata.c
=================================================================== ===================================================================
--- kconfig.orig/confdata.c --- kconfig.orig/confdata.c
+++ kconfig/confdata.c +++ kconfig/confdata.c
@@ -528,11 +528,7 @@ load: @@ -530,11 +530,7 @@ load:
free(line); free(line);
fclose(in); fclose(in);

View File

@ -27,21 +27,21 @@ Index: kconfig/confdata.c
=================================================================== ===================================================================
--- kconfig.orig/confdata.c --- kconfig.orig/confdata.c
+++ kconfig/confdata.c +++ kconfig/confdata.c
@@ -720,7 +720,12 @@ static void print_symbol_for_dotconfig(F @@ -722,7 +722,12 @@ static void print_symbol_for_dotconfig(F
static void print_symbol_for_autoconf(FILE *fp, struct symbol *sym) static void print_symbol_for_autoconf(FILE *fp, struct symbol *sym)
{ {
- __print_symbol(fp, sym, OUTPUT_N_NONE, true); - __print_symbol(fp, sym, OUTPUT_N_NONE, false);
+ int print_negatives = getenv("KCONFIG_NEGATIVES") != NULL; + int print_negatives = getenv("KCONFIG_NEGATIVES") != NULL;
+ enum output_n out = OUTPUT_N_NONE; + enum output_n out = OUTPUT_N_NONE;
+ if (print_negatives) { + if (print_negatives) {
+ out = OUTPUT_N; + out = OUTPUT_N;
+ } + }
+ __print_symbol(fp, sym, out, true); + __print_symbol(fp, sym, out, false);
} }
void print_symbol_for_listconfig(struct symbol *sym) void print_symbol_for_listconfig(struct symbol *sym)
@@ -745,6 +750,10 @@ static void print_symbol_for_c(FILE *fp, @@ -747,6 +752,10 @@ static void print_symbol_for_c(FILE *fp,
case S_TRISTATE: case S_TRISTATE:
switch (*val) { switch (*val) {
case 'n': case 'n':
@ -52,7 +52,7 @@ Index: kconfig/confdata.c
return; return;
case 'm': case 'm':
sym_suffix = "_MODULE"; sym_suffix = "_MODULE";
@@ -756,6 +765,12 @@ static void print_symbol_for_c(FILE *fp, @@ -758,6 +767,12 @@ static void print_symbol_for_c(FILE *fp,
case S_HEX: case S_HEX:
if (val[0] != '0' || (val[1] != 'x' && val[1] != 'X')) if (val[0] != '0' || (val[1] != 'x' && val[1] != 'X'))
val_prefix = "0x"; val_prefix = "0x";
@ -65,7 +65,7 @@ Index: kconfig/confdata.c
break; break;
case S_STRING: case S_STRING:
escaped = escape_string_value(val); escaped = escape_string_value(val);
@@ -1106,8 +1121,9 @@ static int __conf_write_autoconf(const c @@ -1113,8 +1128,9 @@ static int __conf_write_autoconf(const c
conf_write_heading(file, comment_style); conf_write_heading(file, comment_style);

View File

@ -1,27 +0,0 @@
Index: kconfig/confdata.c
===================================================================
--- kconfig.orig/confdata.c
+++ kconfig/confdata.c
@@ -230,6 +230,13 @@ static const char *conf_get_autoheader_n
return name ? name : "include/generated/autoconf.h";
}
+static const char *conf_get_autobase_name(void)
+{
+ char *name = getenv("KCONFIG_SPLITCONFIG");
+
+ return name ? name : "include/config/";
+}
+
static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
{
char *p2;
@@ -1031,7 +1038,7 @@ static int conf_touch_deps(void)
struct symbol *sym;
int res, i;
- strcpy(depfile_path, "include/config/");
+ strcpy(depfile_path, conf_get_autobase_name());
depfile_prefix_len = strlen(depfile_path);
name = conf_get_autoconfig_name();

View File

@ -8,5 +8,4 @@
0008-kconfig-Add-wildcard-support-for-source.patch 0008-kconfig-Add-wildcard-support-for-source.patch
0009-util-kconfig-Allow-emitting-false-booleans-into-kconfig-output.patch 0009-util-kconfig-Allow-emitting-false-booleans-into-kconfig-output.patch
0010-reenable-source-in-choice.patch 0010-reenable-source-in-choice.patch
0011-remove-include-config-hardcodes.patch
0013-util-kconfig-detect-ncurses-on-FreeBSD.patch 0013-util-kconfig-detect-ncurses-on-FreeBSD.patch

View File

@ -141,7 +141,7 @@ static char *do_lineno(int argc, char *argv[])
static char *do_shell(int argc, char *argv[]) static char *do_shell(int argc, char *argv[])
{ {
FILE *p; FILE *p;
char buf[256]; char buf[4096];
char *cmd; char *cmd;
size_t nread; size_t nread;
int i; int i;

View File

@ -170,7 +170,7 @@ sub read_kconfig {
$source =~ s/\$\($env\)/$ENV{$env}/; $source =~ s/\$\($env\)/$ENV{$env}/;
} }
open(my $kinfile, '<', $source) || die "Can't open $kconfig"; open(my $kinfile, '<', $source) || die "Can't open $source";
while (<$kinfile>) { while (<$kinfile>) {
chomp; chomp;