def main():
    parser = argparse.ArgumentParser(description='LiteX SoC on ButterStick')
    parser.add_argument('--build', action='store_true', help='Build bitstream.')
    parser.add_argument('--load', action='store_true', help='Load bitstream.')
    parser.add_argument('--toolchain', default='trellis', help='FPGA toolchain (trellis or diamond).')
    parser.add_argument('--sys-clk-freq', default=75000000.0, help='System clock frequency.')
    parser.add_argument('--revision', default='1.0', help='Board Revision (1.0).')
    parser.add_argument('--device', default='85F', help='ECP5 device (25F, 45F, 85F).')
    parser.add_argument('--sdram-device', default='MT41K64M16', help='SDRAM device (MT41K64M16, MT41K128M16, MT41K256M16 or MT41K512M16).')
    ethopts = parser.add_mutually_exclusive_group()
    ethopts.add_argument('--with-ethernet', action='store_true', help='Add Ethernet.')
    ethopts.add_argument('--with-etherbone', action='store_true', help='Add EtherBone.')
    parser.add_argument('--eth-ip', default='192.168.1.50', help='Ethernet/Etherbone IP address.')
    parser.add_argument('--eth-dynamic-ip', action='store_true', help='Enable dynamic Ethernet IP addresses setting.')
    parser.add_argument('--with-spi-flash', action='store_true', help='Enable SPI Flash (MMAPed).')
    sdopts = parser.add_mutually_exclusive_group()
    sdopts.add_argument('--with-spi-sdcard', action='store_true', help='Enable SPI-mode SDCard support.')
    sdopts.add_argument('--with-sdcard', action='store_true', help='Enable SDCard support.')
    builder_args(parser)
    soc_core_args(parser)
    trellis_args(parser)
    args = parser.parse_args()
    assert (not (args.with_etherbone and args.eth_dynamic_ip))
    soc = BaseSoC(toolchain=args.toolchain, revision=args.revision, device=args.device, sdram_device=args.sdram_device, sys_clk_freq=int(float(args.sys_clk_freq)), with_ethernet=args.with_ethernet, with_etherbone=args.with_etherbone, eth_ip=args.eth_ip, eth_dynamic_ip=args.eth_dynamic_ip, with_spi_flash=args.with_spi_flash, **soc_core_argdict(args))
    if args.with_spi_sdcard:
        soc.add_spi_sdcard()
    if args.with_sdcard:
        soc.add_sdcard()
    builder = Builder(soc, **builder_argdict(args))
    builder_kargs = (trellis_argdict(args) if (args.toolchain == 'trellis') else {})
    builder.build(**builder_kargs, run=args.build)
    if args.load:
        prog = soc.platform.create_programmer()
        prog.load_bitstream(os.path.join(builder.gateware_dir, (soc.build_name + '.bit')))
def main():
    parser = argparse.ArgumentParser(description='LiteX SoC on ButterStick')
    parser.add_argument('--build', action='store_true', help='Build bitstream.')
    parser.add_argument('--load', action='store_true', help='Load bitstream.')
    parser.add_argument('--toolchain', default='trellis', help='FPGA toolchain (trellis or diamond).')
    parser.add_argument('--sys-clk-freq', default=75000000.0, help='System clock frequency.')
    parser.add_argument('--revision', default='1.0', help='Board Revision (1.0).')
    parser.add_argument('--device', default='85F', help='ECP5 device (25F, 45F, 85F).')
    parser.add_argument('--sdram-device', default='MT41K64M16', help='SDRAM device (MT41K64M16, MT41K128M16, MT41K256M16 or MT41K512M16).')
    ethopts = parser.add_mutually_exclusive_group()
    ethopts.add_argument('--with-ethernet', action='store_true', help='Add Ethernet.')
    ethopts.add_argument('--with-etherbone', action='store_true', help='Add EtherBone.')
    parser.add_argument('--eth-ip', default='192.168.1.50', help='Ethernet/Etherbone IP address.')
    parser.add_argument('--eth-dynamic-ip', action='store_true', help='Enable dynamic Ethernet IP addresses setting.')
    parser.add_argument('--with-spi-flash', action='store_true', help='Enable SPI Flash (MMAPed).')
    sdopts = parser.add_mutually_exclusive_group()
    sdopts.add_argument('--with-spi-sdcard', action='store_true', help='Enable SPI-mode SDCard support.')
    sdopts.add_argument('--with-sdcard', action='store_true', help='Enable SDCard support.')
    builder_args(parser)
    soc_core_args(parser)
    trellis_args(parser)
    args = parser.parse_args()
    assert (not (args.with_etherbone and args.eth_dynamic_ip))
    soc = BaseSoC(toolchain=args.toolchain, revision=args.revision, device=args.device, sdram_device=args.sdram_device, sys_clk_freq=int(float(args.sys_clk_freq)), with_ethernet=args.with_ethernet, with_etherbone=args.with_etherbone, eth_ip=args.eth_ip, eth_dynamic_ip=args.eth_dynamic_ip, with_spi_flash=args.with_spi_flash, **soc_core_argdict(args))
    if args.with_spi_sdcard:
        soc.add_spi_sdcard()
    if args.with_sdcard:
        soc.add_sdcard()
    builder = Builder(soc, **builder_argdict(args))
    builder_kargs = (trellis_argdict(args) if (args.toolchain == 'trellis') else {})
    builder.build(**builder_kargs, run=args.build)
    if args.load:
        prog = soc.platform.create_programmer()
        prog.load_bitstream(os.path.join(builder.gateware_dir, (soc.build_name + '.bit')))