Richard Cooper has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/29472 )

Change subject: misc: Fix util/gem5img.py for new versions of sfdisk
......................................................................

misc: Fix util/gem5img.py for new versions of sfdisk

Newer versions of sfdisk have changed the format of the dump output,
as well as the options for partitioning a disk.

Updated the gem5img.py script to work with the new version of sfdisk.
The script should still work with older versions of sfdisk, but this
has not been tested (see https://askubuntu.com/a/819614).

Tested on Ubuntu 18.04.2 LTS with sfdisk from util-linux 2.31.1.

Change-Id: I1197ecacabdd7caaab00327977fb9ab6eae06654
Reviewed-by: Giacomo Travaglini <[email protected]>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/29472
Reviewed-by: Jason Lowe-Power <[email protected]>
Maintainer: Jason Lowe-Power <[email protected]>
Tested-by: kokoro <[email protected]>
---
M util/gem5img.py
1 file changed, 16 insertions(+), 11 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/util/gem5img.py b/util/gem5img.py
index 607f034..51a5487 100755
--- a/util/gem5img.py
+++ b/util/gem5img.py
@@ -135,11 +135,17 @@
         exit(returncode)
     lines = out.splitlines()
     # Make sure the first few lines of the output look like what we expect.
-    assert(lines[0][0] == '#')
-    assert(lines[1] == 'unit: sectors')
-    assert(lines[2] == '')
-    # This line has information about the first partition.
-    chunks = lines[3].split()
+    assert(lines[0][0] == '#' or lines[0].startswith('label:'))
+    assert(lines[1] == 'unit: sectors' or lines[1].startswith('label-id:'))
+    assert(lines[2] == '' or lines[2].startswith('device:'))
+    if lines[0][0] == '#' :
+        # Parsing an 'old style' dump oputput
+        # Line 4 has information about the first partition.
+        chunks = lines[3].split()
+    else :
+        # Parsing a 'new style' dump oputput
+        # Line 6 has information about the first partition.
+        chunks = lines[5].split()
# The fourth chunk is the offset of the partition in sectors followed by
     # a comma. We drop the comma and convert that to an integer.
     sectors = string.atoi(chunks[3][:-1])
@@ -282,12 +288,11 @@
                        [('file', 'Name of the image file.')])

 def partition(dev, cylinders, heads, sectors):
-    # Use fdisk to partition the device
-    comStr = '0,\n;\n;\n;\n'
-    return runPriv([findProg('sfdisk'), '--no-reread', '-D', \
-                   '-C', "%d" % cylinders, \
-                   '-H', "%d" % heads, \
-                   '-S', "%d" % sectors, \
+    # Use sfdisk to partition the device
+    # The specified options are intended to work with both new and old
+    # versions of sfdisk (see https://askubuntu.com/a/819614)
+    comStr = ';'
+    return runPriv([findProg('sfdisk'), '--no-reread', '-u', 'S', '-L', \
                    str(dev)], inputVal=comStr)

 def partitionComFunc(options, args):

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/29472
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I1197ecacabdd7caaab00327977fb9ab6eae06654
Gerrit-Change-Number: 29472
Gerrit-PatchSet: 2
Gerrit-Owner: Richard Cooper <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Ciro Santilli <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Richard Cooper <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to