def retrieve_firmware(self, filename, partition, image_type, tftp_addr): """ Mock retrieve_firmware method """ self.partitions[partition].retrieves += 1 # Upload blank image to tftp work_dir = tempfile.mkdtemp(prefix="cxmanage_test-") open("%s/%s" % (work_dir, filename), "w").write(create_simg("")) address, port = tftp_addr.split(":") port = int(port) tftp = ExternalTftp(address, port) tftp.put_file("%s/%s" % (work_dir, filename), filename) shutil.rmtree(work_dir) return Result(tftp_handle_id = 0)
def retrieve_firmware(self, filename, partition, image_type, tftp_addr): """ Mock retrieve_firmware method """ self.partitions[partition].retrieves += 1 # Upload blank image to tftp work_dir = tempfile.mkdtemp(prefix="cxmanage_test-") open("%s/%s" % (work_dir, filename), "w").write(create_simg("")) address, port = tftp_addr.split(":") port = int(port) tftp = ExternalTftp(address, port) tftp.put_file("%s/%s" % (work_dir, filename), filename) shutil.rmtree(work_dir) return Result(tftp_handle_id=0)
def size(self): """Return the full size of this image (as an SIMG) >>> img.size() 2174976 :returns: The size of the image file in bytes. :rtype: integer """ if (self.simg): return os.path.getsize(self.filename) else: contents = open(self.filename).read() align = (self.type in ["CDB", "BOOT_LOG"]) simg = create_simg(contents, skip_crc32=True, align=align) return len(simg)
def render_to_simg(self, priority, daddr): """Creates a SIMG file. >>> img.render_to_simg(priority=1, daddr=0) >>> 'spi_highbank.bin' :param priority: SIMG header priority value. :type priority: integer :param daddr: SIMG daddr field value. :type daddr: integer :returns: The file name of the image. :rtype: string :raises InvalidImageError: If the SIMG image is not valid. """ filename = self.filename # Create new image if necessary if (not self.simg): contents = open(filename).read() # Figure out daddr if (self.daddr != None): daddr = self.daddr # Create simg align = (self.type in ["CDB", "BOOT_LOG"]) simg = create_simg(contents, priority=priority, daddr=daddr, skip_crc32=self.skip_crc32, align=align, version=self.version) filename = temp_file() with open(filename, "w") as file_: file_.write(simg) # Make sure the simg was built correctly if (not valid_simg(open(filename).read())): raise InvalidImageError("%s is not a valid SIMG" % os.path.basename(self.filename)) return filename