From ea06948c62d3c47bfb295d1cc9ae44629d460621 Mon Sep 17 00:00:00 2001 From: Stafford Horne Date: Sun, 12 Sep 2021 09:31:52 +0900 Subject: [PATCH] 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)