# SPDX-License-Identifier: GPL-2.0+ # Copyright (c) 2018 Google, Inc # Written by Simon Glass """Entry-type module for an image header which points to the FDT map This creates an 8-byte entry with a magic number and the offset of the FDT map (which is another entry in the image), relative to the start or end of the image. """ import struct from binman.entry import Entry from dtoc import fdt_util IMAGE_HEADER_MAGIC = b'BinM' IMAGE_HEADER_LEN = 8 def LocateHeaderOffset(data): """Search an image for an image header Args: data: Data to search Returns: Offset of image header in the image, or None if not found """ hdr_pos = data.find(IMAGE_HEADER_MAGIC) if hdr_pos != -1: size = len(data) hdr = data[hdr_pos:hdr_pos + IMAGE_HEADER_LEN] if len(hdr) == IMAGE_HEADER_LEN: offset = struct.unpack('