Changeset 16fd5a9 in rtems


Ignore:
Timestamp:
08/15/06 21:02:55 (17 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
67eede5
Parents:
5f88544
Message:

2006-08-15 Kolja Waschk <kawk@…>

  • linkcmds.c, linkcmds.h, memory.c, memory.h, sample.ptf: New files.
  • bridges.c: corrected detection of bridged connections
  • clocks.c: removed a printf
  • linkcmds.[ch] new files, added output of linker script
  • Makefile.am: added new files
  • memory.[ch]: new files, detection of memory in SOPC configuration
  • nios2gen.c: updated command line parsing and output control
  • output.[ch]: improved output of BSP header file
  • ptf.[ch]: added ptf_dump_ptf_item and small fixes
  • sample.ptf: new file, sample configuration for nios2gen
  • README: updated
Location:
tools/cpu/nios2
Files:
5 added
10 edited

Legend:

Unmodified
Added
Removed
  • tools/cpu/nios2/ChangeLog

    r5f88544 r16fd5a9  
     12006-08-15      Kolja Waschk <kawk@telos.de>
     2
     3        * linkcmds.c, linkcmds.h, memory.c, memory.h, sample.ptf: New files.
     4        * bridges.c: corrected detection of bridged connections
     5        * clocks.c: removed a printf
     6        * linkcmds.[ch] new files, added output of linker script
     7        * Makefile.am: added new files
     8        * memory.[ch]: new files, detection of memory in SOPC configuration
     9        * nios2gen.c: updated command line parsing and output control
     10        * output.[ch]: improved output of BSP header file
     11        * ptf.[ch]: added ptf_dump_ptf_item and small fixes
     12        * sample.ptf: new file, sample configuration for nios2gen
     13        * README: updated
     14
    1152006-08-10      Joel Sherrill <joel@oarcorp.com>
    216
  • tools/cpu/nios2/Makefile.am

    r5f88544 r16fd5a9  
    1212                                   clocks.c clocks.h \
    1313                                   output.c output.h \
     14                                   linkcmds.c linkcmds.h \
     15                                   memory.c memory.h \
    1416                   ptf.h ptf.c
    1517
  • tools/cpu/nios2/README

    r5f88544 r16fd5a9  
    11$Id$
    2 
    3 As an output from SOPC Builder you get a file with extension ".ptf" that fully
    4 describes the SOPC, including all CPUs, memory and integrated peripherals.
    5 
    6 It is structured as
    7 
    8 
    9 
    102
    113nios2gen:
    124  Tool to generate BSP data for boards utilizing NIOS2 soft core processor.
    135
    14 Specify the PTF and name of the CPU (if there are more than one).
     6=================================
     7What it does
     8
     9It creates a sopc.h and linkcmds file for RTEMS nios2 BSPs from one or more inputs:
     10
     111. SOPC System Description PTF
     12
     13As an output from SOPC Builder you get a file with extension ".ptf" that fully
     14describes the SOPC, including all CPUs, memory and integrated peripherals.
     15(PTF simply means "plain-text file").
     16
     172. BSP Configuration PTF
     18
     19This file, using the same format as the SOPC System Description PTF, describes
     20which components of the SOPC shall be used by the BSP. For example, there may
     21be several timers, but a BSP wants at least one named "CLOCK" and optionally
     22another named "TIMER". This mapping can be specified in the BSP.
     23
     24=================================
     25Contents of the configuration PTF
     26
     27There can be definitions of ...
     28
     29HEADER: This is written to sopc.h before anything else. Example:
     30
     31  HEADER = "
     32  #ifndef __SOPC_H
     33  #define __SOPC_H 1
     34  ";
     35
     36EPILOG: This is written to sopc.h after anything else. Example:
     37
     38  EPILOG = "
     39  #endif
     40  ";
     41
     42CLOCKS section: Used to specify names for clocks to be used in definitions in
     43the sopc.h. The default name (if none is specified here) is the uppercased name
     44as in the system description PTF. Specify the name you want on the left, the
     45name in the sopc PTF on the right! Example:
     46
     47  CLOCKS
     48  {
     49    GLOBAL_CLOCK = "sys_clk";
     50  }
     51
     52MODULES section: Same as clocks but for modules / peripherals. As a special definition,
     53if the PTF contains more than one nios2 CPU, it /must/ define a CPU to use. Example to
     54select cpu_0 and rename timer_0 to CLOCK and timer_1 to TIMER:
     55
     56  MODULES
     57  {
     58    CPU = "cpu_0";
     59    CLOCK = "timer_0";
     60    TIMER = "timer_1";
     61  }
     62
     63CLASS xyz sections: These specify what you want in the sopc.h, and how the definitions
     64shall be named. Actually, the CLASS xyz should look exactly like the corresponding MODULE
     65specification in the system description PTF of modules belonging to that class; e.g. a
     66a JTAG UART is originally described like this:
     67
     68   MODULE jtag_uart_0
     69   {
     70      class = "altera_avalon_jtag_uart";
     71      class_version = "1.0";
     72      iss_model_name = "altera_avalon_jtag_uart";
     73      SLAVE avalon_jtag_slave
     74      {
     75         SYSTEM_BUILDER_INFO
     76         {
     77            Bus_Type = "avalon";
     78            Is_Printable_Device = "1";
     79            Address_Alignment = "native";
     80            Address_Width = "1";
     81            Data_Width = "32";
     82            Has_IRQ = "1";
     83            Read_Wait_States = "peripheral_controlled";
     84            Write_Wait_States = "peripheral_controlled";
     85            JTAG_Hub_Base_Id = "0x04006E";
     86            JTAG_Hub_Instance_Id = "0";
     87            MASTERED_BY cpu_0/data_master
     88            {
     89               priority = "1";
     90            }
     91            IRQ_MASTER cpu_0/data_master
     92            {
     93               IRQ_Number = "2";
     94            }
     95            Base_Address = "0x08000000";
     96         }
     97      }
     98      ...
     99   }
     100
     101If you want to have definitions about its base address and irq number in your sopc.h,
     102define a CLASS for altera_avalon_jtag_uart that matches the MODULE description above,
     103but instead of values for the items you specify names to be used in your sopc.h (You
     104can omit items from the MODULE as you like, but the section nesting must match; and
     105section names (such as avalon_jtag_slave for the SLAVE section) also have to match)
     106
     107   CLASS altera_avalon_jtag_uart
     108   {
     109       SLAVE avalon_jtag_slave
     110       {
     111           SYSTEM_BUILDER_INFO
     112           {
     113               Base_Address = "BASE_ADDR";
     114               IRQ_MASTER { IRQ_Number = "IRQ"; }
     115           }
     116       }
     117   }
     118
     119The output for jtag_uart_0 will be:
     120
     121   #define JTAG_UART_BASE_ADDR 0x021208D0
     122   #define JTAG_UART_IRQ 1
     123
     124There are some values with special meaning to nios2gen,
     125
     126N2G_CLOCKREF_CLOCK: This should be used whereever the value in the SOPC PTF
     127specifies the name of a clock. nios2gen will use whatever you  configured for
     128the selected clock in your CLOCKS section.
     129
     130N2G_CLOCKREF_DEVICE: This should be used whereever the value in the SOPC PTF
     131specifies the name of a module. nios2gen will use whatever you  configured for
     132the selected module in your MODULES section.
     133
     134Additionally, you can specify items in your CLASSes so that nios2gen will include
     135constant definitions in the sopc.h whenever such CLASS is present. The format is
     136
     137  N2G_DEFINE_xyz = "123"
     138
     139and will result in
     140
     141#define MODULENAME_xyz 123
    15142
    16143
     
    18145
    19146
     147
     148
  • tools/cpu/nios2/bridges.c

    r5f88544 r16fd5a9  
    3030 */
    3131
     32#include <string.h>
     33#include <stdlib.h>
     34
    3235#include "ptf.h"
    3336#include "bridges.h"
     
    4144  bus_bridge_pair *bbp;
    4245
    43   curr_master = dev_master;
    44   while(curr_master != NULL)
     46  if(strcmp(cpu_master, dev_master) == 0) return 1; /* cpu directly masters dev */
     47
     48  for(bbp = bridges; bbp != NULL; bbp=bbp->next)
    4549  {
    46     /* Does cpu_master master curr_master? */
    47     if(strcmp(cpu_master, curr_master) == 0) return 1; /* yes, cpu_masters cm */
    48 
    49     /* No, cm is attached to a bridge? */
    50     bbp = bridges;
    51     while(bbp != NULL)
     50    if(strcmp(cpu_master, bbp->mastered_by) == 0 &&
     51       is_bridged(bbp->bridges_to, dev_master, bridges))
    5252    {
    53       if(strcmp(bbp->bridges_to, curr_master) == 0)
    54       {
    55         curr_master = bbp->mastered_by;
    56         break;
    57       };
    58       bbp = bbp->next;
    59     };
    60     if(bbp == NULL) curr_master = NULL;
     53      return 1; /* cpu masters dev via bridge */
     54    }
    6155  };
    6256
  • tools/cpu/nios2/clocks.c

    r5f88544 r16fd5a9  
    2424
    2525  new_clock->freq = strtoul(pi->item[pi->level]->value, 0, 0);
    26   printf("freq = %lu (%s?)\n", new_clock->freq, pi->item[pi->level]->value);
    2726
    2827  new_clock->cfgname = NULL;
  • tools/cpu/nios2/nios2gen.c

    r5f88544 r16fd5a9  
    1717#include "clocks.h"
    1818#include "devices.h"
     19#include "memory.h"
    1920#include "output.h"
     21#include "linkcmds.h"
     22
     23#define NIOS2GEN_PACKAGE PACKAGE
     24#define NIOS2GEN_VERSION VERSION
     25
     26#include "getopt.h"
    2027
    2128/********************************************************/
     
    6572}
    6673
    67 void usage()
    68 {
    69 printf(
    70   "Usage: nios2gen [PTFFILE]\n"
    71   "Generate BSP data based upon PTF file from SOPC Builder.\n"
    72   "\n"
    73   "Please specify the name of a nios2gen PTF file that describes where to\n"
    74   "find the system description PTF from SOPC Builder on the command line.\n"
    75 );
    76 }
    77 
    78 void version()
    79 {
    80 printf(
    81   "RTEMS/NIOS nios2gen\n"
     74/********************************************************/
     75
     76void version(FILE *f)
     77{
     78fprintf(f,
     79  "nios2gen (" __DATE__ ")\n"
    8280  "  Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de\n"
    8381  "\n"
     
    8583  "  found in the file LICENSE in this distribution or at\n"
    8684  "  http://www.rtems.com/license/LICENSE.\n"
     85  , VERSION
    8786);
     87}
     88
     89void usage (FILE *f, char *errmsg)
     90{
     91  char *info = "Purpose:\n  Create RTEMS nios2 BSP configuration from Altera SOPC description\n";
     92  if(errmsg) info=errmsg;
     93  version(f);
     94  fprintf(f,"\n%s\nUsage: nios2gen [OPTIONS] <SOPC PTF> [CONFIG PTF] [CONFIG PTF]...\n", info);
     95  fprintf(f,"   -h         --help               Print help and exit\n");
     96  fprintf(f,"   -V         --version            Print version and exit\n");
     97  fprintf(f,"   -bFILENAME --bspheader=FILENAME Output BSP configuration header file (default='sopc.h')\n");
     98  fprintf(f,"   -B         --no-bspheader       Do not output BSP configuration header file\n");
     99  fprintf(f,"   -lFILENAME --linkcmds=FILENAME  Output linker script (default='linkcmds')\n");
     100  fprintf(f,"   -L         --no-linkcmds        Do not output linker script\n");
     101  fprintf(f,"   -pFILENAME --parsed=FILENAME    Output PTF contents as long list (default: don't)\n");
     102  fprintf(f,"   -P         --no-parsed          Do not output PTF contents as long list\n");
     103  fprintf(f,"   -q         --quiet              Do not print progress info to stdout\n\n");
     104  fprintf(f,"Using \"-\" as the FILENAME means standard output (stdout).\n");
    88105}
    89106
     
    97114    bus_bridge_pair *bridges;
    98115    clock_desc *clocks;
    99 
    100     if (argc<2)
    101     {
    102         usage();
     116    memory_desc *memory;
     117
     118    int verbose = 1;
     119    int output_order = 127;
     120    char *parsed_filename = NULL;
     121    int output_parsed = 0;
     122    char *bspheader_filename = "sopc.h";
     123    int output_bspheader = 1;
     124    char *linkcmds_filename = "linkcmds";
     125    int output_linkcmds = 2;
     126
     127    optarg = 0;
     128    optind = 1;
     129    opterr = 1;
     130    optopt = '?';
     131
     132    if(argc > 126)
     133    {
     134      usage(stderr,"Too many commandline arguments!\n");
     135      return -1;
     136    };
     137
     138    while(1)
     139    {
     140      int c, long_index = 0;
     141      static char *optstring = "hVBb:Ll:Pp:q";
     142
     143      static struct option long_options[] =
     144      {
     145        { "help",           0, NULL, 'h' },
     146        { "version",        0, NULL, 'V' },
     147        { "no-bspheader",   0, NULL, 'B' },
     148        { "bspheader",      1, NULL, 'b' },
     149        { "no-linkcmds",    0, NULL, 'L' },
     150        { "linkcmds",       1, NULL, 'l' },
     151        { "no-parsed",      0, NULL, 'P' },
     152        { "parsed",         1, NULL, 'p' },
     153        { "quiet",          0, NULL, 'q' },
     154        { NULL, 0, NULL, 0 }
     155      };
     156
     157      c = getopt_long (argc, argv, optstring, long_options, &long_index);
     158
     159      if(c == -1) break; /* Exit from while(1) loop */
     160
     161      switch(c)
     162      {
     163      case 'q': /* Be quiet */
     164        verbose = 0;
     165        break;
     166
     167      case 'h': /* Print help and exit */
     168        usage(stdout,NULL);
     169        return 0;
     170
     171      case 'V': /* Print version and exit */
     172        version(stdout);
     173        return 0;
     174
     175      case 'B': /* Do not output BSP configuration header file */
     176        output_bspheader = 0;
     177        break;
     178
     179      case 'b': /* Output BSP configuration header file */
     180        bspheader_filename = optarg;
     181        output_bspheader = output_order;
     182        output_order--;
     183        break;
     184
     185      case 'L': /* Do not output linker script */
     186        output_linkcmds = 0;
     187        break;
     188
     189      case 'l': /* Output linker script */
     190        linkcmds_filename = optarg;
     191        output_linkcmds = output_order;
     192        output_order--;
     193        break;
     194
     195      case 'P': /* Do not output PTF contents */
     196        output_parsed = 0;
     197        break;
     198
     199      case 'p': /* Output PTF contents as long list */
     200        parsed_filename = optarg;
     201        output_parsed = output_order;
     202        output_order--;
     203        break;
     204
     205      case 0:
     206      case '?':
    103207        return -1;
    104     };
    105 
    106     if ( !strcmp(argv[1], "--help") || !strcmp(argv[1],"-?") ) {
    107         usage();
    108         return 0;
    109     };
    110 
    111     if ( !strcmp(argv[1], "--version") ) {
    112         version();
    113         return 0;
    114     };
    115 
    116     cfg = ptf_parse_file(argv[1]);
    117     if(cfg == NULL)
    118     {
    119         fprintf(stderr, "Couldn't parse '%s'.\n", argv[1]);
     208
     209      default:
     210        fprintf(stderr, "%s: unknown option: %c\n", NIOS2GEN_PACKAGE, c);
     211      };
     212    };
     213
     214    if(optind >= argc)
     215    {
     216        usage(stderr,"No PTF specified!\n");
    120217        return -1;
    121218    };
    122219
    123     printf("Successfully read config PTF file %s.\n", argv[1]);
    124 
    125     /********************************************************/
     220    /********************************************************/
     221
     222    sopc = ptf_parse_file(argv[optind]);
     223    if(sopc == NULL)
     224    {
     225        fprintf(stderr, "Could not parse system description PTF '%s'.\n", argv[optind]);
     226        return -1;
     227    };
     228
     229    if(verbose) printf("Successfully read SOPC PTF file %s.\n", argv[optind]);
     230
     231    /********************************************************/
     232
     233    cfg = NULL;
     234
     235    for(optind++;optind<argc;optind++)
     236    {
     237      struct ptf *morecfg = ptf_parse_file(argv[optind]);
     238
     239      if(morecfg == NULL)
     240      {
     241        fprintf(stderr, "Couldn't parse '%s'.\n", argv[optind]);
     242        return -1;
     243      };
     244 
     245      if(verbose) printf("Successfully read config PTF file %s.\n", argv[optind]);
     246
     247      cfg = ptf_concat(cfg, morecfg);
     248    };
     249
     250    /********************************************************/
     251    /* Pull in include files specified in the configs; */
     252    /* Only one level is read; included files are not */
     253    /* checked for further INCLUDEs */
    126254
    127255    {
     
    132260
    133261    /********************************************************/
    134    
    135     {
    136       struct ptf *p;
    137       struct ptf sopc_ptf_item = { item, "SOPC_PTF", 0, 0, 0 };
    138       struct ptf_item sopc_ptf_spec = { 1, &sopc_ptf_item };
    139       ptf_match(cfg, &sopc_ptf_spec, store_ptf_ptr, &p);
    140 
    141       if(p == NULL)
    142       {
    143           fprintf(stderr, "Missing 'SOPC_PTF' filename in %s!\n", argv[1]);
    144           return -1;
    145       };
    146 
    147       sopc = ptf_parse_file(p->value);
    148       if(sopc == NULL)
    149       {
    150           fprintf(stderr, "Could not parse SOPC_PTF '%s'.\n", p->value);
    151           return -1;
    152       };
    153 
    154       printf("Successfully read SOPC PTF file %s.\n", p->value);
    155     };
    156 
    157     /********************************************************/
    158262    /* Find CPU */
    159263
    160     printf("Looking for usable CPUs...\n");
    161 
     264    if(verbose) printf("Looking for usable CPUs...\n");
     265
     266    /* Check if a CPU has been specified in the config PTF */
    162267    {
    163268      struct ptf modules         = { section, "MODULES", 0, 0, 0 };
     
    168273    };
    169274
     275    /* Look for CPUs in system description PTF */
    170276    {
    171277      int cpu_count;
     
    181287      if(cpu_count > 1)
    182288      {
    183         printf("There is more than one CPU. Please specify the one\n");
    184         printf("you want to use with this BSP in your config file.\n");
    185         printf("The available CPUs are named as follows:\n");
     289        fprintf(stderr, "There is more than one CPU. Please specify the one\n");
     290        fprintf(stderr, "you want to use with this BSP in your config file.\n");
     291        fprintf(stderr, "The available CPUs are named as follows:\n");
    186292        ptf_match(sopc, &class_spec, printf_ptf_value, "  %s\n");
    187293        return -1; 
     
    190296      if(cpu_count == 0)
    191297      {
    192         printf("There is no NIOS2 cpu in the system.\n");
     298        fprintf(stderr, "There is no NIOS2 cpu in the system.\n");
    193299        return -1; 
    194300      }
    195301    };
    196302
    197     printf("Using NIOS II CPU '%s'.\n", cpu->value);
    198     printf("Only modules mastered by this CPU are considered now.\n");
     303    if(verbose)
     304    {
     305      printf("Using NIOS II CPU '%s'.\n", cpu->value);
     306      printf("Only modules mastered by this CPU are considered now.\n");
     307    };
     308
     309    /********************************************************/
     310    /* Find Bridges */
     311
     312    if(verbose) printf("Looking for bus bridges...\n");
     313
     314    bridges = find_bridges(sopc);
     315
     316    if(verbose)
     317    {
     318      if(bridges)
     319      {
     320        bus_bridge_pair *bbp;
     321        for(bbp = bridges; bbp; bbp=bbp->next)
     322        {
     323          printf("Found bridge: %s\n", bbp->mastered_by);
     324          printf("               \\_%s\n", bbp->bridges_to);
     325        };
     326      }
     327      else
     328      {
     329        printf("No bridges present.\n");
     330      };
     331    };
    199332
    200333    /********************************************************/
    201334    /* Find clocks */
    202335
    203     printf("Looking for clock definitions...\n");
     336    if(verbose) printf("Looking for clock definitions...\n");
    204337
    205338    clocks = find_clocks(sopc, cfg);
    206339
    207     if(clocks)
    208     {
    209       clock_desc *cs;
    210       for(cs = clocks; cs; cs = cs->next)
    211       {
    212         printf("Found clock: %s (%lu Hz)\n", cs->name, cs->freq);
    213       };
    214     }
    215     else
    216     {
    217       printf("No clocks present.\n");
    218     };
    219 
    220     /********************************************************/
    221     /* Find Bridges */
    222 
    223     printf("Looking for bus bridges...\n");
    224 
    225     bridges = find_bridges(sopc);
    226 
    227     if(bridges)
    228     {
    229       bus_bridge_pair *bbp;
    230       for(bbp = bridges; bbp; bbp=bbp->next)
    231       {
    232         printf("Found bridge: %s\n", bbp->mastered_by);
    233         printf("               \\_%s\n", bbp->bridges_to);
    234       };
    235     }
    236     else
    237     {
    238       printf("No bridges present.\n");
     340    if(verbose)
     341    {
     342      if(clocks)
     343      {
     344        clock_desc *cs;
     345        for(cs = clocks; cs; cs = cs->next)
     346        {
     347          printf("Found clock \"%s\" (%lu Hz), naming it %s\n", cs->name, cs->freq, cs->cfgname);
     348        };
     349      }
     350      else
     351      {
     352        printf("No clocks present.\n");
     353      };
    239354    };
    240355
     
    242357    /* Find other devices available to the selected CPU */
    243358
     359    if(verbose) printf("Looking for devices...\n");
     360
    244361    devices = find_devices(sopc, cfg, cpu, bridges);
    245362
    246     fwrite_header_file(stdout, cfg, devices, clocks);
    247 
    248     // ptf_printf(stdout, ptf, "");
    249     // ptf_printf(stdout, cfg, "");
     363    if(verbose)
     364    {
     365      if(devices)
     366      {
     367        device_desc *dd;
     368        for(dd = devices; dd; dd=dd->next)
     369        {
     370          printf("Found device \"%s\", naming it %s\n", dd->ptf->value, dd->cfgname);
     371        };
     372      }
     373      else
     374      {
     375        printf("No devices present.\n");
     376      };
     377    };
     378
     379    /********************************************************/
     380    /* Find out which devices are actually memory */
     381
     382    if(verbose) printf("Looking for memory...\n");
     383
     384    memory = find_memory(devices);
     385   
     386    if(verbose)
     387    {
     388      if(memory)
     389      {
     390        memory_desc *md;
     391        for(md = memory; md; md=md->next)
     392        {
     393          printf("Found memory in \"%s\", base=0x%08X, size=%lu bytes\n",
     394                          md->dev->cfgname,
     395                          md->base, md->size);
     396        };
     397      }
     398      else
     399      {
     400        printf("None of the devices seems to provide memory?!\n");
     401      };
     402    };
     403
     404
     405    /********************************************************/
     406    /* Output files in the order they were specified
     407       on the command line */
     408
     409    {
     410      int i;
     411      for(i=0;i<3;i++)
     412      {
     413        if(output_bspheader>0
     414           && output_bspheader>=output_linkcmds
     415           && output_bspheader>=output_parsed)
     416        {
     417          output_bspheader = 0;
     418          if(bspheader_filename == NULL || (bspheader_filename[0]=='-' && bspheader_filename[1]==0))
     419          {
     420            fwrite_header_file(stdout, cfg, devices, clocks);
     421          }
     422          else
     423          {
     424            FILE *f = fopen(bspheader_filename, "w");
     425            if(!f)
     426            {
     427              perror(bspheader_filename);
     428              return -1;
     429            }
     430            else
     431            {
     432              fwrite_header_file(f, cfg, devices, clocks);
     433              fclose(f);
     434            }
     435          }
     436        };
     437        if(output_linkcmds>0
     438           && output_linkcmds>=output_bspheader
     439           && output_linkcmds>=output_parsed)
     440        {
     441          output_linkcmds = 0;
     442          if(linkcmds_filename == NULL || (linkcmds_filename[0]=='-' && linkcmds_filename[1]==0))
     443          {
     444            fwrite_linkcmds_file(stdout, cfg, cpu, devices, memory);
     445          }
     446          else
     447          {
     448            FILE *f = fopen(linkcmds_filename, "w");
     449            if(!f)
     450            {
     451              perror(linkcmds_filename);
     452              return -1;
     453            }
     454            else
     455            {
     456              fwrite_linkcmds_file(f, cfg, cpu, devices, memory);
     457              fclose(f);
     458            }
     459          }
     460        };
     461        if(output_parsed>0
     462           && output_parsed>=output_linkcmds
     463           && output_parsed>=output_bspheader)
     464        {
     465          output_parsed = 0;
     466          if(parsed_filename == NULL || (parsed_filename[0]=='-' && parsed_filename[1]==0))
     467          {
     468            ptf_printf(stdout, sopc, "");
     469          }
     470          else
     471          {
     472            FILE *f = fopen(parsed_filename, "w");
     473            if(!f)
     474            {
     475              perror(parsed_filename);
     476              return -1;
     477            }
     478            else
     479            {
     480              ptf_printf(f, sopc, "");
     481              fclose(f);
     482            }
     483          }
     484        };
     485      }
     486    };
     487
     488    if(verbose) printf("Done.\n");
    250489
    251490    return 0;
  • tools/cpu/nios2/output.c

    r5f88544 r16fd5a9  
    151151  struct ptf_item matchaclass = { 1, &aclass };
    152152
    153   struct ptf header = { item, "HEADER", 0, 0, 0 };
    154   struct ptf_item matchheader = { 1, &header };
     153  struct ptf bspsect = { section, "BSPHEADER", 0, 0, 0 };
     154  struct ptf leadtext = { item, "LEADTEXT", 0, 0, 0 };
     155  struct ptf_item matchleadtext = { 2, &bspsect, &leadtext };
    155156
    156157  struct ptf epilog = { item, "EPILOG", 0, 0, 0 };
    157   struct ptf_item matchepilog = { 1, &epilog };
     158  struct ptf_item matchepilog = { 2, &bspsect, &epilog };
    158159
    159160  out_desc dinfo;
     
    163164  dinfo.devices = devices;
    164165
    165   ptf_match(cfg, &matchheader, fwrite_value, file);
     166  ptf_match(cfg, &matchleadtext, fwrite_value, file);
    166167
    167168  if(clocks)
     
    178179    for(dinfo.dev = devices; dinfo.dev; dinfo.dev=dinfo.dev->next)
    179180    {
    180       fprintf(file, "\n");
     181      /* fprintf(file, "\n#define SOPC_HAS_%s 1\n", dinfo.dev->cfgname); */
    181182
    182183      p = ptf_find(dinfo.dev->ptf, &pi, item, "class", 0);
     
    192193}
    193194
    194 
    195195 
  • tools/cpu/nios2/output.h

    r5f88544 r16fd5a9  
    2020#include "devices.h"
    2121
     22void fwrite_value(struct ptf_item *pi, void *arg);
    2223void fwrite_header_file(FILE *file, struct ptf *cfg, device_desc *devices, clock_desc *clocks);
    2324
  • tools/cpu/nios2/ptf.c

    r5f88544 r16fd5a9  
    1010
    1111#include <stdio.h>
     12#include <string.h>
    1213#include <errno.h>
    1314#include "ptf.h"
     
    365366    default:
    366367#if DEBUG&DEBUG_EXPECTATIONS
    367       printf("Expectation: %d (???)\n", state->expectation);
     368      printf("Expectation: %d (?)\n", state->expectation);
    368369#endif
    369370
     
    507508
    508509  return state.tree;
     510}
     511
     512/***************************************************************************/
     513
     514struct ptf *ptf_concat(struct ptf *a, struct ptf *b)
     515{
     516  struct ptf *leaf = a;
     517
     518  if(!a) return b;
     519  if(!b) return a;
     520
     521  for(leaf = a; leaf->next != NULL; leaf = leaf->next);
     522  leaf->next = b;
     523  return a;
     524}
     525
     526/***************************************************************************/
     527
     528void ptf_dump_ptf_item(FILE *f, struct ptf_item *pi)
     529{
     530  int i;
     531  fprintf(f, "level=%d in %p\n", pi->level, pi);
     532  for(i=pi->level;i>=0;i--)
     533  {
     534    if(pi->item[i] != NULL)
     535    {
     536      fprintf(f, "  %d: %s name=%s value=%s\n",
     537        i,
     538        pi->item[i]->type == item ? "item":"section",
     539        pi->item[i]->name,
     540        pi->item[i]->value);
     541    }
     542    else
     543    {
     544        fprintf(f, "  %d: NULL\n");
     545    }
     546    fflush(f);
     547  }
    509548}
    510549
     
    533572        if(leaf->value != NULL && leaf->value[0] != 0)
    534573        {
    535           strcat(new_prefix, "_");
     574          strcat(new_prefix, ":");
    536575          strcat(new_prefix, leaf->value);
    537576        };
    538577        strcat(new_prefix, "/");
    539578        fputs(new_prefix, s);
    540         fputs("\r\n", s);
     579        fputs("\n", s);
    541580        ptf_printf(s, leaf->sub, new_prefix);
    542581        break;
     
    549588        fputs(leaf->name, s);
    550589        fputs(" = \"", s);
    551         for(c=leaf->value; *c; c++)
    552         {
    553           if(*c=='\\' || *c=='"') putc('\\', s);
    554           putc(*c, s);
    555         };
    556         fprintf(s, "\"\r\n");
     590        if(leaf->value == NULL)
     591        {
     592          fputs("(NULL)", s);
     593        }
     594        else
     595        {
     596          for(c=leaf->value; *c; c++)
     597          {
     598            if(*c=='\\' || *c=='"') putc('\\', s);
     599            putc(*c, s);
     600          };
     601        }
     602        fprintf(s, "\"\n");
    557603        break;
    558604      };
  • tools/cpu/nios2/ptf.h

    r5f88544 r16fd5a9  
    4141
    4242struct ptf *ptf_parse_file(char *filename);
     43struct ptf *ptf_concat(struct ptf *a, struct ptf *b);
    4344struct ptf *ptf_alloc_item(ptf_item_type t, char *name, char *value);
    4445void ptf_printf(FILE *s, struct ptf *tree, char *prefix);
     46void ptf_dump_ptf_item(FILE *s, struct ptf_item *pi);
    4547
    4648struct ptf *ptf_find(
Note: See TracChangeset for help on using the changeset viewer.