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 <giacomo.travaglini@arm.com> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/29472 Reviewed-by: Jason Lowe-Power <power.jg@gmail.com> Maintainer: Jason Lowe-Power <power.jg@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -135,11 +135,17 @@ def findPartOffset(devFile, fileName, partition):
|
|||||||
exit(returncode)
|
exit(returncode)
|
||||||
lines = out.splitlines()
|
lines = out.splitlines()
|
||||||
# Make sure the first few lines of the output look like what we expect.
|
# Make sure the first few lines of the output look like what we expect.
|
||||||
assert(lines[0][0] == '#')
|
assert(lines[0][0] == '#' or lines[0].startswith('label:'))
|
||||||
assert(lines[1] == 'unit: sectors')
|
assert(lines[1] == 'unit: sectors' or lines[1].startswith('label-id:'))
|
||||||
assert(lines[2] == '')
|
assert(lines[2] == '' or lines[2].startswith('device:'))
|
||||||
# This line has information about the first partition.
|
if lines[0][0] == '#' :
|
||||||
chunks = lines[3].split()
|
# 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
|
# 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.
|
# a comma. We drop the comma and convert that to an integer.
|
||||||
sectors = string.atoi(chunks[3][:-1])
|
sectors = string.atoi(chunks[3][:-1])
|
||||||
@@ -282,12 +288,11 @@ partitionCom = Command('partition', 'Partition part of "init".',
|
|||||||
[('file', 'Name of the image file.')])
|
[('file', 'Name of the image file.')])
|
||||||
|
|
||||||
def partition(dev, cylinders, heads, sectors):
|
def partition(dev, cylinders, heads, sectors):
|
||||||
# Use fdisk to partition the device
|
# Use sfdisk to partition the device
|
||||||
comStr = '0,\n;\n;\n;\n'
|
# The specified options are intended to work with both new and old
|
||||||
return runPriv([findProg('sfdisk'), '--no-reread', '-D', \
|
# versions of sfdisk (see https://askubuntu.com/a/819614)
|
||||||
'-C', "%d" % cylinders, \
|
comStr = ';'
|
||||||
'-H', "%d" % heads, \
|
return runPriv([findProg('sfdisk'), '--no-reread', '-u', 'S', '-L', \
|
||||||
'-S', "%d" % sectors, \
|
|
||||||
str(dev)], inputVal=comStr)
|
str(dev)], inputVal=comStr)
|
||||||
|
|
||||||
def partitionComFunc(options, args):
|
def partitionComFunc(options, args):
|
||||||
|
|||||||
Reference in New Issue
Block a user