util/kconfig: Uprev to Linux 5.16's kconfig

Linux 5.16 saw a significant rewrite in the boolean handling which
reduces our change set. On the other hand, it's all new code.

Comparing the config.build and config.h files generated by
`util/abuild/abuild -C`, only a few lines of comment in the header
changed.

Change-Id: I52984e15a48236ddf228707aec85e90f71aa4382
Signed-off-by: Patrick Georgi <patrick@coreboot.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/66045
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 14cedd97a5
commit 4c9b9e9709
17 changed files with 364 additions and 567 deletions

View File

@ -648,19 +648,8 @@ static void check_conf(struct menu *menu)
switch (input_mode) { switch (input_mode) {
case listnewconfig: case listnewconfig:
if (sym->name) { if (sym->name)
const char *str; print_symbol_for_listconfig(sym);
if (sym->type == S_STRING) {
str = sym_get_string_value(sym);
str = sym_escape_string_value(str);
printf("%s%s=%s\n", CONFIG_, sym->name, str);
free((void *)str);
} else {
str = sym_get_string_value(sym);
printf("%s%s=%s\n", CONFIG_, sym->name, str);
}
}
break; break;
case helpnewconfig: case helpnewconfig:
printf("-----\n"); printf("-----\n");

View File

@ -11,6 +11,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -129,45 +130,22 @@ static size_t depfile_prefix_len;
/* touch depfile for symbol 'name' */ /* touch depfile for symbol 'name' */
static int conf_touch_dep(const char *name) static int conf_touch_dep(const char *name)
{ {
int fd, ret; int fd;
char *d;
/* check overflow: prefix + name + '\0' must fit in buffer. */ /* check overflow: prefix + name + '\0' must fit in buffer. */
if (depfile_prefix_len + strlen(name) + 1 > sizeof(depfile_path)) if (depfile_prefix_len + strlen(name) + 1 > sizeof(depfile_path))
return -1; return -1;
d = depfile_path + depfile_prefix_len; strcpy(depfile_path + depfile_prefix_len, name);
strcpy(d, name);
/* Assume directory path already exists. */
fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644); fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd == -1) { if (fd == -1)
if (errno != ENOENT) return -1;
return -1;
ret = make_parent_dir(depfile_path);
if (ret)
return ret;
/* Try it again. */
fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd == -1)
return -1;
}
close(fd); close(fd);
return 0; return 0;
} }
struct conf_printer {
void (*print_symbol)(FILE *, struct symbol *, const char *, void *);
void (*print_comment)(FILE *, const char *, void *);
};
#ifdef __MINGW32__
#define mkdir(_n,_p) mkdir((_n))
#endif
static void conf_warning(const char *fmt, ...) static void conf_warning(const char *fmt, ...)
__attribute__ ((format (printf, 1, 2))); __attribute__ ((format (printf, 1, 2)));
@ -177,6 +155,10 @@ static void conf_message(const char *fmt, ...)
static const char *conf_filename; static const char *conf_filename;
static int conf_lineno, conf_warnings; static int conf_lineno, conf_warnings;
#ifdef __MINGW32__
#define mkdir(_n,_p) mkdir((_n))
#endif
static void conf_warning(const char *fmt, ...) static void conf_warning(const char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -241,6 +223,13 @@ static const char *conf_get_autoconfig_name(void)
return name ? name : "include/config/auto.conf"; return name ? name : "include/config/auto.conf";
} }
static const char *conf_get_autoheader_name(void)
{
char *name = getenv("KCONFIG_AUTOHEADER");
return name ? name : "include/generated/autoconf.h";
}
static const char *conf_get_autobase_name(void) static const char *conf_get_autobase_name(void)
{ {
char *name = getenv("KCONFIG_SPLITCONFIG"); char *name = getenv("KCONFIG_SPLITCONFIG");
@ -621,186 +610,186 @@ int conf_read(const char *name)
return 0; return 0;
} }
struct comment_style {
const char *decoration;
const char *prefix;
const char *postfix;
};
static const struct comment_style comment_style_pound = {
.decoration = "#",
.prefix = "#",
.postfix = "#",
};
static const struct comment_style comment_style_c = {
.decoration = " *",
.prefix = "/*",
.postfix = " */",
};
static void conf_write_heading(FILE *fp, const struct comment_style *cs)
{
fprintf(fp, "%s\n", cs->prefix);
fprintf(fp, "%s Automatically generated file; DO NOT EDIT.\n",
cs->decoration);
fprintf(fp, "%s %s\n", cs->decoration, rootmenu.prompt->text);
fprintf(fp, "%s\n", cs->postfix);
}
/* The returned pointer must be freed on the caller side */
static char *escape_string_value(const char *in)
{
const char *p;
char *out;
size_t len;
len = strlen(in) + strlen("\"\"") + 1;
p = in;
while (1) {
p += strcspn(p, "\"\\");
if (p[0] == '\0')
break;
len++;
p++;
}
out = xmalloc(len);
out[0] = '\0';
strcat(out, "\"");
p = in;
while (1) {
len = strcspn(p, "\"\\");
strncat(out, p, len);
p += len;
if (p[0] == '\0')
break;
strcat(out, "\\");
strncat(out, p++, 1);
}
strcat(out, "\"");
return out;
}
/* /*
* Kconfig configuration printer * Kconfig configuration printer
* *
* This printer is used when generating the resulting configuration after * This printer is used when generating the resulting configuration after
* kconfig invocation and `defconfig' files. Unset symbol might be omitted by * kconfig invocation and `defconfig' files. Unset symbol might be omitted by
* passing a non-NULL argument to the printer. * passing a non-NULL argument to the printer.
*
*/ */
static void enum output_n { OUTPUT_N, OUTPUT_N_AS_UNSET, OUTPUT_N_NONE };
kconfig_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
static void __print_symbol(FILE *fp, struct symbol *sym, enum output_n output_n,
bool escape_string)
{ {
const char *val;
char *escaped = NULL;
if (sym->type == S_UNKNOWN)
return;
val = sym_get_string_value(sym);
if ((sym->type == S_BOOLEAN || sym->type == S_TRISTATE) &&
output_n != OUTPUT_N && *val == 'n') {
if (output_n == OUTPUT_N_AS_UNSET)
fprintf(fp, "# %s%s is not set\n", CONFIG_, sym->name);
return;
}
if (sym->type == S_STRING && escape_string) {
escaped = escape_string_value(val);
val = escaped;
}
fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, val);
free(escaped);
}
static void print_symbol_for_dotconfig(FILE *fp, struct symbol *sym)
{
__print_symbol(fp, sym, OUTPUT_N_AS_UNSET, true);
}
static void print_symbol_for_autoconf(FILE *fp, struct symbol *sym)
{
int print_negatives = getenv("KCONFIG_NEGATIVES") != NULL;
enum output_n out = OUTPUT_N_NONE;
if (print_negatives) {
out = OUTPUT_N;
}
__print_symbol(fp, sym, out, true);
}
void print_symbol_for_listconfig(struct symbol *sym)
{
__print_symbol(stdout, sym, OUTPUT_N, true);
}
static void print_symbol_for_c(FILE *fp, struct symbol *sym)
{
const char *val;
const char *sym_suffix = "";
const char *val_prefix = "";
char *escaped = NULL;
if (sym->type == S_UNKNOWN)
return;
val = sym_get_string_value(sym);
switch (sym->type) { switch (sym->type) {
case S_BOOLEAN: case S_BOOLEAN:
case S_TRISTATE: case S_TRISTATE:
if (*value == 'n') { switch (*val) {
bool skip_unset = (arg != NULL);
if (!skip_unset)
fprintf(fp, "# %s%s is not set\n",
CONFIG_, sym->name);
return;
}
break;
default:
break;
}
fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, value);
}
static void
kconfig_print_comment(FILE *fp, const char *value, void *arg)
{
const char *p = value;
size_t l;
for (;;) {
l = strcspn(p, "\n");
fprintf(fp, "#");
if (l) {
fprintf(fp, " ");
xfwrite(p, l, 1, fp);
p += l;
}
fprintf(fp, "\n");
if (*p++ == '\0')
break;
}
}
static struct conf_printer kconfig_printer_cb =
{
.print_symbol = kconfig_print_symbol,
.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)
{
switch (sym->type) {
case S_BOOLEAN:
case S_TRISTATE: {
const char *suffix = "";
switch (*value) {
case 'n': case 'n':
if (getenv("KCONFIG_NEGATIVES") != NULL) if (getenv("KCONFIG_NEGATIVES") != NULL) {
fprintf(fp, "#define %s%s%s 0\n", val = "0";
CONFIG_, sym->name, suffix); break;
break; }
return;
case 'm': case 'm':
suffix = "_MODULE"; sym_suffix = "_MODULE";
/* fall through */ /* fall through */
default: default:
fprintf(fp, "#define %s%s%s 1\n", val = "1";
CONFIG_, sym->name, suffix);
} }
break; break;
} case S_HEX:
case S_HEX: { if (val[0] != '0' || (val[1] != 'x' && val[1] != 'X'))
const char *prefix = ""; val_prefix = "0x";
if (value[0] != '0' || (value[1] != 'x' && value[1] != 'X'))
prefix = "0x";
if (value[0] == '\0') {
/*
* prefix is reset to remain closer to the older
* coreboot patch. No need to keep this once kconfig
* is fully upreved
*/
prefix = "";
value = "0";
}
fprintf(fp, "#define %s%s %s%s\n",
CONFIG_, sym->name, prefix, value);
break;
}
case S_STRING:
if (value[0] == '\0')
break;
if (!(sym->flags & SYMBOL_WRITE))
break;
/* fall through */ /* fall through */
case S_INT: case S_INT:
fprintf(fp, "#define %s%s %s\n", if (val[0] == '\0') {
CONFIG_, sym->name, value[0]?value:"0"); val = "0";
break; val_prefix = "";
default:
break;
}
}
static void
header_print_comment(FILE *fp, const char *value, void *arg)
{
const char *p = value;
size_t l;
fprintf(fp, "/*\n");
for (;;) {
l = strcspn(p, "\n");
fprintf(fp, " *");
if (l) {
fprintf(fp, " ");
xfwrite(p, l, 1, fp);
p += l;
} }
fprintf(fp, "\n");
if (*p++ == '\0')
break;
}
fprintf(fp, " */\n");
}
static struct conf_printer header_printer_cb =
{
.print_symbol = header_print_symbol,
.print_comment = header_print_comment,
};
static void conf_write_symbol(FILE *fp, struct symbol *sym,
struct conf_printer *printer, void *printer_arg)
{
const char *str;
switch (sym->type) {
case S_UNKNOWN:
break; break;
case S_STRING: case S_STRING:
str = sym_get_string_value(sym); escaped = escape_string_value(val);
str = sym_escape_string_value(str); val = escaped;
printer->print_symbol(fp, sym, str, printer_arg);
free((void *)str);
break;
default: default:
str = sym_get_string_value(sym); break;
printer->print_symbol(fp, sym, str, printer_arg);
} }
}
static void fprintf(fp, "#define %s%s%s %s%s\n", CONFIG_, sym->name, sym_suffix,
conf_write_heading(FILE *fp, struct conf_printer *printer, void *printer_arg) val_prefix, val);
{
char buf[256];
snprintf(buf, sizeof(buf), free(escaped);
"\n"
"Automatically generated file; DO NOT EDIT.\n"
"%s\n",
rootmenu.prompt->text);
printer->print_comment(fp, buf, printer_arg);
} }
/* /*
@ -859,7 +848,7 @@ int conf_write_defconfig(const char *filename)
goto next_menu; goto next_menu;
} }
} }
conf_write_symbol(out, sym, &kconfig_printer_cb, NULL); print_symbol_for_dotconfig(out, sym);
} }
next_menu: next_menu:
if (menu->list != NULL) { if (menu->list != NULL) {
@ -880,16 +869,6 @@ next_menu:
return 0; return 0;
} }
static int conf_mktemp(const char *path, char *tmpfile)
{
if (snprintf(tmpfile, PATH_MAX, "%s.tmp.XXXXXX", path) >= PATH_MAX) {
errno = EOVERFLOW;
return -1;
}
return mkstemp(tmpfile);
}
int conf_write(const char *name) int conf_write(const char *name)
{ {
FILE *out; FILE *out;
@ -929,7 +908,7 @@ int conf_write(const char *name)
if (!out) if (!out)
return 1; return 1;
conf_write_heading(out, &kconfig_printer_cb, NULL); conf_write_heading(out, &comment_style_pound);
if (!conf_get_changed()) if (!conf_get_changed())
sym_clear_all_valid(); sym_clear_all_valid();
@ -956,7 +935,7 @@ int conf_write(const char *name)
need_newline = false; need_newline = false;
} }
sym->flags |= SYMBOL_WRITTEN; sym->flags |= SYMBOL_WRITTEN;
conf_write_symbol(out, sym, &kconfig_printer_cb, NULL); print_symbol_for_dotconfig(out, sym);
} }
next: next:
@ -1006,37 +985,50 @@ next:
} }
/* write a dependency file as used by kbuild to track dependencies */ /* write a dependency file as used by kbuild to track dependencies */
static int conf_write_dep(const char *name) static int conf_write_autoconf_cmd(const char *autoconf_name)
{ {
char name[PATH_MAX], tmp[PATH_MAX];
struct file *file; struct file *file;
FILE *out; FILE *out;
int ret;
ret = snprintf(name, sizeof(name), "%s.cmd", autoconf_name);
if (ret >= sizeof(name)) /* check truncation */
return -1;
if (make_parent_dir(name)) if (make_parent_dir(name))
return 1; return -1;
char filename[PATH_MAX];
int fd = conf_mktemp(name, filename);
if (fd == -1)
return 1;
out = fdopen(fd, "w"); ret = snprintf(tmp, sizeof(tmp), "%s.cmd.tmp", autoconf_name);
if (!out) if (ret >= sizeof(tmp)) /* check truncation */
return 1; return -1;
fprintf(out, "deps_config := \\\n");
for (file = file_list; file; file = file->next) { out = fopen(tmp, "w");
if (file->next) if (!out) {
fprintf(out, "\t%s \\\n", file->name); perror("fopen");
else return -1;
fprintf(out, "\t%s\n", file->name);
} }
fprintf(out, "\n%s: \\\n"
"\t$(deps_config)\n\n", conf_get_autoconfig_name());
env_write_dep(out, conf_get_autoconfig_name()); fprintf(out, "deps_config := \\\n");
for (file = file_list; file; file = file->next)
fprintf(out, "\t%s \\\n", file->name);
fprintf(out, "\n%s: $(deps_config)\n\n", autoconf_name);
env_write_dep(out, autoconf_name);
fprintf(out, "\n$(deps_config): ;\n"); fprintf(out, "\n$(deps_config): ;\n");
if (ferror(out)) /* error check for all fprintf() calls */
return -1;
fclose(out); fclose(out);
rename(filename, name); if (rename(tmp, name)) {
perror("rename");
return -1;
}
return 0; return 0;
} }
@ -1112,77 +1104,84 @@ static int conf_touch_deps(void)
return 0; return 0;
} }
static int __conf_write_autoconf(const char *filename,
void (*print_symbol)(FILE *, struct symbol *),
const struct comment_style *comment_style)
{
char tmp[PATH_MAX];
FILE *file;
struct symbol *sym;
int ret, i;
if (make_parent_dir(filename))
return -1;
ret = snprintf(tmp, sizeof(tmp), "%s.tmp", filename);
if (ret >= sizeof(tmp)) /* check truncation */
return -1;
file = fopen(tmp, "w");
if (!file) {
perror("fopen");
return -1;
}
conf_write_heading(file, comment_style);
int print_negatives = getenv("KCONFIG_NEGATIVES") != NULL;
for_all_symbols(i, sym)
if (((sym->flags & SYMBOL_WRITE) || (print_negatives && sym->type != S_STRING)) && sym->name)
print_symbol(file, sym);
/* check possible errors in conf_write_heading() and print_symbol() */
if (ferror(file))
return -1;
fclose(file);
if (rename(tmp, filename)) {
perror("rename");
return -1;
}
return 0;
}
int conf_write_autoconf(int overwrite) int conf_write_autoconf(int overwrite)
{ {
struct symbol *sym; struct symbol *sym;
const char *name;
const char *autoconf_name = conf_get_autoconfig_name(); const char *autoconf_name = conf_get_autoconfig_name();
FILE *out, *out_h; int ret, i;
int i;
int print_negatives = getenv("KCONFIG_NEGATIVES") != NULL;
if (!overwrite && is_present(autoconf_name)) if (!overwrite && is_present(autoconf_name))
return 0; return 0;
char autoconfcmd_path[PATH_MAX]; ret = conf_write_autoconf_cmd(autoconf_name);
snprintf(autoconfcmd_path, sizeof(autoconfcmd_path), "%s%s", if (ret)
conf_get_autobase_name(), "auto.conf.cmd"); return -1;
conf_write_dep(autoconfcmd_path);
if (conf_touch_deps()) if (conf_touch_deps())
return 1; return 1;
if (make_parent_dir(autoconf_name)) for_all_symbols(i, sym)
return 1;
char filename[PATH_MAX];
int fd = conf_mktemp(autoconf_name, filename);
if (fd == -1)
return 1;
out = fdopen(fd, "w");
if (!out)
return 1;
name = getenv("KCONFIG_AUTOHEADER");
if (!name)
name = "include/generated/autoconf.h";
if (make_parent_dir(name))
return 1;
char filename_h[PATH_MAX];
int fd_h = conf_mktemp(name, filename_h);
if (fd_h == -1)
return 1;
out_h = fdopen(fd_h, "w");
if (!out_h) {
fclose(out);
return 1;
}
conf_write_heading(out, &kconfig_printer_cb, NULL);
conf_write_heading(out_h, &header_printer_cb, NULL);
for_all_symbols(i, sym) {
sym_calc_value(sym); sym_calc_value(sym);
if (!(sym->flags & SYMBOL_WRITE) && !print_negatives)
continue;
if (!sym->name)
continue;
/* write symbols to auto.conf and autoconf.h */ ret = __conf_write_autoconf(conf_get_autoheader_name(),
conf_write_symbol(out, sym, &kconfig_printer_cb, print_negatives?NULL:(void *)1); print_symbol_for_c,
conf_write_symbol(out_h, sym, &header_printer_cb, NULL); &comment_style_c);
} if (ret)
fclose(out); return ret;
fclose(out_h);
if (rename(filename_h, name))
return 1;
/* /*
* This must be the last step, kbuild has a dependency on auto.conf * Create include/config/auto.conf. This must be the last step because
* and this marks the successful completion of the previous steps. * Kbuild has a dependency on auto.conf and this marks the successful
* completion of the previous steps.
*/ */
if (rename(filename, autoconf_name)) ret = __conf_write_autoconf(conf_get_autoconfig_name(),
return 1; print_symbol_for_autoconf,
&comment_style_pound);
if (ret)
return ret;
return 0; return 0;
} }

View File

@ -85,8 +85,7 @@ static void warn_ignored_character(char chr)
n [A-Za-z0-9_-] n [A-Za-z0-9_-]
%% %%
int str = 0; char open_quote = 0;
int ts, i;
#.* /* ignore comment */ #.* /* ignore comment */
[ \t]* /* whitespaces */ [ \t]* /* whitespaces */
@ -135,7 +134,7 @@ n [A-Za-z0-9_-]
":=" return T_COLON_EQUAL; ":=" return T_COLON_EQUAL;
"+=" return T_PLUS_EQUAL; "+=" return T_PLUS_EQUAL;
\"|\' { \"|\' {
str = yytext[0]; open_quote = yytext[0];
new_string(); new_string();
BEGIN(STRING); BEGIN(STRING);
} }
@ -172,7 +171,7 @@ n [A-Za-z0-9_-]
append_string(yytext + 1, yyleng - 1); append_string(yytext + 1, yyleng - 1);
} }
\'|\" { \'|\" {
if (str == yytext[0]) { if (open_quote == yytext[0]) {
BEGIN(INITIAL); BEGIN(INITIAL);
yylval.string = text; yylval.string = text;
return T_WORD_QUOTE; return T_WORD_QUOTE;
@ -197,6 +196,8 @@ n [A-Za-z0-9_-]
<HELP>{ <HELP>{
[ \t]+ { [ \t]+ {
int ts, i;
ts = 0; ts = 0;
for (i = 0; i < yyleng; i++) { for (i = 0; i < yyleng; i++) {
if (yytext[i] == '\t') if (yytext[i] == '\t')

View File

@ -18,7 +18,7 @@ extern struct symbol * symbol_hash[SYMBOL_HASHSIZE];
struct symbol * sym_lookup(const char *name, int flags); struct symbol * sym_lookup(const char *name, int flags);
struct symbol * sym_find(const char *name); struct symbol * sym_find(const char *name);
const char * sym_escape_string_value(const char *in); void print_symbol_for_listconfig(struct symbol *sym);
struct symbol ** sym_re_search(const char *pattern); struct symbol ** sym_re_search(const char *pattern);
const char * sym_type_name(enum symbol_type type); const char * sym_type_name(enum symbol_type type);
void sym_calc_value(struct symbol *sym); void sym_calc_value(struct symbol *sym);

View File

@ -728,7 +728,7 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
get_dep_str(r, prop->visible.expr, " Visible if: "); get_dep_str(r, prop->visible.expr, " Visible if: ");
menu = prop->menu->parent; menu = prop->menu->parent;
for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) { for (i = 0; menu && i < 8; menu = menu->parent) {
bool accessible = menu_is_visible(menu); bool accessible = menu_is_visible(menu);
submenu[i++] = menu; submenu[i++] = menu;
@ -758,21 +758,24 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
list_add_tail(&jump->entries, head); list_add_tail(&jump->entries, head);
} }
if (i > 0) { str_printf(r, " Location:\n");
str_printf(r, " Location:\n"); for (j = 4; --i >= 0; j += 2) {
for (j = 4; --i >= 0; j += 2) { menu = submenu[i];
menu = submenu[i]; if (jump && menu == location)
if (jump && menu == location) jump->offset = strlen(r->s);
jump->offset = strlen(r->s);
str_printf(r, "%*c-> %s", j, ' ', if (menu == &rootmenu)
menu_get_prompt(menu)); /* The real rootmenu prompt is ugly */
if (menu->sym) { str_printf(r, "%*cMain menu", j, ' ');
str_printf(r, " (%s [=%s])", menu->sym->name ? else
menu->sym->name : "<choice>", str_printf(r, "%*c-> %s", j, ' ', menu_get_prompt(menu));
sym_get_string_value(menu->sym));
} if (menu->sym) {
str_append(r, "\n"); str_printf(r, " (%s [=%s])", menu->sym->name ?
menu->sym->name : "<choice>",
sym_get_string_value(menu->sym));
} }
str_append(r, "\n");
} }
} }

View File

@ -19,7 +19,7 @@ Index: kconfig/confdata.c
=================================================================== ===================================================================
--- kconfig.orig/confdata.c --- kconfig.orig/confdata.c
+++ kconfig/confdata.c +++ kconfig/confdata.c
@@ -439,6 +439,7 @@ load: @@ -428,6 +428,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;
} }
@@ -521,6 +522,13 @@ load: @@ -510,6 +511,13 @@ load:
} }
free(line); free(line);
fclose(in); fclose(in);

View File

@ -23,7 +23,7 @@ Index: kconfig/confdata.c
=================================================================== ===================================================================
--- kconfig.orig/confdata.c --- kconfig.orig/confdata.c
+++ kconfig/confdata.c +++ kconfig/confdata.c
@@ -184,6 +184,16 @@ static void conf_warning(const char *fmt @@ -166,6 +166,16 @@ static void conf_warning(const char *fmt
conf_warnings++; conf_warnings++;
} }
@ -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# ");
@@ -449,7 +459,7 @@ load: @@ -438,7 +448,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:
@@ -488,7 +498,7 @@ load: @@ -477,7 +487,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;
@@ -513,7 +523,7 @@ load: @@ -502,7 +512,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
@@ -900,7 +900,7 @@ int main(int ac, char **av) @@ -889,7 +889,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
@@ -449,7 +449,9 @@ load: @@ -438,7 +438,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

@ -15,14 +15,14 @@ Index: kconfig/confdata.c
=================================================================== ===================================================================
--- kconfig.orig/confdata.c --- kconfig.orig/confdata.c
+++ kconfig/confdata.c +++ kconfig/confdata.c
@@ -164,6 +164,10 @@ struct conf_printer { @@ -155,6 +155,10 @@ static void conf_message(const char *fmt
void (*print_comment)(FILE *, const char *, void *); static const char *conf_filename;
}; static int conf_lineno, conf_warnings;
+#ifdef __MINGW32__ +#ifdef __MINGW32__
+#define mkdir(_n,_p) mkdir((_n)) +#define mkdir(_n,_p) mkdir((_n))
+#endif +#endif
+ +
static void conf_warning(const char *fmt, ...) static void conf_warning(const char *fmt, ...)
__attribute__ ((format (printf, 1, 2))); {
va_list ap;

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);
@@ -732,6 +734,7 @@ int main(int ac, char **av) @@ -721,6 +723,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 */;
@ -44,7 +44,7 @@ Index: kconfig/conf.c
int no_conf_write = 0; int no_conf_write = 0;
tty_stdio = isatty(0) && isatty(1); tty_stdio = isatty(0) && isatty(1);
@@ -838,6 +841,13 @@ int main(int ac, char **av) @@ -827,6 +830,13 @@ int main(int ac, char **av)
break; break;
} }
@ -62,7 +62,7 @@ Index: kconfig/confdata.c
=================================================================== ===================================================================
--- kconfig.orig/confdata.c --- kconfig.orig/confdata.c
+++ kconfig/confdata.c +++ kconfig/confdata.c
@@ -539,11 +539,7 @@ load: @@ -528,11 +528,7 @@ load:
free(line); free(line);
fclose(in); fclose(in);

View File

@ -34,7 +34,7 @@ Index: kconfig/lexer.l
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -438,6 +439,32 @@ void zconf_nextfile(const char *name) @@ -439,6 +440,32 @@ void zconf_nextfile(const char *name)
current_file = file; current_file = file;
} }

View File

@ -10,74 +10,6 @@ Date: Fri Nov 22 22:08:15 2019 +0100
Change-Id: I9e62b05e45709f1539e455e2eed37308609be15e Change-Id: I9e62b05e45709f1539e455e2eed37308609be15e
Signed-off-by: Patrick Georgi <pgeorgi@google.com> Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Index: kconfig/confdata.c
===================================================================
--- kconfig.orig/confdata.c
+++ kconfig/confdata.c
@@ -687,6 +687,9 @@ header_print_symbol(FILE *fp, struct sym
switch (*value) {
case 'n':
+ if (getenv("KCONFIG_NEGATIVES") != NULL)
+ fprintf(fp, "#define %s%s%s 0\n",
+ CONFIG_, sym->name, suffix);
break;
case 'm':
suffix = "_MODULE";
@@ -702,14 +705,28 @@ header_print_symbol(FILE *fp, struct sym
if (value[0] != '0' || (value[1] != 'x' && value[1] != 'X'))
prefix = "0x";
+ if (value[0] == '\0') {
+ /*
+ * prefix is reset to remain closer to the older
+ * coreboot patch. No need to keep this once kconfig
+ * is fully upreved
+ */
+ prefix = "";
+ value = "0";
+ }
fprintf(fp, "#define %s%s %s%s\n",
CONFIG_, sym->name, prefix, value);
break;
}
case S_STRING:
+ if (value[0] == '\0')
+ break;
+ if (!(sym->flags & SYMBOL_WRITE))
+ break;
+ /* fall through */
case S_INT:
fprintf(fp, "#define %s%s %s\n",
- CONFIG_, sym->name, value);
+ CONFIG_, sym->name, value[0]?value:"0");
break;
default:
break;
@@ -1080,6 +1097,7 @@ int conf_write_autoconf(int overwrite)
const char *autoconf_name = conf_get_autoconfig_name();
FILE *out, *out_h;
int i;
+ int print_negatives = getenv("KCONFIG_NEGATIVES") != NULL;
if (!overwrite && is_present(autoconf_name))
return 0;
@@ -1104,11 +1122,13 @@ int conf_write_autoconf(int overwrite)
for_all_symbols(i, sym) {
sym_calc_value(sym);
- if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
+ if (!(sym->flags & SYMBOL_WRITE) && !print_negatives)
+ continue;
+ if (!sym->name)
continue;
/* write symbols to auto.conf and autoconf.h */
- conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1);
+ conf_write_symbol(out, sym, &kconfig_printer_cb, print_negatives?NULL:(void *)1);
conf_write_symbol(out_h, sym, &header_printer_cb, NULL);
}
fclose(out);
Index: kconfig/symbol.c Index: kconfig/symbol.c
=================================================================== ===================================================================
--- kconfig.orig/symbol.c --- kconfig.orig/symbol.c
@ -91,3 +23,56 @@ Index: kconfig/symbol.c
case S_STRING: case S_STRING:
return str; return str;
case S_UNKNOWN: case S_UNKNOWN:
Index: kconfig/confdata.c
===================================================================
--- kconfig.orig/confdata.c
+++ kconfig/confdata.c
@@ -720,7 +720,12 @@ static void print_symbol_for_dotconfig(F
static void print_symbol_for_autoconf(FILE *fp, struct symbol *sym)
{
- __print_symbol(fp, sym, OUTPUT_N_NONE, true);
+ int print_negatives = getenv("KCONFIG_NEGATIVES") != NULL;
+ enum output_n out = OUTPUT_N_NONE;
+ if (print_negatives) {
+ out = OUTPUT_N;
+ }
+ __print_symbol(fp, sym, out, true);
}
void print_symbol_for_listconfig(struct symbol *sym)
@@ -745,6 +750,10 @@ static void print_symbol_for_c(FILE *fp,
case S_TRISTATE:
switch (*val) {
case 'n':
+ if (getenv("KCONFIG_NEGATIVES") != NULL) {
+ val = "0";
+ break;
+ }
return;
case 'm':
sym_suffix = "_MODULE";
@@ -756,6 +765,12 @@ static void print_symbol_for_c(FILE *fp,
case S_HEX:
if (val[0] != '0' || (val[1] != 'x' && val[1] != 'X'))
val_prefix = "0x";
+ /* fall through */
+ case S_INT:
+ if (val[0] == '\0') {
+ val = "0";
+ val_prefix = "";
+ }
break;
case S_STRING:
escaped = escape_string_value(val);
@@ -1106,8 +1121,9 @@ static int __conf_write_autoconf(const c
conf_write_heading(file, comment_style);
+ int print_negatives = getenv("KCONFIG_NEGATIVES") != NULL;
for_all_symbols(i, sym)
- if ((sym->flags & SYMBOL_WRITE) && sym->name)
+ if (((sym->flags & SYMBOL_WRITE) || (print_negatives && sym->type != S_STRING)) && sym->name)
print_symbol(file, sym);
/* check possible errors in conf_write_heading() and print_symbol() */

View File

@ -2,8 +2,8 @@ Index: kconfig/confdata.c
=================================================================== ===================================================================
--- kconfig.orig/confdata.c --- kconfig.orig/confdata.c
+++ kconfig/confdata.c +++ kconfig/confdata.c
@@ -241,6 +241,13 @@ static const char *conf_get_autoconfig_n @@ -230,6 +230,13 @@ static const char *conf_get_autoheader_n
return name ? name : "include/config/auto.conf"; return name ? name : "include/generated/autoconf.h";
} }
+static const char *conf_get_autobase_name(void) +static const char *conf_get_autobase_name(void)
@ -16,7 +16,7 @@ Index: kconfig/confdata.c
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;
@@ -1024,7 +1031,7 @@ static int conf_touch_deps(void) @@ -1031,7 +1038,7 @@ static int conf_touch_deps(void)
struct symbol *sym; struct symbol *sym;
int res, i; int res, i;
@ -25,15 +25,3 @@ Index: kconfig/confdata.c
depfile_prefix_len = strlen(depfile_path); depfile_prefix_len = strlen(depfile_path);
name = conf_get_autoconfig_name(); name = conf_get_autoconfig_name();
@@ -1102,7 +1109,10 @@ int conf_write_autoconf(int overwrite)
if (!overwrite && is_present(autoconf_name))
return 0;
- conf_write_dep("include/config/auto.conf.cmd");
+ char autoconfcmd_path[PATH_MAX];
+ snprintf(autoconfcmd_path, sizeof(autoconfcmd_path), "%s%s",
+ conf_get_autobase_name(), "auto.conf.cmd");
+ conf_write_dep(autoconfcmd_path);
if (conf_touch_deps())
return 1;

View File

@ -1,124 +0,0 @@
commit 7b2deddbb0ef350e189fe42c025b07c943aedc4c
Author: Raul E Rangel <rrangel@chromium.org>
Date: Thu Jul 25 15:49:52 2019 -0600
Kconfig: Write tmp files into same directory as target files
This removes the need for COREBOOT_BUILD_DIR in Kconfig. Since the
original files will be replaced with the tmp file, the parent directory
already needs to be writable.
Before this change, the tmp files would be created in the CWD (src) if
COREBOOT_BUILD_DIR was not specified.
BUG=b:112267918
TEST=emerge-grunt coreboot and verified no tmp files were created in the
src directory.
Change-Id: Icdaf2ff3dd1ec98813b75ef55b96e38e1ca19ec7
Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/34244
Reviewed-by: Martin Roth <martinroth@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Index: kconfig/confdata.c
===================================================================
--- kconfig.orig/confdata.c
+++ kconfig/confdata.c
@@ -880,6 +880,16 @@ next_menu:
return 0;
}
+
+static int conf_mktemp(const char *path, char *tmpfile)
+{
+ if (snprintf(tmpfile, PATH_MAX, "%s.tmp.XXXXXX", path) >= PATH_MAX) {
+ errno = EOVERFLOW;
+ return -1;
+ }
+ return mkstemp(tmpfile);
+}
+
int conf_write(const char *name)
{
FILE *out;
@@ -1001,7 +1011,14 @@ static int conf_write_dep(const char *na
struct file *file;
FILE *out;
- out = fopen("..config.tmp", "w");
+ if (make_parent_dir(name))
+ return 1;
+ char filename[PATH_MAX];
+ int fd = conf_mktemp(name, filename);
+ if (fd == -1)
+ return 1;
+
+ out = fdopen(fd, "w");
if (!out)
return 1;
fprintf(out, "deps_config := \\\n");
@@ -1019,9 +1036,7 @@ static int conf_write_dep(const char *na
fprintf(out, "\n$(deps_config): ;\n");
fclose(out);
- if (make_parent_dir(name))
- return 1;
- rename("..config.tmp", name);
+ rename(filename, name);
return 0;
}
@@ -1117,11 +1132,26 @@ int conf_write_autoconf(int overwrite)
if (conf_touch_deps())
return 1;
- out = fopen(".tmpconfig", "w");
+ if (make_parent_dir(autoconf_name))
+ return 1;
+ char filename[PATH_MAX];
+ int fd = conf_mktemp(autoconf_name, filename);
+ if (fd == -1)
+ return 1;
+ out = fdopen(fd, "w");
if (!out)
return 1;
- out_h = fopen(".tmpconfig.h", "w");
+ name = getenv("KCONFIG_AUTOHEADER");
+ if (!name)
+ name = "include/generated/autoconf.h";
+ if (make_parent_dir(name))
+ return 1;
+ char filename_h[PATH_MAX];
+ int fd_h = conf_mktemp(name, filename_h);
+ if (fd_h == -1)
+ return 1;
+ out_h = fdopen(fd_h, "w");
if (!out_h) {
fclose(out);
return 1;
@@ -1144,21 +1174,14 @@ int conf_write_autoconf(int overwrite)
fclose(out);
fclose(out_h);
- name = getenv("KCONFIG_AUTOHEADER");
- if (!name)
- name = "include/generated/autoconf.h";
- if (make_parent_dir(name))
- return 1;
- if (rename(".tmpconfig.h", name))
+ if (rename(filename_h, name))
return 1;
- if (make_parent_dir(autoconf_name))
- return 1;
/*
* This must be the last step, kbuild has a dependency on auto.conf
* and this marks the successful completion of the previous steps.
*/
- if (rename(".tmpconfig", autoconf_name))
+ if (rename(filename, autoconf_name))
return 1;
return 0;

View File

@ -9,5 +9,4 @@
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 0011-remove-include-config-hardcodes.patch
0012-safer-tmpfiles.patch
0013-util-kconfig-detect-ncurses-on-FreeBSD.patch 0013-util-kconfig-detect-ncurses-on-FreeBSD.patch

View File

@ -872,49 +872,6 @@ struct symbol *sym_find(const char *name)
return symbol; return symbol;
} }
const char *sym_escape_string_value(const char *in)
{
const char *p;
size_t reslen;
char *res;
size_t l;
reslen = strlen(in) + strlen("\"\"") + 1;
p = in;
for (;;) {
l = strcspn(p, "\"\\");
p += l;
if (p[0] == '\0')
break;
reslen++;
p++;
}
res = xmalloc(reslen);
res[0] = '\0';
strcat(res, "\"");
p = in;
for (;;) {
l = strcspn(p, "\"\\");
strncat(res, p, l);
p += l;
if (p[0] == '\0')
break;
strcat(res, "\\");
strncat(res, p++, 1);
}
strcat(res, "\"");
return res;
}
struct sym_match { struct sym_match {
struct symbol *sym; struct symbol *sym;
off_t so, eo; off_t so, eo;