From 49ae60abe4052e4ca5556db73ba57caf73eb27a3 Mon Sep 17 00:00:00 2001 From: Richard Cooper Date: Mon, 27 Apr 2020 11:16:24 +0100 Subject: [PATCH] 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 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/29472 Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- util/gem5img.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/util/gem5img.py b/util/gem5img.py index 607f034e2..51a5487fd 100755 --- a/util/gem5img.py +++ b/util/gem5img.py @@ -135,11 +135,17 @@ def findPartOffset(devFile, fileName, partition): 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 @@ partitionCom = Command('partition', 'Partition part of "init".', [('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): -- 2.30.2