2022-01-25 01:20:19 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2022 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
2022-02-12 12:23:19 -05:00
|
|
|
# Build/Use:
|
|
|
|
# The current support is sufficient to run LiteX BIOS on Cortex-A53 core #0:
|
|
|
|
# ./alinx_axu2cga.py --build --load
|
|
|
|
# LiteX BIOS can then be executed on hardware using JTAG with the following xsct script from:
|
|
|
|
# https://github.com/trabucayre/litex-template/
|
|
|
|
# make -f Makefile.axu2cga load will build everything and run xsct in the end.
|
|
|
|
#
|
|
|
|
# Relies on https://github.com/lucaceresoli/zynqmp-pmufw-builder to create a generic PMU firmware;
|
|
|
|
# first build will take a while because it includes a cross-toolchain.
|
|
|
|
|
2022-01-25 01:20:19 -05:00
|
|
|
import os
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
|
2023-02-23 03:09:33 -05:00
|
|
|
from litex.gen import *
|
2022-10-27 10:58:55 -04:00
|
|
|
|
2022-02-12 12:23:19 -05:00
|
|
|
from litex_boards.platforms import alinx_axu2cga
|
2022-01-25 01:20:19 -05:00
|
|
|
|
2022-02-12 12:23:19 -05:00
|
|
|
from litex.build.tools import write_to_file
|
|
|
|
|
|
|
|
from litex.soc.interconnect import axi
|
|
|
|
from litex.soc.interconnect import wishbone
|
2022-01-25 01:20:19 -05:00
|
|
|
|
|
|
|
from litex.soc.cores.clock import *
|
|
|
|
from litex.soc.integration.soc_core import *
|
2022-02-12 12:23:19 -05:00
|
|
|
from litex.soc.integration.soc import SoCRegion
|
2022-01-25 01:20:19 -05:00
|
|
|
from litex.soc.integration.builder import *
|
|
|
|
from litex.soc.cores.led import LedChaser
|
|
|
|
|
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
2022-02-12 12:23:19 -05:00
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
class _CRG(LiteXModule):
|
2022-02-12 12:23:19 -05:00
|
|
|
def __init__(self, platform, sys_clk_freq, use_psu_clk=False):
|
2022-10-27 10:58:55 -04:00
|
|
|
self.rst = Signal()
|
|
|
|
self.cd_sys = ClockDomain()
|
2022-01-25 01:20:19 -05:00
|
|
|
|
|
|
|
# # #
|
|
|
|
|
2022-02-12 12:23:19 -05:00
|
|
|
if use_psu_clk:
|
|
|
|
self.comb += [
|
|
|
|
ClockSignal("sys").eq(ClockSignal("ps")),
|
|
|
|
ResetSignal("sys").eq(ResetSignal("ps") | self.rst),
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
# Clk
|
|
|
|
clk25 = platform.request("clk25")
|
|
|
|
|
|
|
|
# PLL
|
2022-10-27 10:58:55 -04:00
|
|
|
self.pll = pll = USMMCM(speedgrade=-1)
|
2022-02-12 12:23:19 -05:00
|
|
|
self.comb += pll.reset.eq(self.rst)
|
|
|
|
pll.register_clkin(clk25, 25e6)
|
|
|
|
pll.create_clkout(self.cd_sys, sys_clk_freq)
|
|
|
|
# Ignore sys_clk to pll.clkin path created by SoC's rst.
|
|
|
|
platform.add_false_path_constraints(self.cd_sys.clk, pll.clkin)
|
2022-01-25 01:20:19 -05:00
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
2022-02-12 12:23:19 -05:00
|
|
|
|
2022-01-25 01:20:19 -05:00
|
|
|
class BaseSoC(SoCCore):
|
2022-11-08 05:54:17 -05:00
|
|
|
def __init__(self, sys_clk_freq=25e6, with_led_chaser=True, **kwargs):
|
2022-02-12 12:23:19 -05:00
|
|
|
platform = alinx_axu2cga.Platform()
|
|
|
|
|
2022-04-21 06:17:26 -04:00
|
|
|
# CRG --------------------------------------------------------------------------------------
|
|
|
|
use_psu_clk = (kwargs.get("cpu_type", None) == "zynqmp")
|
2022-10-27 10:58:55 -04:00
|
|
|
self.crg = _CRG(platform, sys_clk_freq, use_psu_clk)
|
2022-04-21 06:17:26 -04:00
|
|
|
|
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
2022-02-12 12:23:19 -05:00
|
|
|
if kwargs.get("cpu_type", None) == "zynqmp":
|
2022-04-21 09:48:29 -04:00
|
|
|
kwargs["integrated_sram_size"] = 0
|
|
|
|
kwargs["with_uart"] = False
|
2022-02-12 12:23:19 -05:00
|
|
|
self.mem_map = {
|
2022-04-21 09:48:29 -04:00
|
|
|
"csr": 0x8000_0000, # Zynq GP0 default
|
2022-02-12 12:23:19 -05:00
|
|
|
}
|
2022-04-21 06:17:26 -04:00
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on Alinx AXU2CGA", **kwargs)
|
2022-01-25 01:20:19 -05:00
|
|
|
|
2022-02-12 12:23:19 -05:00
|
|
|
# ZynqMP Integration ---------------------------------------------------------------------
|
|
|
|
if kwargs.get("cpu_type", None) == "zynqmp":
|
|
|
|
self.cpu.config.update(platform.psu_config)
|
|
|
|
|
|
|
|
# Connect AXI HPM0 LPD to the SoC
|
|
|
|
wb_lpd = wishbone.Interface()
|
|
|
|
self.submodules += axi.AXI2Wishbone(
|
|
|
|
axi = self.cpu.add_axi_gp_master(2, 32),
|
|
|
|
wishbone = wb_lpd,
|
2022-04-21 09:48:29 -04:00
|
|
|
base_address = self.mem_map["csr"])
|
2022-04-21 09:32:19 -04:00
|
|
|
self.bus.add_master(master=wb_lpd)
|
2022-02-12 12:23:19 -05:00
|
|
|
|
|
|
|
self.bus.add_region("sram", SoCRegion(
|
2022-04-21 06:17:26 -04:00
|
|
|
origin = self.cpu.mem_map["sram"],
|
|
|
|
size = 1 * 1024 * 1024 * 1024) # DDR
|
2022-02-12 12:23:19 -05:00
|
|
|
)
|
|
|
|
self.bus.add_region("rom", SoCRegion(
|
2022-04-21 06:17:26 -04:00
|
|
|
origin = self.cpu.mem_map["rom"],
|
|
|
|
size = 512 * 1024 * 1024 // 8,
|
|
|
|
linker = True)
|
2022-02-12 12:23:19 -05:00
|
|
|
)
|
2022-04-21 09:48:29 -04:00
|
|
|
self.constants["CONFIG_CLOCK_FREQUENCY"] = 1199880127
|
2022-02-12 12:23:19 -05:00
|
|
|
|
2022-01-25 01:20:19 -05:00
|
|
|
# Leds -------------------------------------------------------------------------------------
|
|
|
|
if with_led_chaser:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.leds = LedChaser(
|
2022-01-25 01:20:19 -05:00
|
|
|
pads = platform.request_all("user_led"),
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
|
|
|
|
2022-02-12 12:23:19 -05:00
|
|
|
def finalize(self, *args, **kwargs):
|
|
|
|
super(BaseSoC, self).finalize(*args, **kwargs)
|
|
|
|
if self.cpu_type != "zynqmp":
|
|
|
|
return
|
|
|
|
|
|
|
|
libxil_path = os.path.join(self.builder.software_dir, 'libxil')
|
|
|
|
os.makedirs(os.path.realpath(libxil_path), exist_ok=True)
|
|
|
|
lib = os.path.join(libxil_path, 'embeddedsw')
|
|
|
|
if not os.path.exists(lib):
|
|
|
|
os.system("git clone --depth 1 https://github.com/Xilinx/embeddedsw {}".format(lib))
|
|
|
|
|
|
|
|
os.makedirs(os.path.realpath(self.builder.include_dir), exist_ok=True)
|
|
|
|
|
|
|
|
for header in [
|
|
|
|
'XilinxProcessorIPLib/drivers/uartps/src/xuartps_hw.h',
|
|
|
|
'lib/bsp/standalone/src/common/xil_types.h',
|
|
|
|
'lib/bsp/standalone/src/common/xil_assert.h',
|
|
|
|
'lib/bsp/standalone/src/common/xil_io.h',
|
|
|
|
'lib/bsp/standalone/src/common/xil_printf.h',
|
|
|
|
'lib/bsp/standalone/src/common/xstatus.h',
|
|
|
|
'lib/bsp/standalone/src/common/xdebug.h',
|
|
|
|
'lib/bsp/standalone/src/arm/ARMv8/64bit/xpseudo_asm.h',
|
|
|
|
'lib/bsp/standalone/src/arm/ARMv8/64bit/xreg_cortexa53.h',
|
|
|
|
'lib/bsp/standalone/src/arm/ARMv8/64bit/xil_cache.h',
|
|
|
|
'lib/bsp/standalone/src/arm/ARMv8/64bit/xil_errata.h',
|
|
|
|
'lib/bsp/standalone/src/arm/ARMv8/64bit/platform/ZynqMP/xparameters_ps.h',
|
|
|
|
'lib/bsp/standalone/src/arm/common/xil_exception.h',
|
|
|
|
'lib/bsp/standalone/src/arm/common/gcc/xpseudo_asm_gcc.h',
|
|
|
|
]:
|
|
|
|
shutil.copy(os.path.join(lib, header), self.builder.include_dir)
|
|
|
|
|
|
|
|
write_to_file(os.path.join(self.builder.include_dir, 'bspconfig.h'), """
|
|
|
|
#ifndef BSPCONFIG_H
|
|
|
|
#define BSPCONFIG_H
|
|
|
|
|
|
|
|
#define EL3 1
|
|
|
|
#define EL1_NONSECURE 0
|
|
|
|
|
|
|
|
#endif
|
|
|
|
""")
|
|
|
|
write_to_file(os.path.join(self.builder.include_dir, 'xparameters.h'), '''
|
|
|
|
#ifndef XPARAMETERS_H
|
|
|
|
#define XPARAMETERS_H
|
|
|
|
|
|
|
|
#include "xparameters_ps.h"
|
|
|
|
|
|
|
|
#define STDIN_BASEADDRESS 0xFF010000
|
|
|
|
#define STDOUT_BASEADDRESS 0xFF010000
|
|
|
|
#define XPAR_PSU_DDR_0_S_AXI_BASEADDR 0x00000000
|
|
|
|
#define XPAR_PSU_DDR_0_S_AXI_HIGHADDR 0x7FFFFFFF
|
|
|
|
#define XPAR_PSU_DDR_1_S_AXI_BASEADDR 0x800000000
|
|
|
|
#define XPAR_PSU_DDR_1_S_AXI_HIGHADDR 0x87FFFFFFF
|
|
|
|
#define XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ 99999005
|
|
|
|
|
|
|
|
#endif
|
|
|
|
''')
|
|
|
|
|
|
|
|
|
2022-01-25 01:20:19 -05:00
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
2022-11-06 15:39:52 -05:00
|
|
|
from litex.build.parser import LiteXArgumentParser
|
2022-11-08 04:41:35 -05:00
|
|
|
parser = LiteXArgumentParser(platform=alinx_axu2cga.Platform, description="LiteX SoC on Alinx AXU2CGA.")
|
|
|
|
parser.add_target_argument("--cable", default="ft232", help="JTAG interface.")
|
|
|
|
parser.add_target_argument("--sys-clk-freq", default=25e6, type=float, help="System clock frequency.")
|
2022-02-12 12:23:19 -05:00
|
|
|
parser.set_defaults(cpu_type="zynqmp")
|
2022-01-25 01:20:19 -05:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
soc = BaseSoC(
|
2022-11-08 04:41:35 -05:00
|
|
|
sys_clk_freq=args.sys_clk_freq,
|
2022-11-07 02:43:26 -05:00
|
|
|
**parser.soc_argdict
|
2022-01-25 01:20:19 -05:00
|
|
|
)
|
2022-11-05 03:07:14 -04:00
|
|
|
builder = Builder(soc, **parser.builder_argdict)
|
2022-02-12 12:23:19 -05:00
|
|
|
if args.cpu_type == "zynqmp":
|
|
|
|
soc.builder = builder
|
|
|
|
builder.add_software_package('libxil')
|
|
|
|
builder.add_software_library('libxil')
|
2022-05-06 09:14:32 -04:00
|
|
|
if args.build:
|
2022-11-05 03:07:14 -04:00
|
|
|
builder.build(**parser.toolchain_argdict)
|
2022-01-25 01:20:19 -05:00
|
|
|
|
|
|
|
if args.load:
|
|
|
|
prog = soc.platform.create_programmer(args.cable)
|
2022-03-17 04:21:05 -04:00
|
|
|
prog.load_bitstream(builder.get_bitstream_filename(mode="sram"))
|
2022-01-25 01:20:19 -05:00
|
|
|
|
2022-02-12 12:23:19 -05:00
|
|
|
|
2022-01-25 01:20:19 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|