# # Copyright (C) 2015 The Android Open-Source Project # # 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 common import struct # The target does not support OTA-flashing # the partition table, so blacklist it. DEFAULT_BOOTLOADER_OTA_BLACKLIST = ['partition'] class BadMagicError(Exception): __str__ = "bad magic value" # # Huawei Bootloader packed image format # # typedef struct meta_header { # u32 magic; /* 0xce1ad63c */ # u16 major_version; /* (0x1)-reject images with higher major versions */ # u16 minor_version; /* (0x0)-allow images with higer minor versions */ # char img_version[64]; /* Top level version for images in this meta */ # u16 meta_hdr_sz; /* size of this header */ # u16 img_hdr_sz; /* size of img_header_entry list */ # } meta_header_t; # typedef struct img_header_entry { # char ptn_name[MAX_GPT_NAME_SIZE]; # u32 start_offset; # u32 size; # } img_header_entry_t MAGIC = 0xce1ad63c class HuaweiBootImage(object): def __init__(self, data, name=None): self.name = name self.unpacked_images = None self._unpack(data) def _unpack(self, data): """Unpack the data blob as a Huawei boot image and return the list of contained image objects""" num_imgs_fmt = struct.Struct("