summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kraft <george.kraft@calxeda.com>2012-08-28 10:38:57 -0500
committerGeorge Kraft <george.kraft@calxeda.com>2012-08-28 10:38:57 -0500
commit524194f9a93ba578f9ba6e48282f72e57632c1d8 (patch)
tree27756eddfd8e2074e26cdc91280d0b41e9a1961b
parent7a7c956facb72e13b65bce402ab43caacbe6bd8e (diff)
downloadcxmanage-524194f9a93ba578f9ba6e48282f72e57632c1d8.tar.gz
cxmanage: Rename simg "version" to "priority"
This includes renaming the fwupdate/cxpackage "--version" option to "--priority".
-rw-r--r--cxmanage/controller.py22
-rw-r--r--cxmanage/image.py14
-rw-r--r--cxmanage/simg.py16
-rw-r--r--cxmanage/target.py50
-rw-r--r--cxmanage_test/image_test.py6
-rw-r--r--cxmanage_test/target_test.py8
-rwxr-xr-xscripts/cxmanage10
-rwxr-xr-xscripts/cxpackage8
8 files changed, 69 insertions, 65 deletions
diff --git a/cxmanage/controller.py b/cxmanage/controller.py
index 6d2e452..13d0b5e 100644
--- a/cxmanage/controller.py
+++ b/cxmanage/controller.py
@@ -87,7 +87,7 @@ class Controller:
########################### Images-specific methods ##########################
def add_image(self, filename, image_type, simg=None,
- version=None, daddr=None, skip_crc32=False):
+ priority=None, daddr=None, skip_crc32=False):
""" Add an image to our collection """
if image_type == "PACKAGE":
# Extract files and read config
@@ -106,15 +106,15 @@ class Controller:
filename = "%s/%s" % (self.work_dir, section)
image_type = config.get(section, "type").upper()
image_simg = simg
- image_version = version
+ image_priority = priority
image_daddr = daddr
image_skip_crc32 = skip_crc32
# Read image options from config
if simg == None and config.has_option(section, "simg"):
image_simg = config.getboolean(section, "simg")
- if version == None and config.has_option(section, "version"):
- image_version = config.getint(section, "version")
+ if priority == None and config.has_option(section, "priority"):
+ image_priority = config.getint(section, "priority")
if daddr == None and config.has_option(section, "daddr"):
image_daddr = int(config.get(section, "daddr"), 16)
if (skip_crc32 == False and
@@ -122,12 +122,12 @@ class Controller:
image_skip_crc32 = config.getboolean(section, "skip_crc32")
image = self.image_class(filename, image_type, image_simg,
- image_version, image_daddr, image_skip_crc32)
+ image_priority, image_daddr, image_skip_crc32)
self.images.append(image)
else:
image = self.image_class(filename, image_type,
- simg, version, daddr, skip_crc32)
+ simg, priority, daddr, skip_crc32)
self.images.append(image)
def save_package(self, filename):
@@ -139,8 +139,8 @@ class Controller:
config.add_section(section)
config.set(section, "type", image.type)
config.set(section, "simg", str(image.simg))
- if image.version != None:
- config.set(section, "version", str(image.version))
+ if image.priority != None:
+ config.set(section, "priority", str(image.priority))
if image.daddr != None:
config.set(section, "daddr", "%x" % image.daddr)
if image.skip_crc32:
@@ -167,8 +167,8 @@ class Controller:
print "File: %s" % os.path.basename(image.filename)
print "Type: %s" % image.type
print "SIMG: %s" % image.simg
- if image.version != None:
- print "Version: %i" % image.version
+ if image.priority != None:
+ print "Priority: %i" % image.priority
if image.daddr != None:
print "Daddr: %x" % image.daddr
if image.skip_crc32:
@@ -323,7 +323,7 @@ class Controller:
print "Type : %s" % partition.type
print "Offset : %s" % partition.offset
print "Size : %s" % partition.size
- print "Version : %s" % partition.version
+ print "Priority : %s" % partition.priority
print "Daddr : %s" % partition.daddr
print "Flags : %s" % partition.flags
print "In Use : %s" % partition.in_use
diff --git a/cxmanage/image.py b/cxmanage/image.py
index 51f6816..8213ea4 100644
--- a/cxmanage/image.py
+++ b/cxmanage/image.py
@@ -42,10 +42,10 @@ class Image:
to build an SIMG out of it. """
def __init__(self, filename, image_type, simg=None,
- version=None, daddr=None, skip_crc32=False):
+ priority=None, daddr=None, skip_crc32=False):
self.filename = filename
self.type = image_type
- self.version = version
+ self.priority = priority
self.daddr = daddr
self.skip_crc32 = skip_crc32
@@ -62,7 +62,7 @@ class Image:
raise CxmanageError("%s is not a valid %s image" %
(os.path.basename(filename), image_type))
- def upload(self, work_dir, tftp, version, daddr):
+ def upload(self, work_dir, tftp, priority, daddr):
""" Create and upload an SIMG file """
filename = self.filename
@@ -70,15 +70,15 @@ class Image:
if not self.simg:
contents = open(filename).read()
- # Figure out version and daddr
- if self.version != None:
- version = self.version
+ # Figure out priority and daddr
+ if self.priority != None:
+ priority = self.priority
if self.daddr != None:
daddr = self.daddr
# Create simg
align = (self.type in ["CDB", "BOOT_LOG"])
- simg = create_simg(contents, version=version, daddr=daddr,
+ simg = create_simg(contents, priority=priority, daddr=daddr,
skip_crc32=self.skip_crc32, align=align)
filename = tempfile.mkstemp(".simg", work_dir + "/")[1]
open(filename, "w").write(simg)
diff --git a/cxmanage/simg.py b/cxmanage/simg.py
index a6bfd0e..70ca37d 100644
--- a/cxmanage/simg.py
+++ b/cxmanage/simg.py
@@ -42,7 +42,7 @@ class SIMGHeader:
if header_string == None:
self.magic_string = 'SIMG'
self.hdrfmt = 0
- self.version = 0
+ self.priority = 0
self.imgoff = 28
self.imglen = 0
self.daddr = 0
@@ -52,7 +52,7 @@ class SIMGHeader:
tup = struct.unpack('<4sHHIIIII', header_string)
self.magic_string = tup[0]
self.hdrfmt = tup[1]
- self.version = tup[2]
+ self.priority = tup[2]
self.imgoff = tup[3]
self.imglen = tup[4]
self.daddr = tup[5]
@@ -63,7 +63,7 @@ class SIMGHeader:
return struct.pack('<4sHHIIIII',
self.magic_string,
self.hdrfmt,
- self.version,
+ self.priority,
self.imgoff,
self.imglen,
self.daddr,
@@ -71,14 +71,10 @@ class SIMGHeader:
self.crc32)
-def create_simg(contents, version=0, daddr=0, skip_crc32=False, align=False):
- """Create an SIMG version of a file
-
- Assumes version and hdrfmt are 0.
- """
-
+def create_simg(contents, priority=0, daddr=0, skip_crc32=False, align=False):
+ """Create an SIMG version of a file"""
header = SIMGHeader()
- header.version = version
+ header.priority = priority
header.imglen = len(contents)
header.daddr = daddr
diff --git a/cxmanage/target.py b/cxmanage/target.py
index 77eccd6..2cced8b 100644
--- a/cxmanage/target.py
+++ b/cxmanage/target.py
@@ -226,6 +226,14 @@ class Target:
if len(fwinfo) == 0:
raise CxmanageError("Failed to retrieve firmware info")
+ # For compatibility with old ipmitool versions, make sure
+ # we have a "priority" field. It used to be called "version"
+ for entry in fwinfo:
+ if not hasattr(entry, "priority"):
+ entry.priority = entry.version
+ entry.version = "Unknown"
+
+ # TODO: remove this later
# Flag CDB as "in use" based on socman info
for a in range(1, len(fwinfo)):
previous = fwinfo[a-1]
@@ -246,17 +254,17 @@ class Target:
""" Update firmware on this target. """
fwinfo = self.get_firmware_info()
- # Get the new version
- version = 0
+ # Get the new priority
+ priority = 0
image_types = [x.type for x in images]
for partition in fwinfo:
# Make sure this partition is one of the types we're updating
# and that the partition is flagged as "active"
if (partition.type.split()[1][1:-1] in image_types and
int(partition.flags, 16) & 2 == 0):
- version = max(version, int(partition.version, 16) + 1)
- if version > 0xFFFF:
- raise CxmanageError("Unable to increment SIMG version, too high")
+ priority = max(priority, int(partition.priority, 16) + 1)
+ if priority > 0xFFFF:
+ raise CxmanageError("Unable to increment SIMG priority, too high")
for image in images:
if image.type == "UBOOTENV":
@@ -275,12 +283,12 @@ class Target:
ubootenv = self.ubootenv_class(contents)
ubootenv.variables["bootcmd_default"] = bootcmd
self._upload_ubootenv(tftp, ubootenv,
- running_part, version)
+ running_part, priority)
else:
- self._upload_image(tftp, image, running_part, version)
+ self._upload_image(tftp, image, running_part, priority)
# Update factory ubootenv
- self._upload_image(tftp, image, factory_part, version)
+ self._upload_image(tftp, image, factory_part, priority)
else:
# Get the partitions
@@ -294,7 +302,7 @@ class Target:
# Update the image
for partition in partitions:
- self._upload_image(tftp, image, partition, version)
+ self._upload_image(tftp, image, partition, priority)
def config_reset(self, tftp):
""" Reset configuration to factory default """
@@ -326,8 +334,8 @@ class Target:
# Download active ubootenv, modify, then upload to first partition
ubootenv = self._download_ubootenv(tftp, active_part)
ubootenv.set_boot_order(boot_args)
- version = max(int(x.version, 16) for x in [first_part, active_part])
- self._upload_ubootenv(tftp, ubootenv, first_part, version)
+ priority = max(int(x.priority, 16) for x in [first_part, active_part])
+ self._upload_ubootenv(tftp, ubootenv, first_part, priority)
def get_boot_order(self, tftp):
""" Get boot order """
@@ -389,39 +397,39 @@ class Target:
elif partition_arg == "OLDEST":
# Return the oldest partition
partitions.sort(key=lambda x: x.partition, reverse=True)
- partitions.sort(key=lambda x: x.version)
+ partitions.sort(key=lambda x: x.priority)
return partitions[0]
elif partition_arg == "NEWEST":
# Return the newest partition
partitions.sort(key=lambda x: x.partition)
- partitions.sort(key=lambda x: x.version, reverse=True)
+ partitions.sort(key=lambda x: x.priority, reverse=True)
return partitions[0]
elif partition_arg == "INACTIVE":
# Return the partition that's not in use (or least likely to be)
partitions.sort(key=lambda x: x.partition, reverse=True)
- partitions.sort(key=lambda x: x.version)
+ partitions.sort(key=lambda x: x.priority)
partitions.sort(key=lambda x: int(x.flags, 16) & 2 == 0)
partitions.sort(key=lambda x: x.in_use == "1")
return partitions[0]
elif partition_arg == "ACTIVE":
# Return the partition that's in use (or most likely to be)
partitions.sort(key=lambda x: x.partition)
- partitions.sort(key=lambda x: x.version, reverse=True)
+ partitions.sort(key=lambda x: x.priority, reverse=True)
partitions.sort(key=lambda x: int(x.flags, 16) & 2 == 1)
partitions.sort(key=lambda x: x.in_use == "0")
return partitions[0]
else:
raise ValueError("Invalid partition argument: %s" % partition_arg)
- def _upload_image(self, tftp, image, partition, version=None):
+ def _upload_image(self, tftp, image, partition, priority=None):
""" Upload a single image. This includes uploading the image,
performing the firmware update, crc32 check, and activation."""
tftp_address = "%s:%s" % (tftp.get_address(self.address),
tftp.get_port())
partition_id = int(partition.partition)
- if version == None:
- version = int(partition.version, 16)
+ if priority == None:
+ priority = int(partition.priority, 16)
daddr = int(partition.daddr, 16)
# Check image size
@@ -430,7 +438,7 @@ class Target:
image.type, partition_id)
# Upload image to tftp server
- filename = image.upload(self.work_dir, tftp, version, daddr)
+ filename = image.upload(self.work_dir, tftp, priority, daddr)
# Send firmware update command
image_type = image.type
@@ -468,12 +476,12 @@ class Target:
return Image(filename, image_type)
- def _upload_ubootenv(self, tftp, ubootenv, partition, version=None):
+ def _upload_ubootenv(self, tftp, ubootenv, partition, priority=None):
""" Upload a uboot environment to the target """
filename = tempfile.mkstemp(prefix="%s/env_" % self.work_dir)[1]
open(filename, "w").write(ubootenv.get_contents())
image = Image(filename, "UBOOTENV")
- self._upload_image(tftp, image, partition, version)
+ self._upload_image(tftp, image, partition, priority)
def _download_ubootenv(self, tftp, partition):
""" Download a uboot environment from the target """
diff --git a/cxmanage_test/image_test.py b/cxmanage_test/image_test.py
index 60aef9e..ded11c1 100644
--- a/cxmanage_test/image_test.py
+++ b/cxmanage_test/image_test.py
@@ -57,7 +57,7 @@ class ImageTest(unittest.TestCase):
""" Test image creation and upload """
imglen = 1024
- version = 1
+ priority = 1
daddr = 12345
# Create image
@@ -67,7 +67,7 @@ class ImageTest(unittest.TestCase):
# Upload image and delete file
image_filename = image.upload(self.work_dir,
- self.tftp, version, daddr)
+ self.tftp, priority, daddr)
os.remove(filename)
# Download image
@@ -77,7 +77,7 @@ class ImageTest(unittest.TestCase):
# Examine image
simg = open(filename).read()
header = get_simg_header(simg)
- self.assertEqual(header.version, version)
+ self.assertEqual(header.priority, priority)
self.assertEqual(header.imglen, imglen)
self.assertEqual(header.daddr, daddr)
self.assertEqual(simg[header.imgoff:], contents)
diff --git a/cxmanage_test/target_test.py b/cxmanage_test/target_test.py
index 760e624..c7ca8c7 100644
--- a/cxmanage_test/target_test.py
+++ b/cxmanage_test/target_test.py
@@ -389,18 +389,18 @@ class DummyBMC(LanBMC):
class Partition:
def __init__(self, partition, type, offset=0,
- size=0, version=0, daddr=0, in_use=None):
+ size=0, priority=0, daddr=0, in_use=None):
self.updates = 0
self.retrieves = 0
self.checks = 0
self.activates = 0
self.fwinfo = FWInfoEntry(partition, type, offset,
- size, version, daddr, in_use)
+ size, priority, daddr, in_use)
class FWInfoEntry:
""" Firmware info for a single partition """
def __init__(self, partition, type, offset=0,
- size=0, version=0, daddr=0, in_use=None):
+ size=0, priority=0, daddr=0, in_use=None):
self.partition = "%2i" % partition
self.type = {
2: "02 (S2_ELF)",
@@ -410,7 +410,7 @@ class FWInfoEntry:
}[type]
self.offset = "%8x" % offset
self.size = "%8x" % size
- self.version = "%8x" % version
+ self.priority = "%8x" % priority
self.daddr = "%8x" % daddr
self.in_use = {None: "Unknown", True: "1", False: "0"}[in_use]
self.flags = "fffffffd"
diff --git a/scripts/cxmanage b/scripts/cxmanage
index 7bb4c0a..1be520b 100755
--- a/scripts/cxmanage
+++ b/scripts/cxmanage
@@ -156,8 +156,8 @@ def build_parser():
p['simg_args'].add_argument('--skip-simg',
help='Skip addition of SIMG header',
default=False, action='store_true')
- p['fwupdate'].add_argument('--version',
- help='Version for SIMG header', default=None, type=int)
+ p['fwupdate'].add_argument('--priority',
+ help='Priority for SIMG header', default=None, type=int)
p['fwupdate'].add_argument('-d', '--daddr',
help='Destination address for SIMG',
default=None, type=lambda x : int(x, 16))
@@ -234,8 +234,8 @@ def validate_args(args):
if args.threads < 1:
sys.exit('ERROR: --threads must be at least 1')
if args.func == fwupdate_command:
- if args.skip_simg and args.version:
- sys.exit('Invalid argument --version when supplied with --skip-simg')
+ if args.skip_simg and args.priority:
+ sys.exit('Invalid argument --priority when supplied with --skip-simg')
if args.skip_simg and args.daddr:
sys.exit('Invalid argument --daddr when supplied with --skip-simg')
if args.skip_simg and args.skip_crc32:
@@ -439,7 +439,7 @@ def fwupdate_command(controller, args):
# Add image
controller.add_image(args.filename, args.image_type,
- simg, args.version, args.daddr, args.skip_crc32)
+ simg, args.priority, args.daddr, args.skip_crc32)
# Print all_nodes warning/confirmation
if not args.all_nodes:
diff --git a/scripts/cxpackage b/scripts/cxpackage
index dfae7fa..1217fca 100755
--- a/scripts/cxpackage
+++ b/scripts/cxpackage
@@ -76,7 +76,7 @@ def build_parser():
default=False, action='store_true')
simg_args.add_argument('--skip-simg', help='Skip addition of SIMG header',
default=False, action='store_true')
- add.add_argument('-v', '--version', help='Version for SIMG header',
+ add.add_argument('-v', '--priority', help='Priority for SIMG header',
default=None, type=int)
add.add_argument('-d', '--daddr', help='Destination address for SIMG',
default=None, type=lambda x : int(x, 16))
@@ -92,8 +92,8 @@ def build_parser():
def validate_args(args):
""" Bail out if the arguments don't make sense"""
if args.func == add_command:
- if args.skip_simg and args.version:
- sys.exit('Invalid argument --version when supplied with --skip-simg')
+ if args.skip_simg and args.priority:
+ sys.exit('Invalid argument --priority when supplied with --skip-simg')
if args.skip_simg and args.daddr:
sys.exit('Invalid argument --daddr when supplied with --skip-simg')
if args.skip_simg and args.skip_crc32:
@@ -128,7 +128,7 @@ def add_command(controller, args):
simg = True
controller.add_image(args.filename, args.image_type,
- simg, args.version, args.daddr, args.skip_crc32)
+ simg, args.priority, args.daddr, args.skip_crc32)
controller.save_package(args.package)