util/sconfig: Prepare sconfig to allow parsing multiple trees
In preparation to allow devicetree overrides, it will be necessary to use the same parsing functions to prepare two separate parse trees. This change does the following things: 1. Updates root device and bus names to add base_ prefix. 2. Adds a function parse_devicetree that sets the root_parent and linenum before calling yyparse(). 3. Updates all uses of root_dev to refer to the next base_root_dev. BUG=b:80081934 TEST=Verified that static.c generated for all boards built using abuild is the same with and without this change. Change-Id: I403a90c1ebf07ac66115ddfe137daf0980dc1a18 Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://review.coreboot.org/27017 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
parent
93459d6278
commit
de39fc7160
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
extern int linenum;
|
extern int linenum;
|
||||||
|
|
||||||
|
/* Maintains list of all the unique chip structures for the board. */
|
||||||
static struct chip chip_header;
|
static struct chip chip_header;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -43,8 +44,8 @@ typedef enum {
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* +------------------------+ +----------------------+
|
* +------------------------+ +----------------------+
|
||||||
* | | | Mainboard |
|
* | Root device | | Mainboard |
|
||||||
* +---------+ Root device (root_dev) +--------------->+ instance +
|
* +---------+ (base_root_dev) +--------------->+ instance +
|
||||||
* | | | chip_instance | (mainboard_instance)|
|
* | | | chip_instance | (mainboard_instance)|
|
||||||
* | +------------------------+ | |
|
* | +------------------------+ | |
|
||||||
* | | +----------------------+
|
* | | +----------------------+
|
||||||
|
@ -52,7 +53,7 @@ typedef enum {
|
||||||
* | parent v |
|
* | parent v |
|
||||||
* | +-------------------+ |
|
* | +-------------------+ |
|
||||||
* | | Root bus | |
|
* | | Root bus | |
|
||||||
* +----------->+ (root_bus) | |
|
* +----------->+ (base_root_bus) | |
|
||||||
* | | |
|
* | | |
|
||||||
* +-------------------+ |
|
* +-------------------+ |
|
||||||
* | |
|
* | |
|
||||||
|
@ -74,23 +75,23 @@ typedef enum {
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static struct device root_dev;
|
static struct device base_root_dev;
|
||||||
static struct chip_instance mainboard_instance;
|
static struct chip_instance mainboard_instance;
|
||||||
|
|
||||||
static struct bus root_bus = {
|
static struct bus base_root_bus = {
|
||||||
.id = 0,
|
.id = 0,
|
||||||
.dev = &root_dev,
|
.dev = &base_root_dev,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct device root_dev = {
|
static struct device base_root_dev = {
|
||||||
.name = "dev_root",
|
.name = "dev_root",
|
||||||
.id = 0,
|
.id = 0,
|
||||||
.chip_instance = &mainboard_instance,
|
.chip_instance = &mainboard_instance,
|
||||||
.path = " .type = DEVICE_PATH_ROOT ",
|
.path = " .type = DEVICE_PATH_ROOT ",
|
||||||
.ops = "&default_dev_ops_root",
|
.ops = "&default_dev_ops_root",
|
||||||
.parent = &root_bus,
|
.parent = &base_root_bus,
|
||||||
.enabled = 1,
|
.enabled = 1,
|
||||||
.bus = &root_bus,
|
.bus = &base_root_bus,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct chip mainboard_chip = {
|
static struct chip mainboard_chip = {
|
||||||
|
@ -105,7 +106,7 @@ static struct chip_instance mainboard_instance = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This is the parent of all devices added by parsing the devicetree file. */
|
/* This is the parent of all devices added by parsing the devicetree file. */
|
||||||
struct bus *root_parent = &root_bus;
|
struct bus *root_parent;
|
||||||
|
|
||||||
struct queue_entry {
|
struct queue_entry {
|
||||||
void *data;
|
void *data;
|
||||||
|
@ -581,7 +582,7 @@ static int dev_has_children(struct device *dev)
|
||||||
|
|
||||||
static void pass0(FILE *fil, struct device *ptr, struct device *next)
|
static void pass0(FILE *fil, struct device *ptr, struct device *next)
|
||||||
{
|
{
|
||||||
if (ptr == &root_dev) {
|
if (ptr == &base_root_dev) {
|
||||||
fprintf(fil, "DEVTREE_CONST struct bus %s_links[];\n",
|
fprintf(fil, "DEVTREE_CONST struct bus %s_links[];\n",
|
||||||
ptr->name);
|
ptr->name);
|
||||||
return;
|
return;
|
||||||
|
@ -670,7 +671,7 @@ static void pass1(FILE *fil, struct device *ptr, struct device *next)
|
||||||
struct chip_instance *chip_ins = ptr->chip_instance;
|
struct chip_instance *chip_ins = ptr->chip_instance;
|
||||||
int has_children = dev_has_children(ptr);
|
int has_children = dev_has_children(ptr);
|
||||||
|
|
||||||
if (ptr != &root_dev)
|
if (ptr != &base_root_dev)
|
||||||
fprintf(fil, "static ");
|
fprintf(fil, "static ");
|
||||||
fprintf(fil, "DEVTREE_CONST struct device %s = {\n", ptr->name);
|
fprintf(fil, "DEVTREE_CONST struct device %s = {\n", ptr->name);
|
||||||
fprintf(fil, "#if !DEVTREE_EARLY\n");
|
fprintf(fil, "#if !DEVTREE_EARLY\n");
|
||||||
|
@ -867,15 +868,9 @@ enum {
|
||||||
|
|
||||||
#define ARG_COUNT 3
|
#define ARG_COUNT 3
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
static void parse_devicetree(const char *file, struct bus *parent)
|
||||||
{
|
{
|
||||||
if (argc != ARG_COUNT)
|
FILE *filec = fopen(file, "r");
|
||||||
usage();
|
|
||||||
|
|
||||||
char *devtree = argv[DEVICEFILE_ARG];
|
|
||||||
char *outputc = argv[OUTPUTFILE_ARG];
|
|
||||||
|
|
||||||
FILE *filec = fopen(devtree, "r");
|
|
||||||
if (!filec) {
|
if (!filec) {
|
||||||
perror(NULL);
|
perror(NULL);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -883,9 +878,23 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
yyrestart(filec);
|
yyrestart(filec);
|
||||||
|
|
||||||
|
root_parent = parent;
|
||||||
|
linenum = 0;
|
||||||
|
|
||||||
yyparse();
|
yyparse();
|
||||||
|
|
||||||
fclose(filec);
|
fclose(filec);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
if (argc != ARG_COUNT)
|
||||||
|
usage();
|
||||||
|
|
||||||
|
char *base_devtree = argv[DEVICEFILE_ARG];
|
||||||
|
char *outputc = argv[OUTPUTFILE_ARG];
|
||||||
|
|
||||||
|
parse_devicetree(base_devtree, &base_root_bus);
|
||||||
|
|
||||||
FILE *autogen = fopen(outputc, "w");
|
FILE *autogen = fopen(outputc, "w");
|
||||||
if (!autogen) {
|
if (!autogen) {
|
||||||
|
@ -897,11 +906,11 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
emit_chips(autogen);
|
emit_chips(autogen);
|
||||||
|
|
||||||
walk_device_tree(autogen, &root_dev, inherit_subsystem_ids);
|
walk_device_tree(autogen, &base_root_dev, inherit_subsystem_ids);
|
||||||
fprintf(autogen, "\n/* pass 0 */\n");
|
fprintf(autogen, "\n/* pass 0 */\n");
|
||||||
walk_device_tree(autogen, &root_dev, pass0);
|
walk_device_tree(autogen, &base_root_dev, pass0);
|
||||||
fprintf(autogen, "\n/* pass 1 */\n");
|
fprintf(autogen, "\n/* pass 1 */\n");
|
||||||
walk_device_tree(autogen, &root_dev, pass1);
|
walk_device_tree(autogen, &base_root_dev, pass1);
|
||||||
|
|
||||||
fclose(autogen);
|
fclose(autogen);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue