summaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/confdata.c
diff options
context:
space:
mode:
authorSam Ravnborg <sam@ravnborg.org>2010-07-31 23:35:34 +0200
committerMichal Marek <mmarek@suse.cz>2010-08-03 13:49:32 +0200
commit7cf3d73b4360e91b14326632ab1aeda4cb26308d (patch)
tree547bc52c631c9fb99ecd5c4be5ba25610505397a /scripts/kconfig/confdata.c
parent49192f266ffa187bd7adaf5c2d881f85bd53e0ed (diff)
downloadtalos-obmc-linux-7cf3d73b4360e91b14326632ab1aeda4cb26308d.tar.gz
talos-obmc-linux-7cf3d73b4360e91b14326632ab1aeda4cb26308d.zip
kconfig: add savedefconfig
savedefconfig will save a minimal config to a file named "defconfig". The config symbols are saved in the same order as they appear in the menu structure so it should be possible to map them to the relevant menus if desired. The implementation was tested against several minimal configs for arm which was created using brute-force. There was one regression related to default numbers which had their valid range further limited by another symbol. Sample: config FOO int "foo" default 4 config BAR int "bar" range 0 FOO If FOO is set to 3 then BAR cannot take a value higher than 3. But the current implementation will set BAR equal to 4. This is seldomly used and the final configuration is OK, and the fix was non-trivial. So it was documented in the code and left as is. Signed-off-by: Sam Ravnborg <sam@ravnborg.org> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts/kconfig/confdata.c')
-rw-r--r--scripts/kconfig/confdata.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 583f6405f01d..f81f263b64f2 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -457,6 +457,82 @@ static void conf_write_symbol(struct symbol *sym, enum symbol_type type,
}
}
+/*
+ * Write out a minimal config.
+ * All values that has default values are skipped as this is redundant.
+ */
+int conf_write_defconfig(const char *filename)
+{
+ struct symbol *sym;
+ struct menu *menu;
+ FILE *out;
+
+ out = fopen(filename, "w");
+ if (!out)
+ return 1;
+
+ sym_clear_all_valid();
+
+ /* Traverse all menus to find all relevant symbols */
+ menu = rootmenu.list;
+
+ while (menu != NULL)
+ {
+ sym = menu->sym;
+ if (sym == NULL) {
+ if (!menu_is_visible(menu))
+ goto next_menu;
+ } else if (!sym_is_choice(sym)) {
+ sym_calc_value(sym);
+ if (!(sym->flags & SYMBOL_WRITE))
+ goto next_menu;
+ sym->flags &= ~SYMBOL_WRITE;
+ /* If we cannot change the symbol - skip */
+ if (!sym_is_changable(sym))
+ goto next_menu;
+ /* If symbol equals to default value - skip */
+ if (strcmp(sym_get_string_value(sym), sym_get_string_default(sym)) == 0)
+ goto next_menu;
+
+ /*
+ * If symbol is a choice value and equals to the
+ * default for a choice - skip.
+ * But only if value equal to "y".
+ */
+ if (sym_is_choice_value(sym)) {
+ struct symbol *cs;
+ struct symbol *ds;
+
+ cs = prop_get_symbol(sym_get_choice_prop(sym));
+ ds = sym_choice_default(cs);
+ if (sym == ds) {
+ if ((sym->type == S_BOOLEAN ||
+ sym->type == S_TRISTATE) &&
+ sym_get_tristate_value(sym) == yes)
+ goto next_menu;
+ }
+ }
+ conf_write_symbol(sym, sym->type, out, true);
+ }
+next_menu:
+ if (menu->list != NULL) {
+ menu = menu->list;
+ }
+ else if (menu->next != NULL) {
+ menu = menu->next;
+ } else {
+ while ((menu = menu->parent)) {
+ if (menu->next != NULL) {
+ menu = menu->next;
+ break;
+ }
+ }
+ }
+ }
+ fclose(out);
+ return 0;
+}
+
int conf_write(const char *name)
{
FILE *out;
OpenPOWER on IntegriCloud