1# SPDX-License-Identifier: GPL-2.0+
2# Copyright (c) 2016 Google, Inc
3# Written by Simon Glass <sjg@chromium.org>
4#
5# Entry-type module for a pointer to an Intel Firmware Image Table
6#
7
8import struct
9
10from binman.etype.blob_ext import Entry_blob_ext
11
12class Entry_intel_fit_ptr(Entry_blob_ext):
13    """Intel Firmware Image Table (FIT) pointer
14
15    This entry contains a pointer to the FIT. It is required to be at address
16    0xffffffc0 in the image.
17    """
18    def __init__(self, section, etype, node):
19        super().__init__(section, etype, node)
20        if self.HasSibling('intel-fit') is False:
21            self.Raise("'intel-fit-ptr' section must have an 'intel-fit' sibling")
22
23    def _GetContents(self):
24        fit_pos = self.GetSiblingImagePos('intel-fit')
25        return struct.pack('<II', fit_pos or 0, 0)
26
27    def ObtainContents(self):
28        self.SetContents(self._GetContents())
29        return True
30
31    def ProcessContents(self):
32        """Write an updated version of the FIT pointer to this entry
33
34        This is necessary since image_pos is not available when ObtainContents()
35        is called, since by then the entries have not been packed in the image.
36        """
37        return self.ProcessContentsUpdate(self._GetContents())
38
39    def Pack(self, offset):
40        """Special pack method to set the offset to the right place"""
41        return super().Pack(0xffffffc0)
42