From 7540656fc5b8ce0cafb54f41b913a7e81cbfb4b3 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 4 Dec 2014 16:42:07 -0800 Subject: [PATCH] config: Add two options for setting the kernel command line. Both options accept template which will, through python string formatting, have "mem", "disk", and "script" values substituted in from the mdesc. Additional values can be used on a case by case basis by passing them as keyword arguments to the fillInCmdLine function. That makes it possible to have specialized parameters for a particular ISA, for instance. The first option lets you specify the template directly, and the other lets you specify a file which has the template in it. --- configs/common/FSConfig.py | 37 +++++++++++++++++++++++++------------ configs/common/Options.py | 8 ++++++++ configs/example/fs.py | 37 +++++++++++++++++++++++++++---------- 3 files changed, 60 insertions(+), 22 deletions(-) diff --git a/configs/common/FSConfig.py b/configs/common/FSConfig.py index 56a2a15ea..50c5bc4ff 100644 --- a/configs/common/FSConfig.py +++ b/configs/common/FSConfig.py @@ -55,7 +55,13 @@ class MemBus(CoherentXBar): default = Self.badaddr_responder.pio -def makeLinuxAlphaSystem(mem_mode, mdesc=None, ruby=False): +def fillInCmdline(mdesc, template, **kwargs): + kwargs.setdefault('disk', mdesc.disk()) + kwargs.setdefault('mem', mdesc.mem()) + kwargs.setdefault('script', mdesc.script()) + return template % kwargs + +def makeLinuxAlphaSystem(mem_mode, mdesc=None, ruby=False, cmdline=None): class BaseTsunami(Tsunami): ethernet = NSGigE(pci_bus=0, pci_dev=1, pci_func=0) @@ -113,7 +119,9 @@ def makeLinuxAlphaSystem(mem_mode, mdesc=None, ruby=False): self.kernel = binary('vmlinux') self.pal = binary('ts_osfpal') self.console = binary('console') - self.boot_osflags = 'root=/dev/hda1 console=ttyS0' + if not cmdline: + cmdline = 'root=/dev/hda1 console=ttyS0' + self.boot_osflags = fillInCmdline(mdesc, cmdline) return self @@ -183,7 +191,7 @@ def makeSparcSystem(mem_mode, mdesc=None): return self def makeArmSystem(mem_mode, machine_type, num_cpus=1, mdesc=None, - dtb_filename=None, bare_metal=False): + dtb_filename=None, bare_metal=False, cmdline=None): assert machine_type if bare_metal: @@ -268,9 +276,10 @@ def makeArmSystem(mem_mode, machine_type, num_cpus=1, mdesc=None, self.dtb_filename = binary(dtb_filename) self.machine_type = machine_type # Ensure that writes to the UART actually go out early in the boot - boot_flags = 'earlyprintk=pl011,0x1c090000 console=ttyAMA0 ' + \ - 'lpj=19988480 norandmaps rw loglevel=8 ' + \ - 'mem=%s root=/dev/sda1' % mdesc.mem() + if not cmdline: + cmdline = 'earlyprintk=pl011,0x1c090000 console=ttyAMA0 ' + \ + 'lpj=19988480 norandmaps rw loglevel=8 ' + \ + 'mem=%(mem)s root=/dev/sda1' self.realview.setupBootLoader(self.membus, self, binary) self.gic_cpu_addr = self.realview.gic.cpu_addr @@ -278,7 +287,7 @@ def makeArmSystem(mem_mode, machine_type, num_cpus=1, mdesc=None, if mdesc.disk().lower().count('android'): boot_flags += " init=/init " - self.boot_osflags = boot_flags + self.boot_osflags = fillInCmdline(mdesc, cmdline) self.realview.attachOnChipIO(self.membus, self.bridge) self.realview.attachIO(self.iobus) self.intrctrl = IntrControl() @@ -290,7 +299,7 @@ def makeArmSystem(mem_mode, machine_type, num_cpus=1, mdesc=None, return self -def makeLinuxMipsSystem(mem_mode, mdesc=None): +def makeLinuxMipsSystem(mem_mode, mdesc=None, cmdline=None): class BaseMalta(Malta): ethernet = NSGigE(pci_bus=0, pci_dev=1, pci_func=0) ide = IdeController(disks=[Parent.disk0, Parent.disk2], @@ -326,7 +335,9 @@ def makeLinuxMipsSystem(mem_mode, mdesc=None): self.terminal = Terminal() self.kernel = binary('mips/vmlinux') self.console = binary('mips/console') - self.boot_osflags = 'root=/dev/hda1 console=ttyS0' + if not cmdline: + cmdline = 'root=/dev/hda1 console=ttyS0' + self.boot_osflags = fillInCmdline(mdesc, cmdline) self.system_port = self.membus.slave @@ -501,7 +512,8 @@ def makeX86System(mem_mode, numCPUs=1, mdesc=None, self=None, Ruby=False): self.intel_mp_table.base_entries = base_entries self.intel_mp_table.ext_entries = ext_entries -def makeLinuxX86System(mem_mode, numCPUs=1, mdesc=None, Ruby=False): +def makeLinuxX86System(mem_mode, numCPUs=1, mdesc=None, Ruby=False, + cmdline=None): self = LinuxX86System() # Build up the x86 system and then specialize it for Linux @@ -546,8 +558,9 @@ def makeLinuxX86System(mem_mode, numCPUs=1, mdesc=None, Ruby=False): self.e820_table.entries = entries # Command line - self.boot_osflags = 'earlyprintk=ttyS0 console=ttyS0 lpj=7999923 ' + \ - 'root=/dev/hda1' + if not cmdline: + cmdline = 'earlyprintk=ttyS0 console=ttyS0 lpj=7999923 root=/dev/hda1' + self.boot_osflags = fillInCmdline(mdesc, cmdline) self.kernel = binary('x86_64-vmlinux-2.6.22.9') return self diff --git a/configs/common/Options.py b/configs/common/Options.py index 19c504d97..a788af290 100644 --- a/configs/common/Options.py +++ b/configs/common/Options.py @@ -265,3 +265,11 @@ def addFSOptions(parser): # Disk Image Options parser.add_option("--disk-image", action="store", type="string", default=None, help="Path to the disk image to use.") + + # Command line options + parser.add_option("--command-line", action="store", type="string", + default=None, + help="Template for the kernel command line.") + parser.add_option("--command-line-file", action="store", + default=None, type="string", + help="File with a template for the kernel command line") diff --git a/configs/example/fs.py b/configs/example/fs.py index 0277feef3..62a298559 100644 --- a/configs/example/fs.py +++ b/configs/example/fs.py @@ -71,20 +71,34 @@ def is_kvm_cpu(cpu_class): return have_kvm_support and cpu_class != None and \ issubclass(cpu_class, BaseKvmCPU) +def cmd_line_template(): + if options.command_line and options.command_line_file: + print "Error: --command-line and --command-line-file are " \ + "mutually exclusive" + sys.exit(1) + if options.command_line: + return options.command_line + if options.command_line_file: + return open(options.command_line_file).read().strip() + return None + def build_test_system(np): + cmdline = cmd_line_template() if buildEnv['TARGET_ISA'] == "alpha": - test_sys = makeLinuxAlphaSystem(test_mem_mode, bm[0], options.ruby) + test_sys = makeLinuxAlphaSystem(test_mem_mode, bm[0], options.ruby, + cmdline=cmdline) elif buildEnv['TARGET_ISA'] == "mips": - test_sys = makeLinuxMipsSystem(test_mem_mode, bm[0]) + test_sys = makeLinuxMipsSystem(test_mem_mode, bm[0], cmdline=cmdline) elif buildEnv['TARGET_ISA'] == "sparc": - test_sys = makeSparcSystem(test_mem_mode, bm[0]) + test_sys = makeSparcSystem(test_mem_mode, bm[0], cmdline=cmdline) elif buildEnv['TARGET_ISA'] == "x86": test_sys = makeLinuxX86System(test_mem_mode, options.num_cpus, bm[0], - options.ruby) + options.ruby, cmdline=cmdline) elif buildEnv['TARGET_ISA'] == "arm": test_sys = makeArmSystem(test_mem_mode, options.machine_type, options.num_cpus, bm[0], options.dtb_filename, - bare_metal=options.bare_metal) + bare_metal=options.bare_metal, + cmdline=cmdline) if options.enable_context_switch_stats_dump: test_sys.enable_context_switch_stats_dump = True else: @@ -202,16 +216,19 @@ def build_drive_system(np): drive_mem_mode = 'atomic' DriveMemClass = SimpleMemory + cmdline = cmd_line_template() if buildEnv['TARGET_ISA'] == 'alpha': - drive_sys = makeLinuxAlphaSystem(drive_mem_mode, bm[1]) + drive_sys = makeLinuxAlphaSystem(drive_mem_mode, bm[1], cmdline=cmdline) elif buildEnv['TARGET_ISA'] == 'mips': - drive_sys = makeLinuxMipsSystem(drive_mem_mode, bm[1]) + drive_sys = makeLinuxMipsSystem(drive_mem_mode, bm[1], cmdline=cmdline) elif buildEnv['TARGET_ISA'] == 'sparc': - drive_sys = makeSparcSystem(drive_mem_mode, bm[1]) + drive_sys = makeSparcSystem(drive_mem_mode, bm[1], cmdline=cmdline) elif buildEnv['TARGET_ISA'] == 'x86': - drive_sys = makeLinuxX86System(drive_mem_mode, np, bm[1]) + drive_sys = makeLinuxX86System(drive_mem_mode, np, bm[1], + cmdline=cmdline) elif buildEnv['TARGET_ISA'] == 'arm': - drive_sys = makeArmSystem(drive_mem_mode, options.machine_type, bm[1]) + drive_sys = makeArmSystem(drive_mem_mode, options.machine_type, bm[1], + cmdline=cmdline) # Create a top-level voltage domain drive_sys.voltage_domain = VoltageDomain(voltage = options.sys_voltage)