Skip to content

Commit

Permalink
util/kconfig: Uprev to Linux 6.6's kconfig
Browse files Browse the repository at this point in the history
Upstream reimplemented KCONFIG_STRICT, just calling it KCONFIG_WERROR.
Therefore, adapt our build system and documentation. Upstream is less
strict at this time, but there's a proposed patch that got imported.

TEST=`util/abuild/abuild -C` output (config.h and
config.build) remains the same. Also, the failure type fixed in
https://review.coreboot.org/c/coreboot/+/11272 can be detected,
which I tested by manually breaking our Kconfig in a similar way.

Change-Id: I322fb08a2f7308b93cff71a5dd4136f1a998773b
Signed-off-by: Patrick Georgi <[email protected]>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/79259
Tested-by: build bot (Jenkins) <[email protected]>
Reviewed-by: Martin L Roth <[email protected]>
Reviewed-by: Felix Singer <[email protected]>
  • Loading branch information
Patrick Georgi committed Nov 25, 2023
1 parent 47282a9 commit 0eab62b
Show file tree
Hide file tree
Showing 25 changed files with 406 additions and 449 deletions.
10 changes: 3 additions & 7 deletions Documentation/getting_started/kconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ These variables are typically set in the makefiles or on the make command line.
These variables were added to Kconfig specifically for coreboot and are not
included in the Linux version.

- KCONFIG_STRICT=value. Define to enable warnings as errors. This is enabled
in coreboot, and should not be changed.

- KCONFIG_NEGATIVES=value. Define to show negative values in the autoconf.h file
(build/config.h). This is enabled in coreboot, and should not be changed.

Expand Down Expand Up @@ -102,6 +99,9 @@ included in the Linux version.
- KCONFIG_SPLITCONFIG=”directory name for individual SYMBOL.h files”.
coreboot sets this to $(obj)/config.

- KCONFIG_WERROR=value. Define to enable warnings as errors. This is enabled
in coreboot, and should not be changed.

#### Used only for ‘make menuconfig’
- MENUCONFIG_MODE=single_menu. Set to "single_menu" to enable. All other
values disable the option. This makes submenus appear below the menu option
Expand Down Expand Up @@ -1160,10 +1160,6 @@ saved .config file. As always, a 'select' statement overrides any specified
- coreboot has added the glob operator '*' for the 'source' keyword.
- coreboot’s Kconfig always defines variables except for strings. In other
Kconfig implementations, bools set to false/0/no are not defined.
- coreboot’s version of Kconfig adds the KCONFIG_STRICT environment variable to
error out if there are any issues in the Kconfig files. In the Linux kernel,
Kconfig will generate a warning, but will still output an updated .config or
config.h file.


## Kconfig Editor Highlighting
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
KCONFIG_SPLITCONFIG := $(obj)/config/
KCONFIG_TRISTATE := $(obj)/tristate.conf
KCONFIG_NEGATIVES := 1
KCONFIG_STRICT := 1
KCONFIG_WERROR:= 1
KCONFIG_WARN_UNKNOWN_SYMBOLS:= 1
KCONFIG_PACKAGE := CB.Config
KCONFIG_MAKEFILE_REAL ?= $(objk)/Makefile.real

COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_WERROR
COREBOOT_EXPORTS += KCONFIG_WARN_UNKNOWN_SYMBOLS
COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE

# Make does not offer a recursive wildcard function, so here's one:
Expand Down
15 changes: 12 additions & 3 deletions util/kconfig/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ endif
%_defconfig: $(obj)/conf
$(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)

configfiles=$(wildcard $(srctree)/kernel/configs/$@ $(srctree)/arch/$(SRCARCH)/configs/$@)
configfiles = $(wildcard $(srctree)/kernel/configs/$(1) $(srctree)/arch/$(SRCARCH)/configs/$(1))
all-config-fragments = $(call configfiles,*.config)
config-fragments = $(call configfiles,$@)

%.config: $(obj)/conf
$(if $(call configfiles),, $(error No configuration exists for this target on this architecture))
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh -m .config $(configfiles)
$(if $(config-fragments),, $(error $@ fragment does not exists on this architecture))
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh -m .config $(config-fragments)
$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig

PHONY += tinyconfig
Expand All @@ -115,6 +117,7 @@ clean-files += tests/.cache

# Help text used by make help
help:
@echo 'Configuration targets:'
@echo ' config - Update current config utilising a line-oriented program'
@echo ' nconfig - Update current config utilising a ncurses menu based program'
@echo ' menuconfig - Update current config utilising a menu based program'
Expand All @@ -141,6 +144,12 @@ help:
@echo ' default value without prompting'
@echo ' tinyconfig - Configure the tiniest possible kernel'
@echo ' testconfig - Run Kconfig unit tests (requires python3 and pytest)'
@echo ''
@echo 'Configuration topic targets:'
@$(foreach f, $(all-config-fragments), \
if help=$$(grep -m1 '^# Help: ' $(f)); then \
printf ' %-25s - %s\n' '$(notdir $(f))' "$${help#*: }"; \
fi;)

# ===========================================================================
# object files used by all kconfig flavours
Expand Down
10 changes: 0 additions & 10 deletions util/kconfig/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#include "lkc.h"

int kconfig_warnings = 0;

static void conf(struct menu *menu);
static void check_conf(struct menu *menu);

Expand Down Expand Up @@ -722,7 +720,6 @@ int main(int ac, char **av)
const char *progname = av[0];
int opt;
const char *name, *defconfig_file = NULL /* gcc uninit */;
char *env;
int no_conf_write = 0;

tty_stdio = isatty(0) && isatty(1);
Expand Down Expand Up @@ -830,13 +827,6 @@ int main(int ac, char **av)
break;
}

env = getenv("KCONFIG_STRICT");
if (env && *env && kconfig_warnings) {
fprintf(stderr, "\n*** ERROR: %d warnings encountered, and "
"warnings are errors.\n\n", kconfig_warnings);
exit(1);
}

if (sync_kconfig) {
name = getenv("KCONFIG_NOSILENTUPDATE");
if (name && *name) {
Expand Down
25 changes: 19 additions & 6 deletions util/kconfig/confdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,11 @@ int conf_read_simple(const char *name, int def)
char *p, *p2;
struct symbol *sym;
int i, def_flags;
const char *warn_unknown;
const char *werror;

warn_unknown = getenv("KCONFIG_WARN_UNKNOWN_SYMBOLS");
werror = getenv("KCONFIG_WERROR");
if (name) {
in = zconf_fopen(name);
} else {
Expand Down Expand Up @@ -458,9 +462,10 @@ int conf_read_simple(const char *name, int def)
if (def == S_DEF_USER) {
sym = sym_find(line + 2 + strlen(CONFIG_));
if (!sym) {
conf_message(
"ignoring nonexistent symbol %s",
line + 2 + strlen(CONFIG_));
if (warn_unknown)
conf_warning("unknown symbol: %s",
line + 2 + strlen(CONFIG_));

conf_set_changed(true);
continue;
}
Expand Down Expand Up @@ -495,16 +500,21 @@ int conf_read_simple(const char *name, int def)

sym = sym_find(line + strlen(CONFIG_));
if (!sym) {
if (def == S_DEF_AUTO)
if (def == S_DEF_AUTO) {
/*
* Reading from include/config/auto.conf
* If CONFIG_FOO previously existed in
* auto.conf but it is missing now,
* include/config/FOO must be touched.
*/
conf_touch_dep(line + strlen(CONFIG_));
else
} else {
if (warn_unknown)
conf_warning("unknown symbol: %s",
line + strlen(CONFIG_));

conf_set_changed(true);
}
continue;
}

Expand Down Expand Up @@ -544,7 +554,10 @@ int conf_read_simple(const char *name, int def)
free(line);
fclose(in);

kconfig_warnings += conf_warnings;
if (conf_warnings && werror) {
fprintf(stderr, "\nERROR: %d warnings encountered, and warnings are errors.\n\n", conf_warnings);
exit(1);
}

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion util/kconfig/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ struct jump_key {
struct list_head entries;
size_t offset;
struct menu *target;
int index;
};

extern struct file *file_list;
Expand Down
4 changes: 1 addition & 3 deletions util/kconfig/lkc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ void zconf_nextfiles(const char *name);
int zconf_lineno(void);
const char *zconf_curname(void);

/* conf.c */
extern int kconfig_warnings;

/* confdata.c */
const char *conf_get_configname(void);
void set_all_choice_values(struct symbol *csym);
Expand Down Expand Up @@ -105,6 +102,7 @@ const char *menu_get_prompt(struct menu *menu);
struct menu *menu_get_parent_menu(struct menu *menu);
bool menu_has_help(struct menu *menu);
const char *menu_get_help(struct menu *menu);
int get_jump_key_char(void);
struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head);
void menu_get_ext_help(struct menu *menu, struct gstr *help);

Expand Down
10 changes: 3 additions & 7 deletions util/kconfig/lxdialog/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,9 @@ int first_alpha(const char *string, const char *exempt);
int dialog_yesno(const char *title, const char *prompt, int height, int width);
int dialog_msgbox(const char *title, const char *prompt, int height,
int width, int pause);


typedef void (*update_text_fn)(char *buf, size_t start, size_t end, void
*_data);
int dialog_textbox(const char *title, char *tbuf, int initial_height,
int initial_width, int *keys, int *_vscroll, int *_hscroll,
update_text_fn update_text, void *data);
int dialog_textbox(const char *title, const char *tbuf, int initial_height,
int initial_width, int *_vscroll, int *_hscroll,
int (*extra_key_cb)(int, size_t, size_t, void *), void *data);
int dialog_menu(const char *title, const char *prompt,
const void *selected, int *s_scroll);
int dialog_checklist(const char *title, const char *prompt, int height,
Expand Down
68 changes: 24 additions & 44 deletions util/kconfig/lxdialog/textbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

static int hscroll;
static int begin_reached, end_reached, page_length;
static char *buf;
static char *page;
static const char *buf, *page;
static size_t start, end;

/*
* Go back 'n' lines in text. Called by dialog_textbox().
Expand Down Expand Up @@ -98,21 +98,10 @@ static void print_line(WINDOW *win, int row, int width)
/*
* Print a new page of text.
*/
static void print_page(WINDOW *win, int height, int width, update_text_fn
update_text, void *data)
static void print_page(WINDOW *win, int height, int width)
{
int i, passed_end = 0;

if (update_text) {
char *end;

for (i = 0; i < height; i++)
get_line();
end = page;
back_lines(height);
update_text(buf, page - buf, end - buf, data);
}

page_length = 0;
for (i = 0; i < height; i++) {
print_line(win, i, width);
Expand Down Expand Up @@ -142,24 +131,26 @@ static void print_position(WINDOW *win)
* refresh window content
*/
static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw,
int cur_y, int cur_x, update_text_fn update_text,
void *data)
int cur_y, int cur_x)
{
print_page(box, boxh, boxw, update_text, data);
start = page - buf;

print_page(box, boxh, boxw);
print_position(dialog);
wmove(dialog, cur_y, cur_x); /* Restore cursor position */
wrefresh(dialog);

end = page - buf;
}

/*
* Display text from a file in a dialog box.
*
* keys is a null-terminated array
* update_text() may not add or remove any '\n' or '\0' in tbuf
*/
int dialog_textbox(const char *title, char *tbuf, int initial_height,
int initial_width, int *keys, int *_vscroll, int *_hscroll,
update_text_fn update_text, void *data)
int dialog_textbox(const char *title, const char *tbuf, int initial_height,
int initial_width, int *_vscroll, int *_hscroll,
int (*extra_key_cb)(int, size_t, size_t, void *), void *data)
{
int i, x, y, cur_x, cur_y, key = 0;
int height, width, boxh, boxw;
Expand Down Expand Up @@ -239,8 +230,7 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height,

/* Print first page of text */
attr_clear(box, boxh, boxw, dlg.dialog.atr);
refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x, update_text,
data);
refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);

while (!done) {
key = wgetch(dialog);
Expand All @@ -259,8 +249,7 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height,
begin_reached = 1;
page = buf;
refresh_text_box(dialog, box, boxh, boxw,
cur_y, cur_x, update_text,
data);
cur_y, cur_x);
}
break;
case 'G': /* Last page */
Expand All @@ -270,8 +259,7 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height,
/* point to last char in buf */
page = buf + strlen(buf);
back_lines(boxh);
refresh_text_box(dialog, box, boxh, boxw, cur_y,
cur_x, update_text, data);
refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);
break;
case 'K': /* Previous line */
case 'k':
Expand All @@ -280,8 +268,7 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height,
break;

back_lines(page_length + 1);
refresh_text_box(dialog, box, boxh, boxw, cur_y,
cur_x, update_text, data);
refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);
break;
case 'B': /* Previous page */
case 'b':
Expand All @@ -290,8 +277,7 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height,
if (begin_reached)
break;
back_lines(page_length + boxh);
refresh_text_box(dialog, box, boxh, boxw, cur_y,
cur_x, update_text, data);
refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);
break;
case 'J': /* Next line */
case 'j':
Expand All @@ -300,8 +286,7 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height,
break;

back_lines(page_length - 1);
refresh_text_box(dialog, box, boxh, boxw, cur_y,
cur_x, update_text, data);
refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);
break;
case KEY_NPAGE: /* Next page */
case ' ':
Expand All @@ -310,8 +295,7 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height,
break;

begin_reached = 0;
refresh_text_box(dialog, box, boxh, boxw, cur_y,
cur_x, update_text, data);
refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);
break;
case '0': /* Beginning of line */
case 'H': /* Scroll left */
Expand All @@ -326,8 +310,7 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height,
hscroll--;
/* Reprint current page to scroll horizontally */
back_lines(page_length);
refresh_text_box(dialog, box, boxh, boxw, cur_y,
cur_x, update_text, data);
refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);
break;
case 'L': /* Scroll right */
case 'l':
Expand All @@ -337,8 +320,7 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height,
hscroll++;
/* Reprint current page to scroll horizontally */
back_lines(page_length);
refresh_text_box(dialog, box, boxh, boxw, cur_y,
cur_x, update_text, data);
refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);
break;
case KEY_ESC:
if (on_key_esc(dialog) == KEY_ESC)
Expand All @@ -351,11 +333,9 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height,
on_key_resize();
goto do_resize;
default:
for (i = 0; keys[i]; i++) {
if (key == keys[i]) {
done = true;
break;
}
if (extra_key_cb && extra_key_cb(key, start, end, data)) {
done = true;
break;
}
}
}
Expand Down
Loading

0 comments on commit 0eab62b

Please sign in to comment.