Skip to content

Commit 8066513

Browse files
committed
sim.py: Update/Cleanup.
1 parent 629a46e commit 8066513

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

sim.py

+44-42
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,26 @@
1111

1212
from migen import *
1313

14+
from litex.gen import *
15+
1416
from litex.build.generic_platform import *
15-
from litex.build.sim import SimPlatform
16-
from litex.build.sim.config import SimConfig
17-
from litex.build.sim.verilator import verilator_build_args, verilator_build_argdict
18-
19-
from litex.soc.interconnect.csr import *
20-
from litex.soc.integration.soc_core import *
21-
from litex.soc.integration.builder import *
22-
from litex.soc.interconnect import wishbone
17+
from litex.build.sim import SimPlatform
18+
from litex.build.sim.config import SimConfig
19+
from litex.build.sim.verilator import verilator_build_args, verilator_build_argdict
20+
21+
from litex.soc.interconnect.csr import *
22+
from litex.soc.integration.soc_core import *
23+
from litex.soc.integration.builder import *
24+
from litex.soc.interconnect import wishbone
2325
from litex.soc.cores.cpu.vexriscv_smp import VexRiscvSMP
2426

2527
from litedram import modules as litedram_modules
26-
from litedram.phy.model import SDRAMPHYModel
27-
from litex.tools.litex_sim import sdram_module_nphases, get_sdram_phy_settings
28+
from litedram.phy.model import SDRAMPHYModel
29+
from litex.tools.litex_sim import sdram_module_nphases, get_sdram_phy_settings
2830
from litedram.core.controller import ControllerSettings
2931

3032
from liteeth.phy.model import LiteEthPHYModel
31-
from liteeth.mac import LiteEthMAC
33+
from liteeth.mac import LiteEthMAC
3234

3335
from litex.tools.litex_json2dts_linux import generate_dts
3436

@@ -59,7 +61,7 @@ def __init__(self):
5961

6062
# Supervisor ---------------------------------------------------------------------------------------
6163

62-
class Supervisor(Module, AutoCSR):
64+
class Supervisor(LiteXModule):
6365
def __init__(self):
6466
self._finish = CSR() # Controlled from CPU.
6567
self.finish = Signal() # Controlled from logic.
@@ -68,40 +70,38 @@ def __init__(self):
6870
# SoCLinux -----------------------------------------------------------------------------------------
6971

7072
class SoCLinux(SoCCore):
71-
def __init__(self,
73+
def __init__(self, sys_clk_freq=int(100e6),
7274
init_memories = False,
7375
sdram_module = "MT48LC16M16",
7476
sdram_data_width = 32,
75-
sdram_verbosity = 0):
76-
77-
# Parameters.
78-
sys_clk_freq = int(100e6)
79-
80-
# Platform.
77+
sdram_verbosity = 0
78+
):
79+
# Platform ---------------------------------------------------------------------------------
8180
platform = Platform()
8281
self.comb += platform.trace.eq(1)
8382

84-
# RAM Initialization.
83+
# RAM Init ---------------------------------------------------------------------------------
8584
ram_init = []
8685
if init_memories:
8786
ram_init = get_mem_data("images/boot.json", endianness="little", offset=0x40000000)
8887

8988
# CRG --------------------------------------------------------------------------------------
90-
self.submodules.crg = CRG(platform.request("sys_clk"))
89+
self.crg = CRG(platform.request("sys_clk"))
9190

9291
# SoCCore ----------------------------------------------------------------------------------
9392
SoCCore.__init__(self, platform, clk_freq=sys_clk_freq,
94-
cpu_type = "vexriscv_smp",
95-
cpu_variant = "linux",
96-
integrated_rom_size = 0x10000,
97-
uart_name = "sim")
93+
cpu_type = "vexriscv_smp",
94+
cpu_variant = "linux",
95+
integrated_rom_size = 0x10000,
96+
uart_name = "sim",
97+
)
9898
self.add_config("DISABLE_DELAYS")
9999

100100
# Boot from OpenSBI.
101101
self.add_constant("ROM_BOOT_ADDRESS", self.bus.regions["opensbi"].origin)
102102

103103
# Supervisor -------------------------------------------------------------------------------
104-
self.submodules.supervisor = Supervisor()
104+
self.supervisor = Supervisor()
105105

106106
# SDRAM ------------------------------------------------------------------------------------
107107
sdram_clk_freq = int(100e6) # FIXME: use 100MHz timings
@@ -111,17 +111,20 @@ def __init__(self,
111111
phy_settings = get_sdram_phy_settings(
112112
memtype = sdram_module.memtype,
113113
data_width = sdram_data_width,
114-
clk_freq = sdram_clk_freq)
115-
self.submodules.sdrphy = SDRAMPHYModel(
114+
clk_freq = sdram_clk_freq,
115+
)
116+
self.sdrphy = SDRAMPHYModel(
116117
module = sdram_module,
117118
settings = phy_settings,
118119
clk_freq = sdram_clk_freq,
119120
verbosity = sdram_verbosity,
120-
init = ram_init)
121+
init = ram_init,
122+
)
121123
self.add_sdram("sdram",
122124
phy = self.sdrphy,
123125
module = sdram_module,
124-
l2_cache_size = 0)
126+
l2_cache_size = 0,
127+
)
125128
self.add_constant("SDRAM_TEST_DISABLE") # Skip SDRAM test to avoid corrupting pre-initialized contents.
126129

127130
def generate_dts(self, board_name):
@@ -139,11 +142,11 @@ def compile_dts(self, board_name):
139142
# Build --------------------------------------------------------------------------------------------
140143

141144
def main():
142-
parser = argparse.ArgumentParser(description="Linux on LiteX-VexRiscv Simulation")
143-
parser.add_argument("--with-sdram", action="store_true", help="Enable SDRAM support.")
144-
parser.add_argument("--sdram-module", default="MT48LC16M16", help="Select SDRAM chip.")
145-
parser.add_argument("--sdram-data-width", default=32, help="Set SDRAM chip data width.")
146-
parser.add_argument("--sdram-verbosity", default=0, help="Set SDRAM checker verbosity.")
145+
parser = argparse.ArgumentParser(description="Linux on LiteX-VexRiscv Simulation.")
146+
parser.add_argument("--with-sdram", action="store_true", help="Enable SDRAM support.")
147+
parser.add_argument("--sdram-module", default="MT48LC16M16", help="Select SDRAM chip.")
148+
parser.add_argument("--sdram-data-width", default=32, help="Set SDRAM chip data width.")
149+
parser.add_argument("--sdram-verbosity", default=0, help="Set SDRAM checker verbosity.")
147150
VexRiscvSMP.args_fill(parser)
148151
verilator_build_args(parser)
149152
args = parser.parse_args()
@@ -154,22 +157,21 @@ def main():
154157
sim_config.add_module("serial2console", "serial")
155158

156159
for i in range(2):
160+
prepare = (i == 0)
161+
run = (i == 1)
157162
soc = SoCLinux(
158-
init_memories = i!=0,
163+
init_memories = run,
159164
sdram_module = args.sdram_module,
160165
sdram_data_width = int(args.sdram_data_width),
161166
sdram_verbosity = int(args.sdram_verbosity)
162167
)
163168
board_name = "sim"
164169
build_dir = os.path.join("build", board_name)
165170
builder = Builder(soc, output_dir=build_dir,
166-
compile_gateware = i != 0 ,
171+
compile_gateware = run,
167172
csr_json = os.path.join(build_dir, "csr.json"))
168-
builder.build(sim_config=sim_config,
169-
run = i != 0,
170-
**verilator_build_kwargs
171-
)
172-
if i == 0:
173+
builder.build(sim_config=sim_config, run=run, **verilator_build_kwargs)
174+
if prepare:
173175
soc.generate_dts(board_name)
174176
soc.compile_dts(board_name)
175177

0 commit comments

Comments
 (0)