From: Simon Glass Date: Mon, 8 Jul 2019 20:25:45 +0000 (-0600) Subject: binman: Support locating an image header X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=2d26003df79839d7f6b5e30eaa49e191dc9e6c87;p=u-boot.git binman: Support locating an image header Add support for locating an image header in an image. Signed-off-by: Simon Glass --- diff --git a/tools/binman/etype/image_header.py b/tools/binman/etype/image_header.py index b1c4f8a07e..8f9c5aa5d9 100644 --- a/tools/binman/etype/image_header.py +++ b/tools/binman/etype/image_header.py @@ -15,6 +15,29 @@ from entry import Entry 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('