From 378d129c5f40e2fa7bb6645f16b5d6a33272c399 Mon Sep 17 00:00:00 2001 From: Stafford Horne Date: Sun, 12 Sep 2021 07:35:32 +0900 Subject: [PATCH 1/3] json2dts_linux: Allow disabling of initrd --- litex/tools/litex_json2dts_linux.py | 37 +++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/litex/tools/litex_json2dts_linux.py b/litex/tools/litex_json2dts_linux.py index 97016e88a..5139dd5a4 100755 --- a/litex/tools/litex_json2dts_linux.py +++ b/litex/tools/litex_json2dts_linux.py @@ -10,9 +10,9 @@ import sys import json import argparse +import os - -def generate_dts(d, initrd_start=None, initrd_size=None, polling=False): +def generate_dts(d, initrd_start=None, initrd_size=None, initrd=None, polling=False): kB = 1024 mB = kB*1024 @@ -44,18 +44,32 @@ def generate_dts(d, initrd_start=None, initrd_size=None, polling=False): if initrd_size is None: initrd_size = default_initrd_size + if initrd == "enabled" or initrd is None: + initrd_enabled = True + elif initrd == "disabled": + initrd_enabled = False + else: + initrd_enabled = True + initrd_size = os.path.getsize(initrd) + dts += """ chosen {{ - bootargs = "mem={main_ram_size_mb}M@0x{main_ram_base:x} rootwait console=liteuart earlycon=sbi root=/dev/ram0 init=/sbin/init swiotlb=32"; - linux,initrd-start = <0x{linux_initrd_start:x}>; - linux,initrd-end = <0x{linux_initrd_end:x}>; - }}; -""".format( + bootargs = "mem={main_ram_size_mb}M@0x{main_ram_base:x} {console} {rootfs} init=/sbin/init swiotlb=32";""".format( main_ram_base = d["memories"]["main_ram"]["base"], - main_ram_size = d["memories"]["main_ram"]["size"], main_ram_size_mb = d["memories"]["main_ram"]["size"] // mB, - linux_initrd_start = d["memories"]["main_ram"]["base"] + initrd_start, - linux_initrd_end = d["memories"]["main_ram"]["base"] + initrd_start + initrd_size) + console = "console=liteuart earlycon=sbi", + rootfs = "rootwait root=/dev/ram0") + + if initrd_enabled is True: + dts += """ + linux,initrd-start = <0x{linux_initrd_start:x}>; + linux,initrd-end = <0x{linux_initrd_end:x}>;""".format( + linux_initrd_start = d["memories"]["main_ram"]["base"] + initrd_start, + linux_initrd_end = d["memories"]["main_ram"]["base"] + initrd_start + initrd_size) + + dts += """ + }; +""" # CPU ------------------------------------------------------------------------------------------ @@ -624,10 +638,12 @@ def generate_dts(d, initrd_start=None, initrd_size=None, polling=False): return dts def main(): + parser = argparse.ArgumentParser(description="LiteX's CSR JSON to Linux DTS generator") parser.add_argument("csr_json", help="CSR JSON file") parser.add_argument("--initrd-start", type=int, help="Location of initrd in RAM (relative, default depends on CPU)") parser.add_argument("--initrd-size", type=int, help="Size of initrd (default=8MB)") + parser.add_argument("--initrd", type=str, help="Supports arguments 'enabled', 'disabled' or a file name. Set to 'disabled' if you use a kernel built in rootfs or have your rootfs on an SD card partition. If a file name is provied the size of the file will be used instead of --initrd-size. (default=enabled)") parser.add_argument("--polling", action="store_true", help="Force polling mode on peripherals") args = parser.parse_args() @@ -635,6 +651,7 @@ def main(): r = generate_dts(d, initrd_start = args.initrd_start, initrd_size = args.initrd_size, + initrd = args.initrd, polling = args.polling, ) print(r) From ec2f2a6af5e55b4b7ad2766cebe379135c5e047e Mon Sep 17 00:00:00 2001 From: Stafford Horne Date: Sun, 12 Sep 2021 07:39:47 +0900 Subject: [PATCH 2/3] json2dts_linux: Use liteuart earlycon Now that liteuart earlycon is upstream we can use it. This means all litex soc's should be able to get an earlycon now. Tested on mor1kx. --- litex/tools/litex_json2dts_linux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litex/tools/litex_json2dts_linux.py b/litex/tools/litex_json2dts_linux.py index 5139dd5a4..a8fc2242a 100755 --- a/litex/tools/litex_json2dts_linux.py +++ b/litex/tools/litex_json2dts_linux.py @@ -57,7 +57,7 @@ def generate_dts(d, initrd_start=None, initrd_size=None, initrd=None, polling=Fa bootargs = "mem={main_ram_size_mb}M@0x{main_ram_base:x} {console} {rootfs} init=/sbin/init swiotlb=32";""".format( main_ram_base = d["memories"]["main_ram"]["base"], main_ram_size_mb = d["memories"]["main_ram"]["size"] // mB, - console = "console=liteuart earlycon=sbi", + console = "console=liteuart earlycon=liteuart,0x{:x}".format(d["csr_bases"]["uart"]), rootfs = "rootwait root=/dev/ram0") if initrd_enabled is True: From ea06948c62d3c47bfb295d1cc9ae44629d460621 Mon Sep 17 00:00:00 2001 From: Stafford Horne Date: Sun, 12 Sep 2021 09:31:52 +0900 Subject: [PATCH 3/3] json2dts_linux: Add configuration for root device This allows setting a root device other than ram0, this is useful when using a rootfs from the SD card. Doing this makes boot time faster and saves on memory footprint used by an in ram initrd. --- litex/tools/litex_json2dts_linux.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/litex/tools/litex_json2dts_linux.py b/litex/tools/litex_json2dts_linux.py index a8fc2242a..601208e7e 100755 --- a/litex/tools/litex_json2dts_linux.py +++ b/litex/tools/litex_json2dts_linux.py @@ -12,7 +12,7 @@ import json import argparse import os -def generate_dts(d, initrd_start=None, initrd_size=None, initrd=None, polling=False): +def generate_dts(d, initrd_start=None, initrd_size=None, initrd=None, root_device=None, polling=False): kB = 1024 mB = kB*1024 @@ -52,13 +52,16 @@ def generate_dts(d, initrd_start=None, initrd_size=None, initrd=None, polling=Fa initrd_enabled = True initrd_size = os.path.getsize(initrd) + if root_device is None: + root_device = "ram0" + dts += """ chosen {{ bootargs = "mem={main_ram_size_mb}M@0x{main_ram_base:x} {console} {rootfs} init=/sbin/init swiotlb=32";""".format( main_ram_base = d["memories"]["main_ram"]["base"], main_ram_size_mb = d["memories"]["main_ram"]["size"] // mB, console = "console=liteuart earlycon=liteuart,0x{:x}".format(d["csr_bases"]["uart"]), - rootfs = "rootwait root=/dev/ram0") + rootfs = "rootwait root=/dev/{}".format(root_device)) if initrd_enabled is True: dts += """ @@ -644,6 +647,7 @@ def main(): parser.add_argument("--initrd-start", type=int, help="Location of initrd in RAM (relative, default depends on CPU)") parser.add_argument("--initrd-size", type=int, help="Size of initrd (default=8MB)") parser.add_argument("--initrd", type=str, help="Supports arguments 'enabled', 'disabled' or a file name. Set to 'disabled' if you use a kernel built in rootfs or have your rootfs on an SD card partition. If a file name is provied the size of the file will be used instead of --initrd-size. (default=enabled)") + parser.add_argument("--root-device", type=str, help="Device that has our rootfs, if using initrd use the default. For SD card's use something like mmcblk0p3. (default=ram0)") parser.add_argument("--polling", action="store_true", help="Force polling mode on peripherals") args = parser.parse_args() @@ -652,6 +656,7 @@ def main(): initrd_start = args.initrd_start, initrd_size = args.initrd_size, initrd = args.initrd, + root_device = args.root_device, polling = args.polling, ) print(r)