mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-08-21 16:17:16 +08:00
2006-08-09 Kolja Waschk <waschk@telos.de>
* configure.ac: New port to Altera NIOS II. * nios2/.cvsignore, nios2/Makefile.am, nios2/README, nios2/bridges.c, nios2/bridges.h, nios2/clocks.c, nios2/clocks.h, nios2/configure.ac, nios2/devices.c, nios2/devices.h, nios2/nios2gen.c, nios2/output.c, nios2/output.h, nios2/ptf.c, nios2/ptf.h: New files.
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
2006-08-09 Kolja Waschk <waschk@telos.de>
|
||||
|
||||
* configure.ac: New port to Altera NIOS II.
|
||||
* nios2/.cvsignore, nios2/Makefile.am, nios2/README, nios2/bridges.c,
|
||||
nios2/bridges.h, nios2/clocks.c, nios2/clocks.h, nios2/configure.ac,
|
||||
nios2/devices.c, nios2/devices.h, nios2/nios2gen.c, nios2/output.c,
|
||||
nios2/output.h, nios2/ptf.c, nios2/ptf.h: New files.
|
||||
|
||||
2004-09-24 Ralf Corsepius <ralf_corsepius@rtems.org>
|
||||
|
||||
* configure.ac: Require automake > 1.9.
|
||||
|
||||
@@ -20,6 +20,7 @@ AC_SUBST(program_prefix)
|
||||
AC_CONFIG_SUBDIRS(generic)
|
||||
case "$RTEMS_CPU" in
|
||||
sh ) AC_CONFIG_SUBDIRS(sh);;
|
||||
nios2 ) AC_CONFIG_SUBDIRS(nios2);;
|
||||
esac
|
||||
|
||||
# Explicitly list all Makefiles here
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
aclocal.m4
|
||||
autom4te*.cache
|
||||
config.cache
|
||||
config.guess
|
||||
config.log
|
||||
config.status
|
||||
config.sub
|
||||
configure
|
||||
depcomp
|
||||
install-sh
|
||||
Makefile
|
||||
Makefile.in
|
||||
missing
|
||||
mkinstalldirs
|
||||
@@ -0,0 +1,23 @@
|
||||
##
|
||||
## $Id$
|
||||
##
|
||||
|
||||
ACLOCAL_AMFLAGS = -I ../../../aclocal
|
||||
|
||||
noinst_PROGRAMS = nios2gen
|
||||
|
||||
nios2gen_SOURCES = nios2gen.c \
|
||||
bridges.c bridges.h \
|
||||
devices.c devices.h \
|
||||
clocks.c clocks.h \
|
||||
output.c output.h \
|
||||
ptf.h ptf.c
|
||||
|
||||
if HELP2MAN
|
||||
man_MANS = nios2gen.1
|
||||
|
||||
nios2gen.1: nios2gen$(EXEEXT)
|
||||
$(HELP2MAN) -N ./nios2gen >$@
|
||||
endif
|
||||
|
||||
include $(top_srcdir)/../../../automake/host.am
|
||||
@@ -0,0 +1,19 @@
|
||||
$Id$
|
||||
|
||||
As an output from SOPC Builder you get a file with extension ".ptf" that fully
|
||||
describes the SOPC, including all CPUs, memory and integrated peripherals.
|
||||
|
||||
It is structured as
|
||||
|
||||
|
||||
|
||||
|
||||
nios2gen:
|
||||
Tool to generate BSP data for boards utilizing NIOS2 soft core processor.
|
||||
|
||||
Specify the PTF and name of the CPU (if there are more than one).
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/********************************************************/
|
||||
/* Find bus bridges */
|
||||
|
||||
/* This part of the program builds a list with pairs of bus
|
||||
master port names (each is "device name/master port name").
|
||||
It is then possible to find if a given master is actually
|
||||
available under a different master port name through bridges.
|
||||
*/
|
||||
|
||||
/* Typical example with external SRAM that is slave of
|
||||
tristate_bridge_0/tristate_master, and
|
||||
tristate_bridge_0 itself is slave of cpu0/data_master, the
|
||||
bridge information would be stored as this bus_bridge_pair:
|
||||
mastered_by = "cpu0/data_master" and
|
||||
bridges_to = "tristate_bridge_0/tristate_master".
|
||||
That allows to deduce that SRAM is actually mastered by
|
||||
cpu0/data_master. If there were any address or bus width
|
||||
translations, it should be noted in the bridges list... For
|
||||
now we simply assume that bridges never translate anything.
|
||||
*/
|
||||
|
||||
#include "ptf.h"
|
||||
#include "bridges.h"
|
||||
|
||||
int is_bridged(
|
||||
char *cpu_master,
|
||||
char *dev_master,
|
||||
bus_bridge_pair *bridges)
|
||||
{
|
||||
char *curr_master;
|
||||
bus_bridge_pair *bbp;
|
||||
|
||||
curr_master = dev_master;
|
||||
while(curr_master != NULL)
|
||||
{
|
||||
/* Does cpu_master master curr_master? */
|
||||
if(strcmp(cpu_master, curr_master) == 0) return 1; /* yes, cpu_masters cm */
|
||||
|
||||
/* No, cm is attached to a bridge? */
|
||||
bbp = bridges;
|
||||
while(bbp != NULL)
|
||||
{
|
||||
if(strcmp(bbp->bridges_to, curr_master) == 0)
|
||||
{
|
||||
curr_master = bbp->mastered_by;
|
||||
break;
|
||||
};
|
||||
bbp = bbp->next;
|
||||
};
|
||||
if(bbp == NULL) curr_master = NULL;
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void add_bridge_master(struct ptf_item *pi, void *arg)
|
||||
{
|
||||
struct { char *bt; bus_bridge_pair **bridges; } *binfo = arg;
|
||||
bus_bridge_pair *new_pair;
|
||||
|
||||
if(binfo->bridges == 0) return;
|
||||
|
||||
new_pair = (bus_bridge_pair *)malloc(sizeof(bus_bridge_pair));
|
||||
if(new_pair == NULL) return;
|
||||
|
||||
new_pair->bridges_to = binfo->bt;
|
||||
new_pair->mastered_by = pi->item[pi->level]->value;
|
||||
new_pair->next = *(binfo->bridges);
|
||||
*(binfo->bridges) = new_pair;
|
||||
}
|
||||
|
||||
void add_bridge_dest(struct ptf_item *pi, void *arg)
|
||||
{
|
||||
struct ptf maby_section = { section, "MASTERED_BY", 0, 0, 0 };
|
||||
struct ptf_item maby = { 1, &maby_section };
|
||||
|
||||
char *bridge_name = pi->item[1]->value;
|
||||
char *bridge_dest = pi->item[pi->level]->value;
|
||||
struct { char *bt; bus_bridge_pair **bridges; } binfo;
|
||||
|
||||
binfo.bridges = arg;
|
||||
binfo.bt = (char*)malloc(strlen(bridge_name)+strlen(bridge_dest) + 2);
|
||||
strcpy(binfo.bt, bridge_name);
|
||||
strcat(binfo.bt, "/");
|
||||
strcat(binfo.bt, bridge_dest);
|
||||
|
||||
ptf_match(pi->item[pi->level-1]->sub, &maby, add_bridge_master, &binfo);
|
||||
|
||||
/* binfo.bt is NOT freed here */
|
||||
}
|
||||
|
||||
bus_bridge_pair *find_bridges(struct ptf *p)
|
||||
{
|
||||
bus_bridge_pair *bridges = 0;
|
||||
|
||||
struct ptf system = { section, "SYSTEM", 0, 0, 0 };
|
||||
struct ptf module = { section, "MODULE", 0, 0, 0 };
|
||||
struct ptf slave = { section, "SLAVE", 0, 0, 0 };
|
||||
struct ptf syb = { section, "SYSTEM_BUILDER_INFO", 0, 0, 0 };
|
||||
struct ptf to = { item, "Bridges_To", 0, 0, 0 };
|
||||
struct ptf_item brdg = { 5, &system, &module, &slave, &syb, &to };
|
||||
|
||||
ptf_match(p, &brdg, add_bridge_dest, &bridges);
|
||||
|
||||
return bridges;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef __NIOS2GEN_BRIDGES_H
|
||||
#define __NIOS2GEN_BRIDGES_H 1
|
||||
|
||||
typedef struct bus_bridge_pair
|
||||
{
|
||||
char *mastered_by;
|
||||
char *bridges_to;
|
||||
struct bus_bridge_pair *next;
|
||||
}
|
||||
bus_bridge_pair;
|
||||
|
||||
bus_bridge_pair *find_bridges(struct ptf *p);
|
||||
|
||||
int is_bridged(
|
||||
char *cpu_master,
|
||||
char *dev_master,
|
||||
bus_bridge_pair *bridges);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include "ptf.h"
|
||||
#include "clocks.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void add_clock_spec(struct ptf_item *pi, void *arg)
|
||||
{
|
||||
clock_desc **clocks = arg;
|
||||
clock_desc *new_clock;
|
||||
unsigned long freq;
|
||||
|
||||
new_clock = (clock_desc*)malloc(sizeof(clock_desc));
|
||||
if(new_clock == NULL) return;
|
||||
|
||||
new_clock->freq = strtoul(pi->item[pi->level]->value, 0, 0);
|
||||
printf("freq = %lu (%s?)\n", new_clock->freq, pi->item[pi->level]->value);
|
||||
|
||||
new_clock->cfgname = NULL;
|
||||
new_clock->name = pi->item[pi->level-1]->value;
|
||||
new_clock->next = *clocks;
|
||||
|
||||
|
||||
*clocks = new_clock;
|
||||
}
|
||||
|
||||
void set_clock_cfgname(struct ptf_item *pi, void *arg)
|
||||
{
|
||||
clock_desc *clock = arg;
|
||||
clock->cfgname = pi->item[pi->level]->name;
|
||||
}
|
||||
|
||||
clock_desc *find_clocks( struct ptf *sopc, struct ptf *cfg )
|
||||
{
|
||||
clock_desc *clocks, *reverse;
|
||||
|
||||
struct ptf system = { section, "SYSTEM", 0, 0, 0 };
|
||||
struct ptf wizargs = { section, "WIZARD_SCRIPT_ARGUMENTS", 0, 0, 0 };
|
||||
struct ptf all = { section, "CLOCKS", 0, 0, 0 };
|
||||
struct ptf clock = { section, "CLOCK", 0, 0, 0 };
|
||||
struct ptf freq = { item, "frequency", 0, 0, 0 };
|
||||
struct ptf_item clk_spec = { 5, &system, &wizargs, &all, &clock, &freq };
|
||||
|
||||
struct ptf named = { item, 0, 0, 0, 0 };
|
||||
struct ptf_item clk_cfg = { 2, &all, &named };
|
||||
|
||||
clocks = NULL;
|
||||
ptf_match(sopc, &clk_spec, add_clock_spec, &clocks);
|
||||
|
||||
/* Reverse the linked list and look for configured names */
|
||||
|
||||
reverse = NULL;
|
||||
while(clocks)
|
||||
{
|
||||
clock_desc *tmp = clocks;
|
||||
clocks = clocks->next;
|
||||
tmp->next = reverse;
|
||||
reverse = tmp;
|
||||
|
||||
named.value = tmp->name;
|
||||
ptf_match(cfg, &clk_cfg, set_clock_cfgname, tmp);
|
||||
if(tmp->cfgname == NULL) tmp->cfgname = ptf_defused_name(tmp->name);
|
||||
};
|
||||
|
||||
return reverse;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef __NIOS2GEN_CLOCKS_H
|
||||
#define __NIOS2GEN_CLOCKS_H 1
|
||||
|
||||
#include "ptf.h"
|
||||
|
||||
typedef struct clockdsc
|
||||
{
|
||||
char *name;
|
||||
char *cfgname;
|
||||
unsigned long freq;
|
||||
struct clockdsc *next;
|
||||
}
|
||||
clock_desc;
|
||||
|
||||
clock_desc *find_clocks( struct ptf *ptf, struct ptf *cfg );
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
## Process this file with autoconf to produce a configure script.
|
||||
##
|
||||
## $Id$
|
||||
|
||||
AC_PREREQ(2.59)
|
||||
AC_INIT([rtems-tools-cpu-nios2],[_RTEMS_VERSION],[rtems-bugs@rtems.com])
|
||||
AC_CONFIG_SRCDIR([nios2gen.c])
|
||||
RTEMS_TOP(../../..)
|
||||
|
||||
RTEMS_CANONICAL_TARGET_CPU
|
||||
|
||||
AM_INIT_AUTOMAKE([foreign 1.9])
|
||||
AM_MAINTAINER_MODE
|
||||
|
||||
AC_PROG_CC
|
||||
AC_CHECK_PROGS(HELP2MAN,help2man)
|
||||
AM_CONDITIONAL(HELP2MAN,test -n "$HELP2MAN" )
|
||||
|
||||
RTEMS_TOOLPATHS
|
||||
|
||||
# Explicitly list all Makefiles here
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AC_OUTPUT
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ptf.h"
|
||||
#include "bridges.h"
|
||||
#include "devices.h"
|
||||
|
||||
void add_device(device_desc **dl, struct ptf *dev)
|
||||
{
|
||||
device_desc *eds;
|
||||
|
||||
for(eds = *dl; eds; eds = eds->next)
|
||||
{
|
||||
if(eds->ptf == dev)
|
||||
{
|
||||
eds->slaves++;
|
||||
return;
|
||||
};
|
||||
};
|
||||
|
||||
eds = (device_desc *)malloc(sizeof(device_desc));
|
||||
eds->slaves = 1;
|
||||
eds->ptf = dev;
|
||||
eds->next = *dl;
|
||||
*dl = eds;
|
||||
}
|
||||
|
||||
void check_and_add_device(struct ptf_item *pi, void *arg)
|
||||
{
|
||||
struct ptf *module = pi->item[pi->level-3];
|
||||
struct ptf *sysinfo = pi->item[pi->level-2];
|
||||
char *master_name = pi->item[pi->level]->value;
|
||||
|
||||
struct { char *dm; char *im; device_desc **dl; bus_bridge_pair *bridges; } *dinfo = arg;
|
||||
|
||||
if(is_bridged(dinfo->dm, master_name, dinfo->bridges) ||
|
||||
is_bridged(dinfo->im, master_name, dinfo->bridges))
|
||||
{
|
||||
struct ptf *ni = ptf_alloc_item(item, "N2G_Selected", "1");
|
||||
if(ni != NULL)
|
||||
{
|
||||
ni->next = sysinfo->sub;
|
||||
sysinfo->sub = ni;
|
||||
};
|
||||
add_device(dinfo->dl, module);
|
||||
};
|
||||
}
|
||||
|
||||
void set_dev_cfgname(struct ptf_item *pi, void *arg)
|
||||
{
|
||||
device_desc *dev = arg;
|
||||
dev->cfgname = pi->item[pi->level]->name;
|
||||
}
|
||||
|
||||
|
||||
device_desc *find_devices(
|
||||
struct ptf *ptf,
|
||||
struct ptf *cfg,
|
||||
struct ptf *cpu,
|
||||
bus_bridge_pair *bridges)
|
||||
{
|
||||
struct ptf system = { section, "SYSTEM", 0, 0, 0 };
|
||||
struct ptf module = { section, "MODULE", 0, 0, 0 };
|
||||
struct ptf slave = { section, "SLAVE", 0, 0, 0 };
|
||||
struct ptf syb = { section, "SYSTEM_BUILDER_INFO", 0, 0, 0 };
|
||||
struct ptf maby = { section, "MASTERED_BY", 0, 0, 0 };
|
||||
struct ptf_item brdg = { 5, &system, &module, &slave, &syb, &maby };
|
||||
|
||||
struct ptf modules = { section, "MODULES", 0, 0, 0 };
|
||||
struct ptf named = { item, 0, 0, 0, 0};
|
||||
struct ptf_item devcf = { 2, &modules, &named };
|
||||
|
||||
struct { char *dm; char *im; device_desc **dl; bus_bridge_pair *bridges; } dinfo;
|
||||
|
||||
device_desc *found, *reverse;
|
||||
|
||||
found = NULL;
|
||||
|
||||
add_device(&found, cpu); /* The CPU is "self-connected", add it */
|
||||
|
||||
dinfo.dl = &found;
|
||||
dinfo.bridges = bridges;
|
||||
dinfo.dm = (char *)malloc(strlen(cpu->value)+13);
|
||||
dinfo.im = (char *)malloc(strlen(cpu->value)+20);
|
||||
|
||||
strcpy(dinfo.im, cpu->value);
|
||||
strcat(dinfo.im, "/");
|
||||
strcpy(dinfo.dm, dinfo.im);
|
||||
strcat(dinfo.dm, "data_master");
|
||||
strcat(dinfo.im, "instruction_master");
|
||||
|
||||
/* "Available" is any MODULE with a SLAVE section that is MASTERED_BY
|
||||
either instr_master or data_master of selected CPU, either directly
|
||||
or through a bridge. See code above for more info about bridges.
|
||||
*/
|
||||
|
||||
ptf_match(ptf, &brdg, check_and_add_device, &dinfo);
|
||||
|
||||
free(dinfo.dm);
|
||||
free(dinfo.im);
|
||||
|
||||
/* Reverse the linked list */
|
||||
|
||||
reverse = NULL;
|
||||
while(found)
|
||||
{
|
||||
device_desc *tmp = found;
|
||||
found = found->next;
|
||||
|
||||
tmp->next = reverse;
|
||||
reverse = tmp;
|
||||
|
||||
named.value = tmp->ptf->value;
|
||||
tmp->cfgname = NULL;
|
||||
ptf_match(cfg, &devcf, set_dev_cfgname, tmp);
|
||||
if(tmp->cfgname == NULL) tmp->cfgname = ptf_defused_name(tmp->ptf->value);
|
||||
};
|
||||
|
||||
return reverse;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef __NIOS2GEN_DEVICES_H
|
||||
#define __NIOS2GEN_DEVICES_H 1
|
||||
|
||||
#include "ptf.h"
|
||||
#include "bridges.h"
|
||||
|
||||
typedef struct dev_descr
|
||||
{
|
||||
int slaves;
|
||||
char *cfgname;
|
||||
struct ptf *ptf;
|
||||
struct dev_descr *next;
|
||||
}
|
||||
device_desc;
|
||||
|
||||
device_desc *find_devices(
|
||||
struct ptf *ptf,
|
||||
struct ptf *cfg,
|
||||
struct ptf *cpu,
|
||||
bus_bridge_pair *bridges);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ptf.h"
|
||||
#include "bridges.h"
|
||||
#include "clocks.h"
|
||||
#include "devices.h"
|
||||
#include "output.h"
|
||||
|
||||
/********************************************************/
|
||||
|
||||
void store_ptf_parent(struct ptf_item *pi, void *arg)
|
||||
{
|
||||
struct ptf *p = pi->item[pi->level-1];
|
||||
*(struct ptf **)arg = p;
|
||||
}
|
||||
|
||||
/********************************************************/
|
||||
|
||||
void store_ptf_ptr(struct ptf_item *pi, void *arg)
|
||||
{
|
||||
struct ptf *p = pi->item[pi->level];
|
||||
*(struct ptf **)arg = p;
|
||||
}
|
||||
|
||||
/********************************************************/
|
||||
|
||||
void printf_ptf_value(struct ptf_item *pi, void *arg)
|
||||
{
|
||||
struct ptf *p = pi->item[pi->level];
|
||||
printf(*(char **)arg, p->value);
|
||||
}
|
||||
|
||||
/********************************************************/
|
||||
|
||||
void read_include_file(struct ptf_item *pi, void *arg)
|
||||
{
|
||||
struct ptf *inc, *next;
|
||||
struct ptf *p = pi->item[pi->level];
|
||||
|
||||
inc = ptf_parse_file(p->value);
|
||||
|
||||
if(inc == NULL)
|
||||
{
|
||||
fprintf(stderr, "Warning: couldn't parse included '%s'.\n", p->value);
|
||||
return;
|
||||
};
|
||||
|
||||
printf("Successfully read included PTF file %s.\n", p->value);
|
||||
|
||||
next = p->next;
|
||||
for(p->next = inc; p->next != NULL; p = p->next);
|
||||
p->next = next;
|
||||
}
|
||||
|
||||
void usage()
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Please specify the name of a nios2gen PTF file that describes where to\n"
|
||||
"find the system description PTF from SOPC Builder on the command line.\n");
|
||||
}
|
||||
|
||||
/********************************************************/
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct ptf *sopc, *cfg, *p, *cpu;
|
||||
struct ptf_item pi;
|
||||
device_desc *devices;
|
||||
bus_bridge_pair *bridges;
|
||||
clock_desc *clocks;
|
||||
|
||||
if (argc<2)
|
||||
{
|
||||
usage();
|
||||
return -1;
|
||||
};
|
||||
|
||||
cfg = ptf_parse_file(argv[1]);
|
||||
if(cfg == NULL)
|
||||
{
|
||||
fprintf(stderr, "Couldn't parse '%s'.\n", argv[1]);
|
||||
return -1;
|
||||
};
|
||||
|
||||
printf("Successfully read config PTF file %s.\n", argv[1]);
|
||||
|
||||
/********************************************************/
|
||||
|
||||
{
|
||||
struct ptf include_item = { item, "INCLUDE", 0, 0, 0 };
|
||||
struct ptf_item inc_file_spec = { 1, &include_item };
|
||||
ptf_match(cfg, &inc_file_spec, read_include_file, NULL);
|
||||
}
|
||||
|
||||
/********************************************************/
|
||||
|
||||
{
|
||||
struct ptf *p;
|
||||
struct ptf sopc_ptf_item = { item, "SOPC_PTF", 0, 0, 0 };
|
||||
struct ptf_item sopc_ptf_spec = { 1, &sopc_ptf_item };
|
||||
ptf_match(cfg, &sopc_ptf_spec, store_ptf_ptr, &p);
|
||||
|
||||
if(p == NULL)
|
||||
{
|
||||
fprintf(stderr, "Missing 'SOPC_PTF' filename in %s!\n", argv[1]);
|
||||
return -1;
|
||||
};
|
||||
|
||||
sopc = ptf_parse_file(p->value);
|
||||
if(sopc == NULL)
|
||||
{
|
||||
fprintf(stderr, "Could not parse SOPC_PTF '%s'.\n", p->value);
|
||||
return -1;
|
||||
};
|
||||
|
||||
printf("Successfully read SOPC PTF file %s.\n", p->value);
|
||||
};
|
||||
|
||||
/********************************************************/
|
||||
/* Find CPU */
|
||||
|
||||
printf("Looking for usable CPUs...\n");
|
||||
|
||||
{
|
||||
struct ptf modules = { section, "MODULES", 0, 0, 0 };
|
||||
struct ptf cpu_def = { item, "CPU", 0, 0, 0 };
|
||||
struct ptf_item cpu_spec = { 2, &modules, &cpu_def };
|
||||
|
||||
ptf_match(cfg, &cpu_spec, store_ptf_ptr, &cpu);
|
||||
};
|
||||
|
||||
{
|
||||
int cpu_count;
|
||||
struct ptf system = { section, "SYSTEM", 0, 0, 0 };
|
||||
struct ptf module = { section, "MODULE", 0, 0, 0 };
|
||||
struct ptf nios2_cpu_class = { item, "class", "altera_nios2", 0, 0 };
|
||||
struct ptf_item class_spec = { 3, &system, &module, &nios2_cpu_class };
|
||||
|
||||
if(cpu) if(cpu->value) class_spec.item[1]->value = cpu->value;
|
||||
|
||||
cpu_count = ptf_match(sopc, &class_spec, store_ptf_parent, &cpu);
|
||||
|
||||
if(cpu_count > 1)
|
||||
{
|
||||
printf("There is more than one CPU. Please specify the one\n");
|
||||
printf("you want to use with this BSP in your config file.\n");
|
||||
printf("The available CPUs are named as follows:\n");
|
||||
ptf_match(sopc, &class_spec, printf_ptf_value, " %s\n");
|
||||
return -1;
|
||||
};
|
||||
|
||||
if(cpu_count == 0)
|
||||
{
|
||||
printf("There is no NIOS2 cpu in the system.\n");
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
printf("Using NIOS II CPU '%s'.\n", cpu->value);
|
||||
printf("Only modules mastered by this CPU are considered now.\n");
|
||||
|
||||
/********************************************************/
|
||||
/* Find clocks */
|
||||
|
||||
printf("Looking for clock definitions...\n");
|
||||
|
||||
clocks = find_clocks(sopc, cfg);
|
||||
|
||||
if(clocks)
|
||||
{
|
||||
clock_desc *cs;
|
||||
for(cs = clocks; cs; cs = cs->next)
|
||||
{
|
||||
printf("Found clock: %s (%lu Hz)\n", cs->name, cs->freq);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("No clocks present.\n");
|
||||
};
|
||||
|
||||
/********************************************************/
|
||||
/* Find Bridges */
|
||||
|
||||
printf("Looking for bus bridges...\n");
|
||||
|
||||
bridges = find_bridges(sopc);
|
||||
|
||||
if(bridges)
|
||||
{
|
||||
bus_bridge_pair *bbp;
|
||||
for(bbp = bridges; bbp; bbp=bbp->next)
|
||||
{
|
||||
printf("Found bridge: %s\n", bbp->mastered_by);
|
||||
printf(" \\_%s\n", bbp->bridges_to);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("No bridges present.\n");
|
||||
};
|
||||
|
||||
/********************************************************/
|
||||
/* Find other devices available to the selected CPU */
|
||||
|
||||
devices = find_devices(sopc, cfg, cpu, bridges);
|
||||
|
||||
fwrite_header_file(stdout, cfg, devices, clocks);
|
||||
|
||||
// ptf_printf(stdout, ptf, "");
|
||||
// ptf_printf(stdout, cfg, "");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi:ts=4:
|
||||
*/
|
||||
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ptf.h"
|
||||
#include "devices.h"
|
||||
#include "output.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FILE *file;
|
||||
device_desc *dev;
|
||||
char *def_name;
|
||||
char *orig_value;
|
||||
clock_desc *clocks;
|
||||
device_desc *devices;
|
||||
}
|
||||
out_desc;
|
||||
|
||||
int is_not_connected(struct ptf_item *pi)
|
||||
{
|
||||
if(pi->item[0] == NULL) return 0;
|
||||
if(pi->item[0]->name == NULL) return 0;
|
||||
|
||||
if(strcmp(pi->item[0]->name, "SLAVE") == 0)
|
||||
{
|
||||
struct ptf *t;
|
||||
struct ptf_item ti;
|
||||
t = ptf_find(pi->item[0]->sub, &ti, item, "N2G_Selected", "1");
|
||||
|
||||
if(t == NULL) return 1;
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fwrite_devhead_def(struct ptf_item *pi, void *arg)
|
||||
{
|
||||
out_desc *dinfo = arg;
|
||||
|
||||
if(pi != NULL) if(is_not_connected(pi)) return;
|
||||
|
||||
fprintf(dinfo->file, "#define %s_%s %s\n",
|
||||
dinfo->dev->cfgname, dinfo->def_name, dinfo->orig_value);
|
||||
}
|
||||
|
||||
void fwrite_devhead_line(struct ptf_item *pi, void *arg)
|
||||
{
|
||||
out_desc *dinfo = arg;
|
||||
|
||||
if(is_not_connected(pi)) return;
|
||||
|
||||
if(strncmp(dinfo->orig_value, "N2G_", 4)==0)
|
||||
{
|
||||
if(strncmp(dinfo->orig_value, "N2G_CLOCKREF_", 13)==0)
|
||||
{
|
||||
clock_desc *c;
|
||||
for(c = dinfo->clocks; c; c=c->next)
|
||||
{
|
||||
if(strcmp(c->name, pi->item[pi->level]->value) == 0)
|
||||
{
|
||||
fprintf(dinfo->file, "#define %s_%s %s\n",
|
||||
dinfo->dev->cfgname, dinfo->orig_value + 13, c->cfgname);
|
||||
break;
|
||||
};
|
||||
};
|
||||
}
|
||||
else if(strncmp(dinfo->orig_value, "N2G_DEVICEREF_", 14)==0)
|
||||
{
|
||||
device_desc *d;
|
||||
for(d = dinfo->devices; d; d=d->next)
|
||||
{
|
||||
if(strcmp(d->ptf->value, pi->item[pi->level]->value) == 0)
|
||||
{
|
||||
fprintf(dinfo->file, "#define %s_%s %s\n",
|
||||
dinfo->dev->cfgname, dinfo->orig_value + 14, d->cfgname);
|
||||
break;
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(dinfo->file, "#define %s_%s %s\n",
|
||||
dinfo->dev->cfgname, dinfo->orig_value,
|
||||
pi->item[pi->level]->value);
|
||||
};
|
||||
}
|
||||
|
||||
void fwrite_device_header(struct ptf_item *pi, void *arg)
|
||||
{
|
||||
struct ptf *f;
|
||||
struct ptf_item fi;
|
||||
out_desc *dinfo = arg;
|
||||
|
||||
/* This is called for every matching CLASS section in the
|
||||
configuration. The following loop iterates through all
|
||||
items in the CLASS section regardless of their nesting level */
|
||||
|
||||
f = ptf_find(pi->item[pi->level]->sub, &fi, item, 0, 0);
|
||||
|
||||
while(f != NULL)
|
||||
{
|
||||
dinfo->orig_value = f->value;
|
||||
if(f->name && strncmp(f->name, "N2G_DEFINE_", 11)==0)
|
||||
{
|
||||
dinfo->def_name = f->name + 11;
|
||||
if(fi.level >= 2)
|
||||
{
|
||||
fi.level--; /* match only the enclosing section */
|
||||
ptf_match(dinfo->dev->ptf->sub, &fi, fwrite_devhead_def, dinfo);
|
||||
fi.level++;
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite_devhead_def( 0, dinfo );
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
f->value = 0; /* Match ANY value */
|
||||
ptf_match(dinfo->dev->ptf->sub, &fi, fwrite_devhead_line, dinfo);
|
||||
f->value = dinfo->orig_value;
|
||||
};
|
||||
f = ptf_next(&fi, item, 0, 0);
|
||||
};
|
||||
}
|
||||
|
||||
void fwrite_value(struct ptf_item *pi, void *arg)
|
||||
{
|
||||
FILE *file = arg;
|
||||
fputs(pi->item[pi->level]->value, file);
|
||||
}
|
||||
|
||||
void fwrite_header_file( FILE *file, struct ptf *cfg, device_desc *devices, clock_desc *clocks)
|
||||
{
|
||||
struct ptf *p;
|
||||
struct ptf_item pi;
|
||||
|
||||
struct ptf aclass = { section, "CLASS", 0, 0, 0 };
|
||||
struct ptf_item matchaclass = { 1, &aclass };
|
||||
|
||||
struct ptf header = { item, "HEADER", 0, 0, 0 };
|
||||
struct ptf_item matchheader = { 1, &header };
|
||||
|
||||
struct ptf epilog = { item, "EPILOG", 0, 0, 0 };
|
||||
struct ptf_item matchepilog = { 1, &epilog };
|
||||
|
||||
out_desc dinfo;
|
||||
|
||||
dinfo.file = file;
|
||||
dinfo.clocks = clocks;
|
||||
dinfo.devices = devices;
|
||||
|
||||
ptf_match(cfg, &matchheader, fwrite_value, file);
|
||||
|
||||
if(clocks)
|
||||
{
|
||||
clock_desc *cs;
|
||||
for(cs = clocks; cs; cs = cs->next)
|
||||
{
|
||||
fprintf(file, "#define %s_FREQ %luu\n", cs->cfgname, cs->freq);
|
||||
};
|
||||
};
|
||||
|
||||
if(devices)
|
||||
{
|
||||
for(dinfo.dev = devices; dinfo.dev; dinfo.dev=dinfo.dev->next)
|
||||
{
|
||||
fprintf(file, "\n");
|
||||
|
||||
p = ptf_find(dinfo.dev->ptf, &pi, item, "class", 0);
|
||||
if(p)
|
||||
{
|
||||
aclass.value = p->value;
|
||||
ptf_match(cfg, &matchaclass, fwrite_device_header, &dinfo);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
ptf_match(cfg, &matchepilog, fwrite_value, file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef __OUTPUT_H
|
||||
#define __OUTPUT_H 1
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ptf.h"
|
||||
#include "clocks.h"
|
||||
#include "devices.h"
|
||||
|
||||
void fwrite_header_file(FILE *file, struct ptf *cfg, device_desc *devices, clock_desc *clocks);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#if !defined(__PTF_H)
|
||||
#define __PTF_H 1
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX_SECTION_NESTING 20
|
||||
|
||||
typedef enum
|
||||
{
|
||||
item, section
|
||||
}
|
||||
ptf_item_type;
|
||||
|
||||
struct ptf
|
||||
{
|
||||
ptf_item_type type;
|
||||
char *name;
|
||||
char *value;
|
||||
struct ptf *sub;
|
||||
struct ptf *next;
|
||||
};
|
||||
|
||||
struct ptf_item
|
||||
{
|
||||
int level;
|
||||
struct ptf *item[MAX_SECTION_NESTING];
|
||||
};
|
||||
|
||||
|
||||
typedef void (*ptf_match_action)(struct ptf_item *x, void *arg);
|
||||
|
||||
struct ptf *ptf_parse_file(char *filename);
|
||||
struct ptf *ptf_alloc_item(ptf_item_type t, char *name, char *value);
|
||||
void ptf_printf(FILE *s, struct ptf *tree, char *prefix);
|
||||
|
||||
struct ptf *ptf_find(
|
||||
struct ptf *tree,
|
||||
struct ptf_item *item,
|
||||
ptf_item_type ttype,
|
||||
char *name,
|
||||
char *value);
|
||||
|
||||
struct ptf *ptf_next(
|
||||
struct ptf_item *item,
|
||||
ptf_item_type ttype,
|
||||
char *name,
|
||||
char *value);
|
||||
|
||||
int ptf_match(
|
||||
struct ptf *const ptf,
|
||||
struct ptf_item *const match,
|
||||
const ptf_match_action action,
|
||||
void *arg);
|
||||
|
||||
char *ptf_defused_name(char *);
|
||||
|
||||
|
||||
#endif /* !defined(__PTF_H) */
|
||||
|
||||
Reference in New Issue
Block a user