2019-06-24 06:38:58 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
# This file is Copyright (c) 2014-2019 Florent Kermarrec <florent@enjoy-digital.fr>
|
|
|
|
# This file is Copyright (c) 2013-2014 Sebastien Bourdeauducq <sb@m-labs.hk>
|
|
|
|
# License: BSD
|
|
|
|
|
2020-05-05 09:11:38 -04:00
|
|
|
import os
|
2019-06-24 06:38:58 -04:00
|
|
|
import argparse
|
|
|
|
import importlib
|
|
|
|
|
|
|
|
from migen import *
|
2020-04-10 04:26:19 -04:00
|
|
|
|
|
|
|
from litex.build.io import CRG
|
2019-06-24 06:38:58 -04:00
|
|
|
|
|
|
|
from litex.soc.integration.soc_core import *
|
|
|
|
from litex.soc.integration.builder import *
|
|
|
|
|
|
|
|
from liteeth.phy import LiteEthPHY
|
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BaseSoC(SoCCore):
|
2020-03-21 13:29:52 -04:00
|
|
|
def __init__(self, platform, with_ethernet=False, **kwargs):
|
2019-06-24 06:38:58 -04:00
|
|
|
sys_clk_freq = int(1e9/platform.default_clk_period)
|
2019-12-03 03:07:09 -05:00
|
|
|
|
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
2020-06-30 12:11:04 -04:00
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq,
|
|
|
|
ident = "LiteX Simple SoC",
|
|
|
|
ident_version = True,
|
|
|
|
**kwargs)
|
2020-01-16 04:28:09 -05:00
|
|
|
|
2019-12-03 03:07:09 -05:00
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2019-06-24 06:38:58 -04:00
|
|
|
self.submodules.crg = CRG(platform.request(platform.default_clk_name))
|
|
|
|
|
2020-01-16 04:28:09 -05:00
|
|
|
# Ethernet ---------------------------------------------------------------------------------
|
2020-03-21 13:29:52 -04:00
|
|
|
if with_ethernet:
|
|
|
|
self.submodules.ethphy = LiteEthPHY(
|
|
|
|
clock_pads = self.platform.request("eth_clocks"),
|
|
|
|
pads = self.platform.request("eth"),
|
|
|
|
clk_freq = self.clk_freq)
|
|
|
|
self.add_csr("ethphy")
|
|
|
|
self.add_ethernet(phy=self.ethphy)
|
2019-06-24 06:38:58 -04:00
|
|
|
|
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description="Generic LiteX SoC")
|
2020-05-05 09:11:38 -04:00
|
|
|
parser.add_argument("--build", action="store_true", help="Build bitstream")
|
2019-06-24 06:38:58 -04:00
|
|
|
builder_args(parser)
|
|
|
|
soc_core_args(parser)
|
2020-05-05 09:11:38 -04:00
|
|
|
parser.add_argument("--with-ethernet", action="store_true", help="Enable Ethernet support")
|
|
|
|
parser.add_argument("platform", help="Module name of the platform to build for")
|
2020-06-02 07:45:05 -04:00
|
|
|
parser.add_argument("--toolchain", default=None, help="FPGA gateware toolchain used for build")
|
2019-06-24 06:38:58 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
platform_module = importlib.import_module(args.platform)
|
2020-06-02 07:45:05 -04:00
|
|
|
if args.toolchain is not None:
|
|
|
|
platform = platform_module.Platform(toolchain=args.toolchain)
|
2019-06-24 06:38:58 -04:00
|
|
|
else:
|
|
|
|
platform = platform_module.Platform()
|
2020-03-21 13:29:52 -04:00
|
|
|
soc = BaseSoC(platform, with_ethernet=args.with_ethernet, **soc_core_argdict(args))
|
2019-06-24 06:38:58 -04:00
|
|
|
builder = Builder(soc, **builder_argdict(args))
|
2020-05-05 09:11:38 -04:00
|
|
|
builder.build(run=args.build)
|
2019-06-24 06:38:58 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|