diff options
author | George Kraft <george.kraft@calxeda.com> | 2012-08-28 11:15:37 -0500 |
---|---|---|
committer | George Kraft <george.kraft@calxeda.com> | 2012-08-28 11:15:37 -0500 |
commit | 019c810ae26af0bbbcc32690845e8e56b11f68ca (patch) | |
tree | 50f3aba6b8f2790be6f728532590fc7e76a56b6e | |
parent | 524194f9a93ba578f9ba6e48282f72e57632c1d8 (diff) | |
download | cxmanage-019c810ae26af0bbbcc32690845e8e56b11f68ca.tar.gz |
simg: Add new SIMG version field
and bump hdrfmt to 2
-rw-r--r-- | cxmanage/controller.py | 15 | ||||
-rw-r--r-- | cxmanage/image.py | 6 | ||||
-rw-r--r-- | cxmanage/simg.py | 42 |
3 files changed, 45 insertions, 18 deletions
diff --git a/cxmanage/controller.py b/cxmanage/controller.py index 13d0b5e..37590b3 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, - priority=None, daddr=None, skip_crc32=False): + priority=None, daddr=None, skip_crc32=False, version=None): """ Add an image to our collection """ if image_type == "PACKAGE": # Extract files and read config @@ -109,6 +109,7 @@ class Controller: image_priority = priority image_daddr = daddr image_skip_crc32 = skip_crc32 + image_version = version # Read image options from config if simg == None and config.has_option(section, "simg"): @@ -120,14 +121,17 @@ class Controller: if (skip_crc32 == False and config.has_option(section, "skip_crc32")): image_skip_crc32 = config.getboolean(section, "skip_crc32") + if version == None and config.has_option(section, "versionstr"): + image_version = config.get(section, "versionstr") image = self.image_class(filename, image_type, image_simg, - image_priority, image_daddr, image_skip_crc32) + image_priority, image_daddr, image_skip_crc32, + image_version) self.images.append(image) else: image = self.image_class(filename, image_type, - simg, priority, daddr, skip_crc32) + simg, priority, daddr, skip_crc32, version) self.images.append(image) def save_package(self, filename): @@ -145,6 +149,8 @@ class Controller: config.set(section, "daddr", "%x" % image.daddr) if image.skip_crc32: config.set(section, "skip_crc32", str(image.skip_crc32)) + if image.version != None: + config.set(section, "versionstr", image.version) manifest = open("%s/MANIFEST" % self.work_dir, "w") config.write(manifest) manifest.close() @@ -173,6 +179,8 @@ class Controller: print "Daddr: %x" % image.daddr if image.skip_crc32: print "Skip CRC32: %s" % image.skip_crc32 + if image.version != None: + print "Version: %s" % image.version print @@ -326,6 +334,7 @@ class Controller: print "Priority : %s" % partition.priority print "Daddr : %s" % partition.daddr print "Flags : %s" % partition.flags + print "Version : %s" % partition.version print "In Use : %s" % partition.in_use print diff --git a/cxmanage/image.py b/cxmanage/image.py index 8213ea4..11ffdd4 100644 --- a/cxmanage/image.py +++ b/cxmanage/image.py @@ -42,12 +42,13 @@ class Image: to build an SIMG out of it. """ def __init__(self, filename, image_type, simg=None, - priority=None, daddr=None, skip_crc32=False): + priority=None, daddr=None, skip_crc32=False, version=None): self.filename = filename self.type = image_type self.priority = priority self.daddr = daddr self.skip_crc32 = skip_crc32 + self.version = version if not os.path.exists(filename): raise ValueError("File %s does not exist" % filename) @@ -79,7 +80,8 @@ class Image: # Create simg align = (self.type in ["CDB", "BOOT_LOG"]) simg = create_simg(contents, priority=priority, daddr=daddr, - skip_crc32=self.skip_crc32, align=align) + skip_crc32=self.skip_crc32, align=align, + version=self.version) filename = tempfile.mkstemp(".simg", work_dir + "/")[1] open(filename, "w").write(simg) diff --git a/cxmanage/simg.py b/cxmanage/simg.py index 70ca37d..d787919 100644 --- a/cxmanage/simg.py +++ b/cxmanage/simg.py @@ -35,21 +35,26 @@ import struct from cxmanage.crc32 import get_crc32 +HEADER_LENGTH = 60 +MIN_HEADER_LENGTH = 28 + class SIMGHeader: """ Container for an SIMG header """ def __init__(self, header_string=None): if header_string == None: self.magic_string = 'SIMG' - self.hdrfmt = 0 + self.hdrfmt = 2 self.priority = 0 - self.imgoff = 28 + self.imgoff = HEADER_LENGTH self.imglen = 0 self.daddr = 0 self.flags = 0 self.crc32 = 0 + self.version = '' else: - tup = struct.unpack('<4sHHIIIII', header_string) + header_string = header_string.ljust(HEADER_LENGTH, chr(0)) + tup = struct.unpack('<4sHHIIIII32s', header_string) self.magic_string = tup[0] self.hdrfmt = tup[1] self.priority = tup[2] @@ -58,9 +63,13 @@ class SIMGHeader: self.daddr = tup[5] self.flags = tup[6] self.crc32 = tup[7] + if self.hdrfmt >= 2: + self.version = tup[8] + else: + self.version = '' def __str__(self): - return struct.pack('<4sHHIIIII', + return struct.pack('<4sHHIIIII32s', self.magic_string, self.hdrfmt, self.priority, @@ -68,15 +77,21 @@ class SIMGHeader: self.imglen, self.daddr, self.flags, - self.crc32) + self.crc32, + self.version) -def create_simg(contents, priority=0, daddr=0, skip_crc32=False, align=False): +def create_simg(contents, priority=0, daddr=0, skip_crc32=False, align=False, + version=None): """Create an SIMG version of a file""" + if version == None: + version = '' + header = SIMGHeader() header.priority = priority header.imglen = len(contents) header.daddr = daddr + header.version = version if align: header.imgoff = 4096 @@ -85,7 +100,7 @@ def create_simg(contents, priority=0, daddr=0, skip_crc32=False, align=False): if skip_crc32: crc32 = 0 else: - crc32 = get_crc32(contents, get_crc32(str(header))) + crc32 = get_crc32(contents, get_crc32(str(header)[:MIN_HEADER_LENGTH])) # Get SIMG header header.flags = 0xFFFFFFFF @@ -97,9 +112,9 @@ def create_simg(contents, priority=0, daddr=0, skip_crc32=False, align=False): def has_simg(simg): """Return true if this string has an SIMG header""" - if len(simg) < 28: + if len(simg) < MIN_HEADER_LENGTH: return False - header = SIMGHeader(simg[:28]) + header = SIMGHeader(simg[:HEADER_LENGTH]) # Check for magic word return header.magic_string == 'SIMG' @@ -110,10 +125,10 @@ def valid_simg(simg): if not has_simg(simg): return False - header = SIMGHeader(simg[:28]) + header = SIMGHeader(simg[:HEADER_LENGTH]) # Check offset - if header.imgoff < 28: + if header.imgoff < MIN_HEADER_LENGTH: return False # Check length @@ -128,7 +143,8 @@ def valid_simg(simg): if crc32 != 0: header.flags = 0 header.crc32 = 0 - if crc32 != get_crc32(contents, get_crc32(str(header))): + if crc32 != get_crc32(contents, + get_crc32(str(header)[:MIN_HEADER_LENGTH])): return False return True @@ -139,7 +155,7 @@ def get_simg_header(simg): if not valid_simg(simg): raise ValueError("Failed to read invalid SIMG") - return SIMGHeader(simg[:28]) + return SIMGHeader(simg[:HEADER_LENGTH]) def get_simg_contents(simg): |