Exemple #1
0
def fetch(args):
    core = CoreManager().get_core(args.core)
    if core:
        cores = CoreManager().get_depends(core.name)
        try:
            core.setup()
        except URLError as e:
            pr_err("Problem while fetching '" + core.name + "': " +
                   str(e.reason))
            exit(1)
        except HTTPError as e:
            pr_err("Problem while fetching '" + core.name + "': " +
                   str(e.reason))
            exit(1)
        for name in cores:
            pr_info("Fetching " + name)
            core = CoreManager().get_core(name)
            try:
                core.setup()
            except URLError as e:
                pr_err("Problem while fetching '" + core.name + "': " +
                       str(e.reason))
                exit(1)
            except HTTPError as e:
                pr_err("Problem while fetching '" + core.name + "': " +
                       str(e.reason))
                exit(1)
    else:
        pr_err("Can't find core '" + args.core + "'")
Exemple #2
0
def fetch(args):
    core = CoreManager().get_core(args.core)
    if core:
        cores = CoreManager().get_depends(core.name)
        try:
            core.setup()
        except URLError as e:
            pr_err("Problem while fetching '" + core.name + "': " + str(e.reason))
            exit(1)
        except HTTPError as e:
            pr_err("Problem while fetching '" + core.name + "': " + str(e.reason))
            exit(1)
        for name in cores:
             pr_info("Fetching " + name)
             core = CoreManager().get_core(name)
             try:
                 core.setup()
             except URLError as e:
                 pr_err("Problem while fetching '" + core.name + "': " + str(e.reason))
                 exit(1)
             except HTTPError as e:
                 pr_err("Problem while fetching '" + core.name + "': " + str(e.reason))
                 exit(1)
    else:
        pr_err("Can't find core '" + args.core + "'")
Exemple #3
0
    def _verilate(self):
        if self.src_type == 'systemC':
            args = ['--sc']
        else:
            args = ['--cc']
        args += ['-f', self.verilator_file]
        args += ['--top-module', self.top_module]
        args += ['--exe']
        args += ['-LDFLAGS "']
        args += ['-Wl,--start-group']
        args += [os.path.join(self.sim_root, s) for s in self.archives]
        args += ['-Wl,--end-group']
        args += [l for l in self.libs]
        args += ['"']
        args += ['-CFLAGS ' + '-I' + i for i in self.include_dirs]
        args += [os.path.join(self.src_root, self.system.name, self.tb_toplevel)]
        args += self.verilator_options

        cmd = utils.find_verilator()
        if cmd is None:
             raise RuntimeError("VERILATOR_ROOT not set and there is no verilator program in your PATH")
        cmd += ' ' + ' '.join(args)
        l = utils.Launcher(cmd,
                           shell=True,
                           cwd = self.sim_root,
                           stderr = open(os.path.join(self.sim_root,'verilator.log'),'w')
        )
        print('')
        pr_info("Starting Verilator:")
        print(l)
        print('')
        l.run()
Exemple #4
0
    def _checkout(self, local_dir, core_name):
        pr_info("Checking out " + self.url + " to " + local_dir)
        try:
            (filename, headers) = urllib.urlretrieve(self.url)
        except urllib.URLError:
            raise
        except urllib.HTTPError:
            raise

        (cache_root, core) = os.path.split(local_dir)

        if self.filetype == 'tar':
            t = tarfile.open(filename)
            t.extractall(os.path.join(cache_root, core_name))
        elif self.filetype == 'zip':
            with zipfile.ZipFile(filename, "r") as z:
                z.extractall(os.path.join(cache_root, core_name))
        elif self.filetype == 'simple':
            # Splits the string at the last occurrence of sep, and
            # returns a 3-tuple containing the part before the separator,
            # the separator itself, and the part after the separator.
            # If the separator is not found, return a 3-tuple containing
            # two empty strings, followed by the string itself
            segments = self.url.rpartition('/')
            self.path = os.path.join(cache_root, core_name)
            os.makedirs(self.path)
            self.path = os.path.join(self.path, segments[2])
            shutil.copy2(filename, self.path)
        else:
            raise RuntimeError("Unknown file type '" + self.filetype + "' in [provider] section")
Exemple #5
0
    def run(self, args):
        logger.debug('run() *Entered*')

        parser = argparse.ArgumentParser(prog ='fusesoc sim '+self.system.name, conflict_handler='resolve')
        for name in self.cores:
            core = self.cm.get_core(name)
            if core.plusargs:
                core.plusargs.add_arguments(parser)

        p = parser.parse_args(args)

        self.plusargs = []
        for key,value in vars(p).items():
            if value == True:
                self.plusargs += [key]
            elif value == False or value is None:
                pass
            else:
                self.plusargs += [key+'='+str(value[0])]

        for script in self.system.pre_run_scripts:
            script = os.path.abspath(os.path.join(self.system.core_root, script))
            pr_info("Running " + script);
            try:
                Launcher(script, cwd = self.sim_root, env = self.env, shell=True).run()
            except RuntimeError:
                print("Error: script " + script + " failed")
Exemple #6
0
    def build(self):
        super(Verilator, self).build()
        self.archives = []
        for core_name in self.cores:
            core = self.cm.get_core(core_name)
            if core.verilator:
                 if core.verilator.archive:
                      self.archives += [core_name+'.a']
                 self.libs += core.verilator.libs
                 self.include_dirs += [os.path.join(self.src_root, core_name, d) for d in core.verilator.include_dirs]
                 self.include_dirs += [os.path.dirname(os.path.join(self.sim_root, self.tb_toplevel))]

        self.include_dirs += [self.src_root]
        pr_info("Verilating source")
        self._verilate()
        for core_name in self.cores:
            core = self.cm.get_core(core_name)
            if core.verilator:
                 core.verilator.build(core_name, self.sim_root, self.src_root)

        pr_info("Building verilator executable:")
        args = ['-f', 'V' + self.top_module + '.mk', 'V' + self.top_module]
        utils.Launcher('make', args,
                       cwd=os.path.join(self.sim_root, 'obj_dir'),
                       stdout = open(os.path.join(self.sim_root, 'verilator.make.log'),'w')).run()
Exemple #7
0
    def configure(self):
        if os.path.exists(self.sim_root):
            for f in os.listdir(self.sim_root):
                if os.path.isdir(os.path.join(self.sim_root, f)):
                    shutil.rmtree(os.path.join(self.sim_root, f))
                else:
                    os.remove(os.path.join(self.sim_root, f))
        else:
            os.makedirs(self.sim_root)

        self.env['SIM_ROOT'] = os.path.abspath(self.sim_root)

        for name in self.cores:
            pr_info("Preparing " + name)
            dst_dir = os.path.join(Config().build_root, self.system.name,
                                   'src', name)
            core = self.cm.get_core(name)
            try:
                core.setup()
            except urllib.URLError as e:
                raise RuntimeError("Problem while fetching '" + core.name +
                                   "': " + str(e.reason))
            except urllib.HTTPError as e:
                raise RuntimeError("Problem while fetching '" + core.name +
                                   "': " + str(e.reason))
            core.export(dst_dir)
Exemple #8
0
    def build_SysC(self, core, sim_root, src_root):
        verilator_root = utils.get_verilator_root()
        args = ['-I.']
        args += ['-MMD']
        args += ['-I'+src_root]
        args += ['-I'+s for s in self.include_dirs]
        args += ['-Iobj_dir']
        args += ['-I'+os.path.join(verilator_root,'include')]
        args += ['-I'+os.path.join(verilator_root,'include', 'vltstd')]  
        args += ['-DVL_PRINTF=printf']
        args += ['-DVM_TRACE=1']
        args += ['-DVM_COVERAGE=0']
        if os.getenv('SYSTEMC_INCLUDE'):
            args += ['-I'+os.getenv('SYSTEMC_INCLUDE')]
        if os.getenv('SYSTEMC'):
            args += ['-I'+os.path.join(os.getenv('SYSTEMC'),'include')]
        args += ['-Wno-deprecated']
        if os.getenv('SYSTEMC_CXX_FLAGS'):
             args += [os.getenv('SYSTEMC_CXX_FLAGS')]
        args += ['-c']
        args += ['-g']

        for src_file in self.src_files:
            pr_info("Compiling " + src_file)
            l = Launcher('g++', args + [os.path.join(src_root, core, src_file)],
                         cwd=sim_root)
            print(l)
            l.run()
Exemple #9
0
    def configure(self, args):
        if os.path.exists(self.work_root):
            for f in os.listdir(self.work_root):
                if os.path.isdir(os.path.join(self.work_root, f)):
                    shutil.rmtree(os.path.join(self.work_root, f))
                else:
                    os.remove(os.path.join(self.work_root, f))
        else:
            os.makedirs(self.work_root)

        for name in self.cores:
            pr_info("Preparing " + str(name))
            core = self.cm.get_core(name)
            dst_dir = os.path.join(Config().build_root,
                                   self.system.sanitized_name, 'src',
                                   core.sanitized_name)
            try:
                core.setup()
            except URLError as e:
                raise RuntimeError("Problem while fetching '" + core.name +
                                   "': " + str(e.reason))
            except HTTPError as e:
                raise RuntimeError("Problem while fetching '" + core.name +
                                   "': " + str(e.reason))
            core.export(dst_dir)
Exemple #10
0
    def run(self, args):

        parser = argparse.ArgumentParser(prog ='fusesoc sim '+self.system.name, conflict_handler='resolve')
        for name in self.cores:
            core = self.cm.get_core(name)
            if core.plusargs:
                core.plusargs.add_arguments(parser)

        p = parser.parse_args(args)

        self.plusargs = []
        for key,value in vars(p).items():
            if value == True:
                self.plusargs += [key]
            elif value == False or value is None:
                pass
            else:
                self.plusargs += [key+'='+str(value[0])]

        for script in self.system.pre_run_scripts:
            script = os.path.abspath(os.path.join(self.system.core_root, script))
            pr_info("Running " + script);
            try:
                Launcher(script, cwd = self.sim_root, env = self.env, shell=True).run()
            except RuntimeError:
                pr_err("Error: script " + script + " failed")
Exemple #11
0
 def done(self):
     for script in self.system.post_build_scripts:
         script = os.path.abspath(os.path.join(self.systems_root, self.system.name, script))
         pr_info("Running " + script);
         try:
             Launcher(script, cwd = os.path.abspath(self.build_root), env = self.env, shell=True).run()
         except RuntimeError:
             print("Error: script " + script + " failed")
Exemple #12
0
    def done(self, args):

        for script in self.system.post_run_scripts:
            script = os.path.abspath(os.path.join(self.system.core_root, script))
            pr_info("Running " + script);
            try:
                Launcher(script, cwd = self.sim_root, env = self.env, shell=True).run()
            except RuntimeError:
                pr_err("Error: script " + script + " failed")
Exemple #13
0
    def _checkout(self, local_dir):
        pr_info("Downloading " + self.repo_name + " from OpenCores")

        Launcher('svn', ['co', '-q', '--no-auth-cache',
                         '-r', self.revision_number,
                         '--username', 'orpsoc',
                         '--password', 'orpsoc',
                         self.repo_path,
                         local_dir]).run()
Exemple #14
0
    def _checkout(self, local_dir):
        pr_info("Checking out " + self.repo_path + " revision " + self.revision_number + " to " + local_dir)

        Launcher('svn', ['co', '-q', '--no-auth-cache',
                         '-r', self.revision_number,
                         '--username', 'orpsoc',
                         '--password', 'orpsoc',
                         self.repo_path,
                         local_dir]).run()
Exemple #15
0
 def build(self):
     for script in self.system.pre_build_scripts:
         script = os.path.abspath(os.path.join(self.system.core_root, script))
         pr_info("Running " + script);
         try:
             Launcher(script, cwd = self.sim_root, env = self.env, shell=True).run()
         except RuntimeError:
             pr_err("Error: script " + script + " failed")
     return
Exemple #16
0
    def _checkout(self, local_dir):

        #TODO : Sanitize URL
        pr_info("Checking out " + self.repo + " to " + local_dir)
        args = ['clone', '-q', self.repo, local_dir]
        Launcher('git', args).run()
        if self.version:
            args = ['-C', local_dir, 'checkout', '-q', self.version]
            Launcher('git', args).run()
Exemple #17
0
    def _checkout(self, local_dir):
        pr_info("Checking out " + self.repo_path + " revision " +
                self.revision_number + " to " + local_dir)

        Launcher('svn', [
            'co', '-q', '--no-auth-cache', '-r', self.revision_number,
            '--username', 'orpsoc', '--password', 'orpsoc', self.repo_path,
            local_dir
        ]).run()
Exemple #18
0
 def done(self):
     if not self.system.scripts:
         return
     for script in self.system.scripts.post_impl_scripts:
         script = os.path.abspath(os.path.join(self.system.files_root, script))
         pr_info("Running " + script);
         try:
             Launcher(script, cwd = os.path.abspath(self.work_root), env = self.env, shell=True).run()
         except RuntimeError:
             print("Error: script " + script + " failed")
Exemple #19
0
 def configure(self):
     if os.path.exists(self.work_root): 
         shutil.rmtree(self.work_root)
     os.makedirs(self.work_root)
     cm = CoreManager()
     for name in self.cores:
         pr_info("Preparing " + name)
         core = cm.get_core(name)
         dst_dir = os.path.join(Config().build_root, self.system.name, 'src', name)
         core.setup()
         core.export(dst_dir)
Exemple #20
0
    def done(self, args):

        for script in self.system.post_run_scripts:
            script = os.path.abspath(
                os.path.join(self.system.core_root, script))
            pr_info("Running " + script)
            try:
                Launcher(script, cwd=self.sim_root, env=self.env,
                         shell=True).run()
            except RuntimeError:
                pr_err("Error: script " + script + " failed")
Exemple #21
0
 def run(self, args):
     self.env = os.environ.copy()
     self.env['CORE_ROOT'] = os.path.abspath(self.system.core_root)
     self.env['BUILD_ROOT'] = os.path.abspath(self.build_root)
     self.env['SIM_ROOT'] = os.path.abspath(self.sim_root)
     #TODO: Handle arguments parsing
     pr_info("Running simulation")
     utils.Launcher('./V' + self.top_module,
                    args,
                    cwd=os.path.join(self.sim_root, 'obj_dir'),
                    env=self.env).run()
Exemple #22
0
 def done(self):
     for script in self.system.post_build_scripts:
         script = os.path.abspath(os.path.join(self.system_root, script))
         pr_info("Running " + script)
         try:
             Launcher(script,
                      cwd=os.path.abspath(self.build_root),
                      env=self.env,
                      shell=True).run()
         except RuntimeError:
             print("Error: script " + script + " failed")
Exemple #23
0
    def _checkout(self, local_dir):
        logger.debug('_checkout() *Entered*')
        pr_info("Checking out " + self.repo_path + " revision " + self.revision_number + " to " + local_dir)

        Launcher('svn', ['co', '-q', '--no-auth-cache',
                         '-r', self.revision_number,
                         '--username', 'orpsoc',
                         '--password', 'orpsoc',
                         self.repo_path,
                         local_dir]).run()

        logger.debug('_checkout() -Done-')
Exemple #24
0
 def build_C(self, core, sim_root, src_root):
     args = ['-c']
     args += ['-std=c99']
     args += ['-I'+src_root]
     args += ['-I'+os.path.join(src_root, core, s) for s in self.include_dirs]
     for src_file in self.src_files:
         pr_info("Compiling " + src_file)
         l = Launcher('gcc',
                  args + [os.path.join(src_root, core, src_file)],
                  cwd=sim_root)
         print(l)
         l.run()
Exemple #25
0
 def configure(self):
     if os.path.exists(self.work_root):
         shutil.rmtree(self.work_root)
     os.makedirs(self.work_root)
     cm = CoreManager()
     for name in self.cores:
         pr_info("Preparing " + name)
         core = cm.get_core(name)
         dst_dir = os.path.join(Config().build_root, self.system.name,
                                'src', name)
         core.setup()
         core.export(dst_dir)
Exemple #26
0
 def build_C(self, core, sim_root, src_root):
     args = ['-c']
     args += ['-std=c99']
     args += ['-I'+src_root]
     args += ['-I'+os.path.join(src_root, core, s) for s in self.include_dirs]
     for src_file in self.src_files:
         pr_info("Compiling " + src_file)
         l = Launcher('gcc',
                  args + [os.path.join(src_root, core, src_file)],
                      cwd=sim_root,
                      stderr = open(os.path.join(sim_root, src_file+'.err.log'),'w'),
                      stdout = open(os.path.join(sim_root, src_file+'.out.log'),'w'))
         l.run()
Exemple #27
0
    def build(self):
        super(Verilator, self).build()
        self.archives = []
        for core in self.cores:
            if core.verilator:
                 if core.verilator.archive:
                      self.archives += [core.sanitized_name+'.a']
                 self.libs += core.verilator.libs
                 self.include_dirs += [os.path.join(self.src_root, core.sanitized_name, d) for d in core.verilator.include_dirs]
        self.include_dirs += [os.path.dirname(os.path.join(self.work_root, self.tb_toplevel))]

        self.include_dirs += [self.src_root]

        pr_info("Verilating source")
        self._verilate()
        for core in self.cores:
            if core.verilator:
                 self._build(core, self.work_root, self.src_root)

        # Do parallel builds with <number of cpus> * 2 jobs.
        make_job_count = multiprocessing.cpu_count() * 2

        pr_info("Building verilator executable:")
        args = ['-f', 'V' + self.top_module + '.mk', '-j', str(make_job_count), 'V' + self.top_module]
        l = utils.Launcher('make', args,
                       cwd=os.path.join(self.work_root, 'obj_dir'),
                       stdout = open(os.path.join(self.work_root,
                                                  'verilator.make.log'),'w'))
        if Config().verbose:
             pr_info("  Verilator executable working dir: "
                     + os.path.join(self.work_root, 'obj_dir'))
             pr_info("  Verilator executable command: make " + ' '.join(args))
        l.run()
Exemple #28
0
    def _checkout(self, local_dir):
        #TODO : Sanitize URL
        url = 'https://github.com/{user}/{repo}/archive/{version}.tar.gz'.format(user=self.user, repo=self.repo, version=self.version)
        pr_info("Checking out " + url + " revision " + self.version + " to " + local_dir)
        (filename, headers) = urllib.urlretrieve(url)

        t = tarfile.open(filename)
        (cache_root, core) = os.path.split(local_dir)

        #Ugly hack to get the first part of the directory name of the extracted files
        tmp = t.getnames()[0]
        t.extractall(cache_root)
        os.rename(os.path.join(cache_root, tmp),
                  os.path.join(cache_root, core))
Exemple #29
0
def update(args):
    for root in CoreManager().get_cores_root():
        if os.path.exists(root):
            args = ['-C', root, 'config', '--get', 'remote.origin.url']
            repo_root = ""
            try:
                repo_root = subprocess.check_output(['git'] +
                                                    args).decode("utf-8")
                if repo_root.strip() in [repo[1] for repo in REPOS]:
                    pr_info("Updating '{}'".format(root))
                    args = ['-C', root, 'pull']
                    Launcher('git', args).run()
            except subprocess.CalledProcessError:
                pass
    def build(self):
        super(Verilator, self).build()
        self.archives = []
        for core_name in self.cores:
            core = self.cm.get_core(core_name)
            if core.verilator:
                 if core.verilator.archive:
                      self.archives += [core_name+'.a']
                 self.libs += core.verilator.libs
                 self.include_dirs += [os.path.join(self.src_root, core_name, d) for d in core.verilator.include_dirs]
        self.include_dirs += [os.path.dirname(os.path.join(self.sim_root, self.tb_toplevel))]

        self.include_dirs += [self.src_root]

        pr_info("Verilating source")
        self._verilate()
        for core_name in self.cores:
            core = self.cm.get_core(core_name)
            if core.verilator:
                 self._build(core, self.sim_root, self.src_root)

        pr_info("Building verilator executable:")
        args = ['-f', 'V' + self.top_module + '.mk', 'V' + self.top_module]
        l = utils.Launcher('make', args,
                       cwd=os.path.join(self.sim_root, 'obj_dir'),
                       stdout = open(os.path.join(self.sim_root,
                                                  'verilator.make.log'),'w'))
        if Config().verbose:
             pr_info("  Verilator executable working dir: "
                     + os.path.join(self.sim_root, 'obj_dir'))
             pr_info("  Verilator executable command: make " + ' '.join(args))
        l.run()
Exemple #31
0
def update(args):
    for root in CoreManager().get_cores_root():
        if os.path.exists(root):
            args = ['-C', root,
                    'config', '--get', 'remote.origin.url']
            repo_root = ""
            try:
                repo_root = subprocess.check_output(['git'] + args).decode("utf-8")
                if repo_root.strip() == REPO_URI:
                    pr_info("Updating '{}'".format(root))
                    args = ['-C', root, 'pull']
                    Launcher('git', args).run()
            except subprocess.CalledProcessError:
                pass
Exemple #32
0
    def build(self):
        super(Verilator, self).build()
        self.archives = []
        for core_name in self.cores:
            core = self.cm.get_core(core_name)
            if core.verilator:
                 if core.verilator.archive:
                      self.archives += [core.sanitized_name+'.a']
                 self.libs += core.verilator.libs
                 self.include_dirs += [os.path.join(self.src_root, core.sanitized_name, d) for d in core.verilator.include_dirs]
        self.include_dirs += [os.path.dirname(os.path.join(self.sim_root, self.tb_toplevel))]

        self.include_dirs += [self.src_root]

        pr_info("Verilating source")
        self._verilate()
        for core_name in self.cores:
            core = self.cm.get_core(core_name)
            if core.verilator:
                 self._build(core, self.sim_root, self.src_root)

        # Do parallel builds with <number of cpus> * 2 jobs.
        make_job_count = multiprocessing.cpu_count() * 2

        pr_info("Building verilator executable:")
        args = ['-f', 'V' + self.top_module + '.mk', '-j', str(make_job_count), 'V' + self.top_module]
        l = utils.Launcher('make', args,
                       cwd=os.path.join(self.sim_root, 'obj_dir'),
                       stdout = open(os.path.join(self.sim_root,
                                                  'verilator.make.log'),'w'))
        if Config().verbose:
             pr_info("  Verilator executable working dir: "
                     + os.path.join(self.sim_root, 'obj_dir'))
             pr_info("  Verilator executable command: make " + ' '.join(args))
        l.run()
Exemple #33
0
    def _checkout(self, local_dir):
        # TODO : Sanitize URL
        url = URL.format(user=self.user, repo=self.repo, version=self.version)
        pr_info("Downloading {}/{} from github".format(self.user, self.repo))
        try:
            (filename, headers) = urllib.urlretrieve(url)
        except URLError as e:
            raise RuntimeError("Failed to download '{}'. '{}'".format(url, e.reason))
        t = tarfile.open(filename)
        (cache_root, core) = os.path.split(local_dir)

        # Ugly hack to get the first part of the directory name of the extracted files
        tmp = t.getnames()[0]
        t.extractall(cache_root)
        os.rename(os.path.join(cache_root, tmp), os.path.join(cache_root, core))
Exemple #34
0
 def build_CPP(self, core, sim_root, src_root):
     verilator_root = utils.get_verilator_root()
     if verilator_root is None:
         verilator_root = utils.get_verilator_root()
     args = ['-c']
     args += ['-I'+src_root]
     args += ['-I'+os.path.join(src_root, core, s) for s in self.include_dirs]
     args += ['-I'+os.path.join(verilator_root,'include')]
     args += ['-I'+os.path.join(verilator_root,'include', 'vltstd')]
     for src_file in self.src_files:
         pr_info("Compiling " + src_file)
         l = Launcher('g++', args + [os.path.join(src_root, core, src_file)],
                      cwd=sim_root)
         print(l)
         l.run()
Exemple #35
0
 def configure(self):
     if os.path.exists(self.work_root): 
         shutil.rmtree(self.work_root)
     os.makedirs(self.work_root)
     cm = CoreManager()
     for name in self.cores:
         pr_info("Preparing " + name)
         core = cm.get_core(name)
         dst_dir = os.path.join(Config().build_root, self.system.name, 'src', name)
         try:
             core.setup()
         except URLError as e:
             raise RuntimeError("Problem while fetching '" + core.name + "': " + str(e.reason))
         except urllib.HTTPError as e:
             raise RuntimeError("Problem while fetching '" + core.name + "': " + str(e.reason))
         core.export(dst_dir)
Exemple #36
0
    def run(self, args):
        if not self.fusesoc_cli_parser:
            self.plusarg = []
        super(Verilator, self).run(args)

        if self.fusesoc_cli_parser:
            _args = []
            for key, value in self.plusarg.items():
                _args += ['+{}={}'.format(key, value)]
        else:
            _args = args
        pr_info("Running simulation")
        utils.Launcher('./V' + self.top_module,
                       _args,
                       cwd=os.path.join(self.work_root, 'obj_dir'),
                       env=self.env).run()
Exemple #37
0
    def _checkout(self, local_dir):
        #TODO : Sanitize URL
        url = URL.format(user=self.user, repo=self.repo, version=self.version)
        pr_info("Downloading {}/{} from github".format(self.user, self.repo))
        try:
            (filename, headers) = urllib.urlretrieve(url)
        except URLError as e:
            raise RuntimeError("Failed to download '{}'. '{}'".format(
                url, e.reason))
        t = tarfile.open(filename)
        (cache_root, core) = os.path.split(local_dir)

        #Ugly hack to get the first part of the directory name of the extracted files
        tmp = t.getnames()[0]
        t.extractall(cache_root)
        os.rename(os.path.join(cache_root, tmp),
                  os.path.join(cache_root, core))
Exemple #38
0
 def run(self, args):
     if not self.fusesoc_cli_parser:
         self.plusargs = []
     super(Verilator, self).run(args)
     self.env = os.environ.copy()
     self.env['CORE_ROOT'] = os.path.abspath(self.system.core_root)
     self.env['BUILD_ROOT'] = os.path.abspath(self.build_root)
     self.env['SIM_ROOT'] = os.path.abspath(self.sim_root)
     if self.fusesoc_cli_parser:
         _args = ['+' + s for s in self.plusargs]
     else:
         _args = args
     pr_info("Running simulation")
     utils.Launcher('./V' + self.top_module,
                    _args,
                    cwd=os.path.join(self.sim_root, 'obj_dir'),
                    env=self.env).run()
Exemple #39
0
    def configure(self):
        if os.path.exists(self.sim_root):
            for f in os.listdir(self.sim_root):
                if os.path.isdir(os.path.join(self.sim_root, f)):
                    shutil.rmtree(os.path.join(self.sim_root, f))
                else:
                    os.remove(os.path.join(self.sim_root, f))
        else:
            os.makedirs(self.sim_root)

        self.env['SIM_ROOT'] = os.path.abspath(self.sim_root)

        for name in self.cores:
            pr_info("Preparing " + name)
            dst_dir = os.path.join(Config().build_root, self.system.name, 'src', name)
            core = self.cm.get_core(name)
            core.setup()
            core.export(dst_dir)
Exemple #40
0
    def configure(self):
        if os.path.exists(self.sim_root):
            for f in os.listdir(self.sim_root):
                if os.path.isdir(os.path.join(self.sim_root, f)):
                    shutil.rmtree(os.path.join(self.sim_root, f))
                else:
                    os.remove(os.path.join(self.sim_root, f))
        else:
            os.makedirs(self.sim_root)

        self.env['SIM_ROOT'] = os.path.abspath(self.sim_root)

        for name in self.cores:
            pr_info("Preparing " + name)
            dst_dir = os.path.join(Config().build_root, self.system.name, 'src', name)
            core = self.cm.get_core(name)
            core.setup()
            core.export(dst_dir)
Exemple #41
0
    def _checkout(self):
        pr_info("Using Xilinx Vivado to generate LogiCORE(tm) project " + self.project_file)
        if not os.path.isdir(self.files_root):
            os.mkdir(self.files_root)
        src_files = [self.script_file, self.project_file]
        if self.extra_files:
            src_files += self.extra_files.split()

        for f in src_files:
            f_src = os.path.join(self.core_root, f)
            f_dst = os.path.join(self.files_root, f)
            if(os.path.exists(f_src)):
                shutil.copyfile(f_src, f_dst)
            else:
                pr_err('Cannot find file %s' % f_src)
        args = ['-mode', 'batch',
                '-source', self.script_file]
        Launcher('vivado', args, cwd=self.files_root).run()
Exemple #42
0
    def build(self):
        super(Verilator, self).build()

        pr_info("Building simulation model")

        if not os.getenv('VERILATOR_ROOT') and not utils.which('verilator'):
            raise RuntimeError(
                "VERILATOR_ROOT not set and there is no verilator program in your PATH"
            )

        # Do parallel builds with <number of cpus> * 2 jobs.
        make_job_count = multiprocessing.cpu_count() * 2

        _s = os.path.join(self.work_root, 'verilator.{}.log')
        l = utils.Launcher('make', ['-j', str(make_job_count)],
                           cwd=self.work_root,
                           stderr=open(_s.format('err'), 'w'),
                           stdout=open(_s.format('out'), 'w')).run()
Exemple #43
0
    def _checkout(self):
        pr_info("Using Xilinx Vivado to generate LogiCORE(tm) project " +
                self.project_file)
        if not os.path.isdir(self.files_root):
            os.mkdir(self.files_root)
        src_files = [self.script_file, self.project_file]
        if self.extra_files:
            src_files += self.extra_files.split()

        for f in src_files:
            f_src = os.path.join(self.core_root, f)
            f_dst = os.path.join(self.files_root, f)
            if (os.path.exists(f_src)):
                shutil.copyfile(f_src, f_dst)
            else:
                pr_err('Cannot find file %s' % f_src)
        args = ['-mode', 'batch', '-source', self.script_file]
        Launcher('vivado', args, cwd=self.files_root).run()
    def _checkout(self):
        pr_info("Using Coregen to generate project " + self.project_file)
        if not os.path.isdir(self.files_root):
            os.mkdir(self.files_root)
        src_files = [self.script_file, self.project_file]
        if self.extra_files:
            src_files += self.extra_files.split()

        for f in src_files:
            f_src = os.path.join(self.core_root, f)
            f_dst = os.path.join(self.files_root, f)
            if (os.path.exists(f_src)):
                shutil.copyfile(f_src, f_dst)
            else:
                pr_err('Cannot find file %s' % f_src)
        args = ['-r', '-b', self.script_file, '-p', self.project_file]
        #'-intstyle', 'silent']
        Launcher('coregen', args, cwd=self.files_root).run()
 def run(self, args):
     if not self.fusesoc_cli_parser:
         self.plusarg = []
     super(Verilator, self).run(args)
     self.env = os.environ.copy()
     self.env['CORE_ROOT'] = os.path.abspath(self.system.core_root)
     self.env['BUILD_ROOT'] = os.path.abspath(self.build_root)
     self.env['SIM_ROOT'] = os.path.abspath(self.sim_root)
     if self.fusesoc_cli_parser:
         _args = []
         for key, value in self.plusarg.items():
             _args += ['+{}={}'.format(key, value)]
     else:
         _args = args
     pr_info("Running simulation")
     utils.Launcher('./V' + self.top_module,
                    _args,
                    cwd=os.path.join(self.sim_root, 'obj_dir'),
                    env = self.env).run()
Exemple #46
0
 def configure(self):
     if os.path.exists(self.work_root):
         shutil.rmtree(self.work_root)
     os.makedirs(self.work_root)
     cm = CoreManager()
     for name in self.cores:
         pr_info("Preparing " + name)
         core = cm.get_core(name)
         dst_dir = os.path.join(Config().build_root, self.system.name,
                                'src', name)
         try:
             core.setup()
         except urllib.URLError as e:
             raise RuntimeError("Problem while fetching '" + core.name +
                                "': " + str(e.reason))
         except urllib.HTTPError as e:
             raise RuntimeError("Problem while fetching '" + core.name +
                                "': " + str(e.reason))
         core.export(dst_dir)
Exemple #47
0
    def _checkout(self, local_dir):
        #TODO : Sanitize URL
        url = 'https://github.com/{user}/{repo}/archive/{version}.tar.gz'.format(
            user=self.user, repo=self.repo, version=self.version)
        pr_info("Checking out " + url + " revision " + self.version + " to " +
                local_dir)
        try:
            (filename, headers) = urllib.urlretrieve(url)
        except URLError as e:
            raise RuntimeError("Failed to download '{}'. '{}'".format(
                url, e.reason))
        t = tarfile.open(filename)
        (cache_root, core) = os.path.split(local_dir)

        #Ugly hack to get the first part of the directory name of the extracted files
        tmp = t.getnames()[0]
        t.extractall(cache_root)
        os.rename(os.path.join(cache_root, tmp),
                  os.path.join(cache_root, core))
Exemple #48
0
    def _checkout(self):
        pr_info("Using Coregen to generate project " + self.project_file)
        if not os.path.isdir(self.files_root):
            os.mkdir(self.files_root)
        src_files = [self.script_file, self.project_file]
        if self.extra_files:
            src_files += self.extra_files.split()

        for f in src_files:
            f_src = os.path.join(self.core_root, f)
            f_dst = os.path.join(self.files_root, f)
            if(os.path.exists(f_src)):
                shutil.copyfile(f_src, f_dst)
            else:
                pr_err('Cannot find file %s' % f_src)
        args = ['-r',
                '-b', self.script_file,
                '-p', self.project_file]
                #'-intstyle', 'silent']
        Launcher('coregen', args, cwd=self.files_root).run()
Exemple #49
0
    def build(self, core, sim_root, src_root):
        if self.source_type == "C" or self.source_type == "":
            self.build_C(core, sim_root, src_root)
        elif self.source_type == "CPP":
            self.build_CPP(core, sim_root, src_root)
        elif self.source_type == "systemC":
            self.build_SysC(core, sim_root, src_root)
        else:
            raise Source(self.source_type)

        if self._object_files:
            args = []
            args += ["rvs"]
            args += [core + ".a"]
            args += self._object_files
            l = Launcher("ar", args, cwd=sim_root)
            if Config().verbose:
                pr_info("  linker working dir: " + sim_root)
                pr_info("  linker command: ar " + " ".join(args))
            l.run()
            print()
Exemple #50
0
    def configure(self, args):
        if os.path.exists(self.work_root):
            for f in os.listdir(self.work_root):
                if os.path.isdir(os.path.join(self.work_root, f)):
                    shutil.rmtree(os.path.join(self.work_root, f))
                else:
                    os.remove(os.path.join(self.work_root, f))
        else:
            os.makedirs(self.work_root)

        for name in self.cores:
            pr_info("Preparing " + str(name))
            core = self.cm.get_core(name)
            dst_dir = os.path.join(Config().build_root, self.system.sanitized_name, 'src', core.sanitized_name)
            try:
                core.setup()
            except URLError as e:
                raise RuntimeError("Problem while fetching '" + core.name + "': " + str(e.reason))
            except HTTPError as e:
                raise RuntimeError("Problem while fetching '" + core.name + "': " + str(e.reason))
            core.export(dst_dir)
Exemple #51
0
    def build(self, core, sim_root, src_root):
        if self.source_type == 'C' or self.source_type == '':
            self.build_C(core, sim_root, src_root)
        elif self.source_type == 'CPP':
            self.build_CPP(core, sim_root, src_root)
        elif self.source_type == 'systemC':
            self.build_SysC(core, sim_root, src_root)
        else:
            raise Source(self.source_type)

        if self._object_files:
            args = []
            args += ['rvs']
            args += [core + '.a']
            args += self._object_files
            l = Launcher('ar', args, cwd=sim_root)
            if Config().verbose:
                pr_info("  linker working dir: " + sim_root)
                pr_info("  linker command: ar " + ' '.join(args))
            l.run()
            print()
Exemple #52
0
def abort_handler(signal, frame):
    print('')
    pr_info('****************************')
    pr_info('****   FuseSoC aborted  ****')
    pr_info('****************************')
    print('')
    sys.exit(0)
Exemple #53
0
def abort_handler(signal, frame):
        print('');
        pr_info('****************************')
        pr_info('****   FuseSoC aborted  ****')
        pr_info('****************************')
        print('');
        sys.exit(0)
Exemple #54
0
 def build_CPP(self, core, sim_root, src_root):
     verilator_root = utils.get_verilator_root()
     if verilator_root is None:
         verilator_root = utils.get_verilator_root()
     args = ['-c']
     args += ['-I' + src_root]
     args += [
         '-I' + os.path.join(src_root, core.sanitized_name, s)
         for s in self.include_dirs
     ]
     args += ['-Iobj_dir']
     args += ['-I' + os.path.join(verilator_root, 'include')]
     args += ['-I' + os.path.join(verilator_root, 'include', 'vltstd')]
     for src_file in core.verilator.src_files:
         pr_info("Compiling " + src_file.name)
         l = utils.Launcher(
             'g++',
             args +
             [os.path.join(src_root, core.sanitized_name, src_file.name)],
             cwd=sim_root,
             stderr=open(os.path.join(sim_root, 'g++.err.log'), 'a'))
         if Config().verbose:
             pr_info("  C++ compilation working dir: " + sim_root)
             pr_info(
                 "  C++ compilation command: g++ " + ' '.join(args) + ' ' +
                 os.path.join(src_root, core.sanitized_name, src_file.name))
         l.run()
Exemple #55
0
    def build_SysC(self, core, work_root, src_root):
        verilator_root = utils.get_verilator_root()
        args = ['-I.']
        args += ['-MMD']
        args += ['-I'+src_root]
        args += ['-I'+s for s in self.include_dirs]
        args += ['-Iobj_dir']
        args += ['-I'+os.path.join(verilator_root,'include')]
        args += ['-I'+os.path.join(verilator_root,'include', 'vltstd')]  
        args += ['-DVL_PRINTF=printf']
        args += ['-DVM_TRACE=1']
        args += ['-DVM_COVERAGE=0']
        if os.getenv('SYSTEMC_INCLUDE'):
            args += ['-I'+os.getenv('SYSTEMC_INCLUDE')]
        if os.getenv('SYSTEMC'):
            args += ['-I'+os.path.join(os.getenv('SYSTEMC'),'include')]
        args += ['-Wno-deprecated']
        if os.getenv('SYSTEMC_CXX_FLAGS'):
             args += [os.getenv('SYSTEMC_CXX_FLAGS')]
        args += ['-c']
        args += ['-g']

        for src_file in core.verilator.src_files:
            pr_info("Compiling " + src_file.name)
            l = utils.Launcher('g++', args + [os.path.join(src_root, core.sanitized_name, src_file.name)],
                         cwd=work_root,
                         stderr = open(os.path.join(work_root, 'g++.err.log'),'a'))
            if Config().verbose:
                pr_info("  SystemC compilation working dir: " + work_root)
                pr_info("  SystemC compilation command: g++ " + ' '.join(args) + ' ' + os.path.join(src_root, core.sanitized_name, src_file.name))
            l.run()
    def build_SysC(self, core, sim_root, src_root):
        verilator_root = utils.get_verilator_root()
        args = ['-I.']
        args += ['-MMD']
        args += ['-I'+src_root]
        args += ['-I'+s for s in self.include_dirs]
        args += ['-Iobj_dir']
        args += ['-I'+os.path.join(verilator_root,'include')]
        args += ['-I'+os.path.join(verilator_root,'include', 'vltstd')]  
        args += ['-DVL_PRINTF=printf']
        args += ['-DVM_TRACE=1']
        args += ['-DVM_COVERAGE=0']
        if os.getenv('SYSTEMC_INCLUDE'):
            args += ['-I'+os.getenv('SYSTEMC_INCLUDE')]
        if os.getenv('SYSTEMC'):
            args += ['-I'+os.path.join(os.getenv('SYSTEMC'),'include')]
        args += ['-Wno-deprecated']
        if os.getenv('SYSTEMC_CXX_FLAGS'):
             args += [os.getenv('SYSTEMC_CXX_FLAGS')]
        args += ['-c']
        args += ['-g']

        for src_file in core.verilator.src_files:
            pr_info("Compiling " + src_file.name)
            l = utils.Launcher('g++', args + [os.path.join(src_root, core.sanitized_name, src_file.name)],
                         cwd=sim_root,
                         stderr = open(os.path.join(sim_root, 'g++.err.log'),'a'))
            if Config().verbose:
                pr_info("  SystemC compilation working dir: " + sim_root)
                pr_info("  SystemC compilation command: g++ " + ' '.join(args) + ' ' + os.path.join(src_root, core.sanitized_name, src_file.name))
            l.run()
Exemple #57
0
    def build(self, core, sim_root, src_root):
        if self.source_type == 'C' or self.source_type == '':
            self.build_C(core, sim_root, src_root)
        elif self.source_type == 'CPP':
            self.build_CPP(core, sim_root, src_root)
        elif self.source_type == 'systemC':
            self.build_SysC(core, sim_root, src_root)
        else:
            raise Source(self.source_type)

        if self._object_files:
            args = []
            args += ['rvs']
            args += [core+'.a']
            args += self._object_files
            l = Launcher('ar', args,
                     cwd=sim_root)
            if Config().verbose:
                pr_info("  linker working dir: " + sim_root)
                pr_info("  linker command: ar " + ' '.join(args))
            l.run()
            print()