changeset 4fdc929c0aaa in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=4fdc929c0aaa
description:
        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.

diffstat:

 configs/common/FSConfig.py |  37 +++++++++++++++++++++++++------------
 configs/common/Options.py  |   8 ++++++++
 configs/example/fs.py      |  37 +++++++++++++++++++++++++++----------
 3 files changed, 60 insertions(+), 22 deletions(-)

diffs (186 lines):

diff -r a39de7b8d2c9 -r 4fdc929c0aaa configs/common/FSConfig.py
--- a/configs/common/FSConfig.py        Thu Dec 04 15:53:54 2014 -0800
+++ b/configs/common/FSConfig.py        Thu Dec 04 16:42:07 2014 -0800
@@ -55,7 +55,13 @@
     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 @@
     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 @@
     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 @@
             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 @@
 
         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 @@
     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 @@
     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 @@
     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 @@
     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 -r a39de7b8d2c9 -r 4fdc929c0aaa configs/common/Options.py
--- a/configs/common/Options.py Thu Dec 04 15:53:54 2014 -0800
+++ b/configs/common/Options.py Thu Dec 04 16:42:07 2014 -0800
@@ -265,3 +265,11 @@
     # 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 -r a39de7b8d2c9 -r 4fdc929c0aaa configs/example/fs.py
--- a/configs/example/fs.py     Thu Dec 04 15:53:54 2014 -0800
+++ b/configs/example/fs.py     Thu Dec 04 16:42:07 2014 -0800
@@ -71,20 +71,34 @@
     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 @@
     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)
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to