# Copyright (c) 2020 Arm Limited # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import argparse import logging import struct import sys from imgtool.image import (IMAGE_HEADER_SIZE, IMAGE_MAGIC, TLV_INFO_MAGIC, TLV_PROT_INFO_MAGIC, TLV_VALUES) from shutil import copyfile def get_tlv_type_string(tlv_type): tlvs = {v: f"IMAGE_TLV_{k}" for k, v in TLV_VALUES.items()} return tlvs.get(tlv_type, "UNKNOWN({:d})".format(tlv_type)) class ImageHeader: def __init__(self): self.ih_magic = 0 self.ih_load_addr = 0 self.ih_hdr_size = 0 self.ih_protect_tlv_size = 0 self.ih_img_size = 0 self.ih_flags = 0 self.iv_major = 0 self.iv_minor = 0 self.iv_revision = 0 self.iv_build_num = 0 self._pad1 = 0 @staticmethod def read_from_binary(in_file): h = ImageHeader() (h.ih_magic, h.ih_load_addr, h.ih_hdr_size, h.ih_protect_tlv_size, h.ih_img_size, h.ih_flags, h.iv_major, h.iv_minor, h.iv_revision, h.iv_build_num, h._pad1 ) = struct.unpack('