util/kconfig: Add `toada` Ada spec generation tool
Converts `auto.conf` to an Ada spec file. Write to $(obj)/cb-config.ads and set the package name to `CB.Config`. Change-Id: I97c060d8a613c74a82a18aff9524ad4b01f9df56 Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/31053 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org> Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
parent
a402a9e7ab
commit
533bc0a7ef
9
Makefile
9
Makefile
|
@ -44,6 +44,7 @@ COREBOOT_EXPORTS += top src srck obj objutil objk
|
|||
|
||||
DOTCONFIG ?= $(top)/.config
|
||||
KCONFIG_CONFIG = $(DOTCONFIG)
|
||||
KCONFIG_AUTOADS := $(obj)/cb-config.ads
|
||||
KCONFIG_AUTOHEADER := $(obj)/config.h
|
||||
KCONFIG_AUTOCONFIG := $(obj)/auto.conf
|
||||
KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
|
||||
|
@ -51,10 +52,12 @@ KCONFIG_SPLITCONFIG := $(obj)/config
|
|||
KCONFIG_TRISTATE := $(obj)/tristate.conf
|
||||
KCONFIG_NEGATIVES := 1
|
||||
KCONFIG_STRICT := 1
|
||||
KCONFIG_PACKAGE := CB.Config
|
||||
|
||||
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_AUTOADS KCONFIG_PACKAGE
|
||||
|
||||
# directory containing the toplevel Makefile.inc
|
||||
TOPLEVEL := .
|
||||
|
@ -179,6 +182,12 @@ real-all: real-target
|
|||
$(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
|
||||
+$(MAKE) oldconfig
|
||||
|
||||
$(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
|
||||
true
|
||||
|
||||
$(KCONFIG_AUTOADS): $(KCONFIG_AUTOCONFIG) $(objutil)/kconfig/toada
|
||||
$(objutil)/kconfig/toada CB.Config <$< >$@
|
||||
|
||||
# Add a new class of source/object files to the build system
|
||||
add-class= \
|
||||
$(eval $(1)-srcs:=) \
|
||||
|
|
|
@ -344,6 +344,8 @@ $(objk)/nconf: $(patsubst %,$(objk)/%,$(nconf-objs))
|
|||
$(HOSTCC) $(HOSTCFLAGS) -o $@ $^ $(HOSTLOADLIBES_nconf)
|
||||
$(objk)/conf: $(patsubst %,$(objk)/%,$(conf-objs))
|
||||
$(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -o $@ $^
|
||||
$(objk)/toada: $(objk)/toada.o
|
||||
$(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -o $@ $^
|
||||
|
||||
$(objk)/mconf.o: $(srck)/mconf.c
|
||||
$(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -c -o $@ $<
|
||||
|
@ -382,5 +384,8 @@ $(objk)/lxdialog/lxdialog: $(objk)/dochecklxdialog \
|
|||
$(objk)/lxdialog/%.o: $(srck)/lxdialog/%.c
|
||||
$(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) $^ -c -o $@
|
||||
|
||||
$(objk)/toada.o: $(srck)/toada.c
|
||||
$(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -c -o $@ $<
|
||||
|
||||
$(objk)/%.o: HOSTCFLAGS+=-I$(srck) -I$(objk)
|
||||
$(objk)/%.o: HOSTCXXFLAGS+=-I$(srck) -I$(objk)
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* This file is part of the coreboot project.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
static void print_bool(const char *const name, const bool val)
|
||||
{
|
||||
printf(" %-46s : constant boolean := %s;\n",
|
||||
name, val ? "true" : "false");
|
||||
}
|
||||
|
||||
static void print_hex(const char *const name, const char *val)
|
||||
{
|
||||
unsigned int hexlen;
|
||||
|
||||
printf(" %-46s : constant := 16#", name);
|
||||
for (hexlen = strlen(val); hexlen > 0;) {
|
||||
const unsigned int len = hexlen % 4 ? : 4;
|
||||
char quad[] = "0000";
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < len; ++i)
|
||||
quad[4 - len + i] = val[i];
|
||||
printf("%s", quad);
|
||||
|
||||
val += len;
|
||||
hexlen -= len;
|
||||
if (hexlen > 0)
|
||||
printf("_");
|
||||
}
|
||||
printf ("#;\n");
|
||||
}
|
||||
|
||||
static void print_dec(const char *const name, const char *const val)
|
||||
{
|
||||
printf(" %-46s : constant := %s;\n", name, val);
|
||||
}
|
||||
|
||||
static void print_string(const char *const name, const char *const val)
|
||||
{
|
||||
printf(" %-46s : constant string := \"%s\";\n", name, val);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char unset_fmt[256], string_fmt[256], set_fmt[256], line[256];
|
||||
char *prefix = "CONFIG", *package = "KConfig";
|
||||
|
||||
if (argc > 3) {
|
||||
fprintf(stderr,
|
||||
"Usage: %s [<package name> [<config prefix>]]\n\n",
|
||||
argv[0]);
|
||||
return 1;
|
||||
}
|
||||
if (argc > 2)
|
||||
prefix = argv[2];
|
||||
if (argc > 1)
|
||||
package = argv[1];
|
||||
|
||||
snprintf(set_fmt, sizeof(set_fmt), "%s_%%255[^=]=%%255s", prefix);
|
||||
snprintf(string_fmt, sizeof(string_fmt),
|
||||
"%s_%%255[^=]=\"%%255[^\"]\"", prefix);
|
||||
snprintf(unset_fmt, sizeof(unset_fmt),
|
||||
"# %s_%%255s is not set", prefix);
|
||||
|
||||
printf("package %s is\n\n", package);
|
||||
|
||||
while (fgets(line, sizeof(line), stdin)) {
|
||||
char name[256], val[256];
|
||||
|
||||
if (line[strlen(line) - 1] != '\n') {
|
||||
fprintf(stderr,
|
||||
"Line longer than %zu chars, skipping...\n",
|
||||
sizeof(line) - 1);
|
||||
while (fgets(line, sizeof(line), stdin)) {
|
||||
if (line[strlen(line) - 1] == '\n')
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sscanf(line, unset_fmt, name) == 1) {
|
||||
print_bool(name, false);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sscanf(line, string_fmt, name, val) == 2) {
|
||||
print_string(name, val);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (sscanf(line, set_fmt, name, val)) {
|
||||
case 1:
|
||||
/* ignore for now, our Kconfig is full of these atm */
|
||||
/* fprintf(stderr, "unset non-bool: %s=\n", name); */
|
||||
continue;
|
||||
case 2:
|
||||
if (strcmp(val, "\"\"") == 0) {
|
||||
print_string(name, "");
|
||||
} else if (strcmp(val, "y") == 0) {
|
||||
print_bool(name, true);
|
||||
} else if (strncmp(val, "0x", 2) == 0) {
|
||||
print_hex(name, val + 2);
|
||||
} else if (isdigit(val[0])) {
|
||||
print_dec(name, val);
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"couldn't parse value '%s' for '%s'\n",
|
||||
val, name);
|
||||
}
|
||||
continue;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
unsigned int i = 0;
|
||||
while (isspace(line[i]))
|
||||
++i;
|
||||
if (line[i] == '#') {
|
||||
printf(" --%s", line + i + 1);
|
||||
continue;
|
||||
} else if (i == strlen(line)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fprintf(stderr, "spurious line:\n%s", line);
|
||||
}
|
||||
|
||||
printf("\nend %s;\n", package);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue