litex_json2dts_linux: Cleanup bootargs IP address generation.

This commit is contained in:
Florent Kermarrec 2024-06-13 12:14:44 +02:00
parent 02d6e9760a
commit 491974c719
1 changed files with 26 additions and 21 deletions

View File

@ -42,13 +42,13 @@ def generate_dts(d, initrd_start=None, initrd_size=None, initrd=None, root_devic
# Boot Arguments ------------------------------------------------------------------------------- # Boot Arguments -------------------------------------------------------------------------------
# Init Ram Disk.
default_initrd_start = { default_initrd_start = {
"or1k": 8 * MEGABYTE, "or1k": 8 * MEGABYTE,
"riscv": 16 * MEGABYTE, "riscv": 16 * MEGABYTE,
} }
default_initrd_size = 8 * MEGABYTE default_initrd_size = 8 * MEGABYTE
if initrd_start is None: if initrd_start is None:
initrd_start = default_initrd_start[cpu_family] initrd_start = default_initrd_start[cpu_family]
@ -63,23 +63,28 @@ def generate_dts(d, initrd_start=None, initrd_size=None, initrd=None, root_devic
initrd_enabled = True initrd_enabled = True
initrd_size = os.path.getsize(initrd) initrd_size = os.path.getsize(initrd)
# if json constants contains localip ethernet has been enabled # Root Filesystem.
if "localip1" in d["constants"]:
localip = '.'.join([str(d["constants"][f"localip{i}"]) for i in range(1,5)])
remoteip = '.'.join([str(d["constants"][f"remoteip{i}"]) for i in range(1,5)])
ip = f" ip={localip}:{remoteip}:{remoteip}:255.255.255.0::eth0:off:::"
else:
ip = ""
if root_device is None: if root_device is None:
root_device = "ram0" root_device = "ram0"
# Ethernet IP Address.
def get_eth_ip_config():
def get_ip_address(prefix):
return '.'.join(str(d["constants"][f"{prefix}{i+1}"]) for i in range(4))
ip_config = ""
if all(f"localip{i + 1}" in d["constants"] for i in range(4)):
local_ip = get_ip_address("localip")
remote_ip = get_ip_address("remoteip")
ip_config = f" ip={local_ip}:{remote_ip}:{remote_ip}:255.255.255.0::eth0:off:::"
return ip_config
# Bootargs Generation.
dts += """ dts += """
chosen {{ chosen {{
bootargs = "{console} {rootfs}{ip}";""".format( bootargs = "{console} {rootfs}{ip}";""".format(
console = "console=liteuart earlycon=liteuart,0x{:x}".format(d["csr_bases"]["uart"]), console = "console=liteuart earlycon=liteuart,0x{:x}".format(d["csr_bases"]["uart"]),
rootfs = "rootwait root=/dev/{}".format(root_device), rootfs = "rootwait root=/dev/{}".format(root_device),
ip = ip) ip = get_eth_ip_config())
if initrd_enabled is True: if initrd_enabled is True:
dts += """ dts += """
@ -92,7 +97,7 @@ def generate_dts(d, initrd_start=None, initrd_size=None, initrd=None, root_devic
}; };
""" """
# Clocks ------------------------------------------------------------------------------------------ # Clocks ---------------------------------------------------------------------------------------
for c in [c for c in d["constants"].keys() if c.endswith("config_clock_frequency")]: for c in [c for c in d["constants"].keys() if c.endswith("config_clock_frequency")]:
name = c.removesuffix("config_clock_frequency") + "sys_clk" name = c.removesuffix("config_clock_frequency") + "sys_clk"
@ -340,8 +345,8 @@ def generate_dts(d, initrd_start=None, initrd_size=None, initrd=None, root_devic
reg-names = "control"; reg-names = "control";
}}; }};
""".format( """.format(
clint_base=d["memories"]["clint"]["base"], clint_base = d["memories"]["clint"]["base"],
cpu_mapping =("\n" + " "*20).join(["&L{} 3 &L{} 7".format(cpu, cpu) for cpu in range(cpu_count)])) cpu_mapping = ("\n" + " "*20).join(["&L{} 3 &L{} 7".format(cpu, cpu) for cpu in range(cpu_count)]))
if cpu_family == "riscv": if cpu_family == "riscv":
if cpu_name == "rocket": if cpu_name == "rocket":
extra_attr = """ extra_attr = """
@ -364,9 +369,9 @@ def generate_dts(d, initrd_start=None, initrd_size=None, initrd=None, root_devic
{extra_attr} {extra_attr}
}}; }};
""".format( """.format(
plic_base =d["memories"]["plic"]["base"], plic_base = d["memories"]["plic"]["base"],
cpu_mapping =("\n" + " "*20).join(["&L{} 11 &L{} 9".format(cpu, cpu) for cpu in range(cpu_count)]), cpu_mapping = ("\n" + " "*20).join(["&L{} 11 &L{} 9".format(cpu, cpu) for cpu in range(cpu_count)]),
extra_attr =extra_attr) extra_attr = extra_attr)
elif cpu_family == "or1k": elif cpu_family == "or1k":
dts += """ dts += """