Commit 524cfa5f authored by Jens Korinth's avatar Jens Korinth
Browse files

Squashed 'packaging/' content from commit d2df30ff

git-subtree-dir: packaging
git-subtree-split: d2df30ff
parents
package chisel.packaging
import scala.io.Source
import play.api.libs.json._
import play.api.libs.functional.syntax._
/**
* Basic definition of a core for IP-XACT packaging.
**/
case class CoreDefinition(name: String, vendor: String, library: String, version: String, root: String) {
import CoreDefinition._
def write(filename: String) : Boolean = try {
val fw = new java.io.FileWriter(filename)
fw.append(Json.toJson(this).toString)
fw.flush()
fw.close()
true
} catch { case ex: Exception => println("ERROR: " + ex); false }
}
/**
* Contains methods for reading a core definition from Json.
**/
object CoreDefinition {
/** Provide automatic IP directory for given name. **/
def root(name: String): String =
java.nio.file.Paths.get(".").toAbsolutePath.resolveSibling("ip").resolve(name).toString
implicit val coreDefinitionWrites : Writes[CoreDefinition] = (
(JsPath \ "name").write[String] ~
(JsPath \ "vendor").write[String] ~
(JsPath \ "library").write[String] ~
(JsPath \ "version").write[String] ~
(JsPath \ "root").write[String]
)(unlift(CoreDefinition.unapply))
implicit val coreDefinitionReads : Reads[CoreDefinition] = (
(JsPath \ "name").read[String] ~
(JsPath \ "vendor").read[String] ~
(JsPath \ "library").read[String] ~
(JsPath \ "version").read[String] ~
(JsPath \ "root").read[String]
)(CoreDefinition.apply _)
/**
* Read CoreDefinition from file containing Json format.
* @param filename Name (and path) of file.
**/
def read(filename: String) : Option[CoreDefinition] = try {
val contents = Source.fromFile(filename).getLines.mkString("\n")
val json = Json.parse(contents)
json.validate[CoreDefinition] match {
case s: JsSuccess[CoreDefinition] => Some(s.get)
case e: JsError => { println("ERROR: " + e); None }
}
} catch { case ex: Exception => println("ERROR: " + ex); None }
}
package chisel.packaging
import Chisel._
import scala.sys.process._
/**
* Abstract IP-XACT builder class:
* Objects can inherit from ModuleBuilder to automate the building
* and packaging process. Provides main method that can be run
* automatically via sbt run, takes arguments which cores to build.
* @param packagingDir Base directory of packaging submodule
* (default: ./packaging)
**/
abstract class ModuleBuilder(packagingDir: String = "packaging") {
val chiselArgs = Array("--backend", "v", "--compile")
val modules: List[(() => Module, CoreDefinition)]
def main(args: Array[String]) {
assert ((modules map (_._2.name.toLowerCase)).toSet.size == modules.length, "module names must be unique")
val fm = modules filter (m => args.length == 0 || args.map(_.toLowerCase).contains(m._2.name.toLowerCase))
assert (fm.length > 0, "no matching cores found for: " + args.mkString(", "))
fm foreach { m =>
chiselMain(chiselArgs ++ Array("--targetDir", m._2.root), m._1)
val json = "%s/%s.json".format(m._2.root, m._2.name)
m._2.write(json)
"%s/package.py %s".format(packagingDir, json) !
}
}
}
#!/usr/bin/python
import json
import argparse
from subprocess import Popen, STDOUT, PIPE
script = '''
create_project -force "{0}" /tmp
ipx::infer_core -name "{0}" -vendor "{1}" -library "{2}" -version "{3}" "{4}"
set_property supported_families {{virtex7 Production qvirtex7 Production kintex7 Production kintex7l Production qkintex7 Production qkintex7l Production artix7 Production artix7l Production aartix7 Production qartix7 Production zynq Production qzynq Production azynq Production}} [ipx::current_core]
set_property core_revision 1 [ipx::current_core]
set_property display_name "{0}" [ipx::current_core]
set_property description "{0}" [ipx::current_core]
set_property taxonomy "{2}" [ipx::current_core]
ipx::add_bus_parameter POLARITY [ipx::get_bus_interfaces reset -of_objects [ipx::current_core]]
set_property value ACTIVE_HIGH [ipx::get_bus_parameters POLARITY -of_objects [ipx::get_bus_interfaces reset -of_objects [ipx::current_core]]]
ipx::update_checksums [ipx::current_core]
ipx::save_core [ipx::current_core]
close_project -delete
'''
def read_json(jsonfile):
with open(jsonfile, 'r') as jf:
contents = jf.read()
return json.loads(contents)
def make_vivado_script(jsonfile):
cd = read_json(jsonfile)
return script.format(cd['name'], cd['vendor'], cd['library'], cd['version'], cd['root'])
def run_vivado(script):
p = Popen(['vivado', '-mode', 'tcl', '-nolog', '-nojournal'], stdin=PIPE, stdout=PIPE, stderr=STDOUT)
output = p.communicate(input = script)[0]
print output.decode()
def parse_args():
parser = argparse.ArgumentParser(description = 'Package a hardware module specified by JSON as IP-XACT.')
parser.add_argument('json', help = 'path to JSON file')
return parser.parse_args()
args = parse_args()
run_vivado(make_vivado_script(args.json))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment