OpenCores
URL https://opencores.org/ocsvn/or1k_soc_on_altera_embedded_dev_kit/or1k_soc_on_altera_embedded_dev_kit/trunk

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [soc/] [sw/] [adv_jtag_bridge/] [bsdl.c] - Diff between revs 12 and 21

Show entire file | Details | Blame | View Log

Rev 12 Rev 21
Line 1... Line 1...
/* bsdl.c - BSDL file handler for the advanced JTAG bridge
/* bsdl.c - BSDL file handler for the advanced JTAG bridge
   Copyright(C) 2008 Nathan Yawn
   Copyright(C) 2008 - 2010 Nathan Yawn
 
 
   This program is free software; you can redistribute it and/or modify
   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
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   (at your option) any later version.
Line 18... Line 18...
 
 
#include <sys/types.h>
#include <sys/types.h>
#include <string.h>
#include <string.h>
#include <stdio.h>
#include <stdio.h>
#include <dirent.h>
#include <dirent.h>
 
#include <stdlib.h>
 
#include <errno.h>
#include "bsdl.h"
#include "bsdl.h"
#include "bsdl_parse.h"
#include "bsdl_parse.h"
 
 
 
 
#define debug(...) //fprintf(stderr, __VA_ARGS__ ) 
#define debug(...) //fprintf(stderr, __VA_ARGS__ ) 
Line 37... Line 39...
// Globals to hold BSDL info
// Globals to hold BSDL info
static bsdlinfo *bsdl_head = NULL;
static bsdlinfo *bsdl_head = NULL;
static bsdlinfo *bsdl_tail = NULL;
static bsdlinfo *bsdl_tail = NULL;
static bsdlinfo *bsdl_last = NULL;  // optimization: pointer to the last struct we used (not necessarily the last in the linked list)
static bsdlinfo *bsdl_last = NULL;  // optimization: pointer to the last struct we used (not necessarily the last in the linked list)
 
 
 
// Scratchpad for full pathname
 
int bsdl_scratchpad_size = 0;
 
char *bsdl_scratchpad = NULL;
 
 
// Prototypes for local functions
// Prototypes for local functions
bsdlinfo *get_bsdl_info(uint32_t idcode);
bsdlinfo *get_bsdl_info(uint32_t idcode);
 
 
 
 
 
 
Line 52... Line 58...
  bsdl_dirs[0] = strdup("/opt/bsdl");
  bsdl_dirs[0] = strdup("/opt/bsdl");
  bsdl_dirs[1] = strdup("/usr/share/bsdl");
  bsdl_dirs[1] = strdup("/usr/share/bsdl");
  bsdl_dirs[2] = strdup("~/.bsdl");
  bsdl_dirs[2] = strdup("~/.bsdl");
  bsdl_dirs[3] = strdup(".");
  bsdl_dirs[3] = strdup(".");
  bsdl_current_dir = 3;
  bsdl_current_dir = 3;
 
  bsdl_scratchpad = (char *) malloc(64);
 
  bsdl_scratchpad_size = 64;
}
}
 
 
void bsdl_add_directory(const char *dirname)
void bsdl_add_directory(const char *dirname)
{
{
  if(bsdl_current_dir >= (MAX_BSDL_DIRS-1)) {
  if(bsdl_current_dir >= (MAX_BSDL_DIRS-1)) {
Line 173... Line 181...
          if(bsdl_current_dir < 0)
          if(bsdl_current_dir < 0)
            return NULL;  // There are no more directories to check
            return NULL;  // There are no more directories to check
          debug("Trying BSDL dir \'%s\'\n", bsdl_dirs[bsdl_current_dir]);
          debug("Trying BSDL dir \'%s\'\n", bsdl_dirs[bsdl_current_dir]);
          bsdl_open_dir = opendir(bsdl_dirs[bsdl_current_dir]);
          bsdl_open_dir = opendir(bsdl_dirs[bsdl_current_dir]);
          if((bsdl_open_dir == NULL) && (bsdl_current_dir > 2))  // Don't warn if default dirs not found
          if((bsdl_open_dir == NULL) && (bsdl_current_dir > 2))  // Don't warn if default dirs not found
            printf("Warning: unable to open BSDL directory \'%s\'\n", bsdl_dirs[bsdl_current_dir]);
            printf("Warning: unable to open BSDL directory \'%s\': %s\n", bsdl_dirs[bsdl_current_dir], strerror(errno));
          bsdl_current_dir--;
          bsdl_current_dir--;
          direntry = NULL;
          direntry = NULL;
        }
        }
 
 
      // Find a BSDL file
      // Find a BSDL file
      do
      do
        {
        {
          direntry = readdir(bsdl_open_dir);
          direntry = readdir(bsdl_open_dir);
          if(direntry == NULL)
          if(direntry == NULL)
            {  // We've exhausted this directory
            {  // We've exhausted this directory
 
              debug("Next bsdl directory\n");
              closedir(bsdl_open_dir);
              closedir(bsdl_open_dir);
              bsdl_open_dir = NULL;
              bsdl_open_dir = NULL;
              break;
              break;
            }
            }
 
 
Line 206... Line 215...
      while(1);
      while(1);
 
 
      if(direntry == NULL)  // We need a new directory
      if(direntry == NULL)  // We need a new directory
        continue;
        continue;
 
 
 
      // Make sure we can hold the full path
 
      if((strlen(direntry->d_name) + strlen(bsdl_dirs[bsdl_current_dir+1])+1) >= bsdl_scratchpad_size)
 
        {
 
          char *tmp = (char *) realloc(bsdl_scratchpad, (bsdl_scratchpad_size*2));
 
          if(tmp != NULL)
 
            {
 
              debug("Extending bsdl scratchpad to size %i", bsdl_scratchpad_size);
 
              bsdl_scratchpad_size *= 2;
 
              bsdl_scratchpad = tmp;
 
            }
 
          else
 
            {
 
              fprintf(stderr, "Warning: failed to reallocate BSDL scratchpad to size %i", bsdl_scratchpad_size*2);
 
              continue;
 
            }
 
        }
 
 
 
      strcpy(bsdl_scratchpad, bsdl_dirs[bsdl_current_dir+1]);
 
      strcat(bsdl_scratchpad, "/");
 
      strcat(bsdl_scratchpad, direntry->d_name);
 
 
      // Parse the BSDL file we found
      // Parse the BSDL file we found
      debug("Parsing file \'%s\'\n", direntry->d_name);
      debug("Parsing file \'%s\'\n", bsdl_scratchpad);
      ptr = parse_extract_values(direntry->d_name);
      ptr = parse_extract_values(bsdl_scratchpad);
 
 
      // If we got good data...
      // If we got good data...
      if(ptr != NULL)
      if(ptr != NULL)
        {
        {
          // Store the values...
          // Store the values...

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.