2018-05-07 06:58:06 +09:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2016-11-26 12:15:53 +09:00
|
|
|
# Copyright (c) 2016 Google, Inc
|
|
|
|
# Written by Simon Glass <sjg@chromium.org>
|
|
|
|
#
|
2019-08-24 22:23:08 +09:00
|
|
|
# Entry-type module for Intel flash descriptor
|
2016-11-26 12:15:53 +09:00
|
|
|
#
|
|
|
|
|
|
|
|
import struct
|
|
|
|
|
2020-04-18 09:09:03 +09:00
|
|
|
from binman.entry import Entry
|
2020-07-10 09:39:37 +09:00
|
|
|
from binman.etype.blob_ext import Entry_blob_ext
|
2016-11-26 12:15:53 +09:00
|
|
|
|
|
|
|
FD_SIGNATURE = struct.pack('<L', 0x0ff0a55a)
|
|
|
|
MAX_REGIONS = 5
|
|
|
|
|
2018-07-18 04:25:35 +09:00
|
|
|
# Region numbers supported by the Intel firmware format
|
2016-11-26 12:15:53 +09:00
|
|
|
(REGION_DESCRIPTOR, REGION_BIOS, REGION_ME, REGION_GBE,
|
|
|
|
REGION_PDATA) = range(5)
|
|
|
|
|
|
|
|
class Region:
|
|
|
|
def __init__(self, data, frba, region_num):
|
|
|
|
pos = frba + region_num * 4
|
|
|
|
val = struct.unpack('<L', data[pos:pos + 4])[0]
|
|
|
|
self.base = (val & 0xfff) << 12
|
|
|
|
self.limit = ((val & 0x0fff0000) >> 4) | 0xfff
|
|
|
|
self.size = self.limit - self.base + 1
|
|
|
|
|
2020-07-10 09:39:37 +09:00
|
|
|
class Entry_intel_descriptor(Entry_blob_ext):
|
2016-11-26 12:15:53 +09:00
|
|
|
"""Intel flash descriptor block (4KB)
|
|
|
|
|
2018-07-18 04:25:35 +09:00
|
|
|
Properties / Entry arguments:
|
|
|
|
filename: Filename of file containing the descriptor. This is typically
|
|
|
|
a 4KB binary file, sometimes called 'descriptor.bin'
|
|
|
|
|
|
|
|
This entry is placed at the start of flash and provides information about
|
2016-11-26 12:15:53 +09:00
|
|
|
the SPI flash regions. In particular it provides the base address and
|
2018-07-18 04:25:35 +09:00
|
|
|
size of the ME (Management Engine) region, allowing us to place the ME
|
|
|
|
binary in the right place.
|
|
|
|
|
|
|
|
With this entry in your image, the position of the 'intel-me' entry will be
|
|
|
|
fixed in the image, which avoids you needed to specify an offset for that
|
|
|
|
region. This is useful, because it is not possible to change the position
|
|
|
|
of the ME region without updating the descriptor.
|
|
|
|
|
|
|
|
See README.x86 for information about x86 binary blobs.
|
2016-11-26 12:15:53 +09:00
|
|
|
"""
|
2018-06-02 00:38:14 +09:00
|
|
|
def __init__(self, section, etype, node):
|
2020-07-10 09:39:35 +09:00
|
|
|
super().__init__(section, etype, node)
|
2016-11-26 12:15:53 +09:00
|
|
|
self._regions = []
|
2019-07-21 03:24:01 +09:00
|
|
|
|
|
|
|
def Pack(self, offset):
|
|
|
|
"""Put this entry at the start of the image"""
|
2019-07-09 04:18:37 +09:00
|
|
|
if self.offset is None:
|
2019-07-21 03:24:01 +09:00
|
|
|
offset = self.section.GetStartOffset()
|
2020-07-10 09:39:35 +09:00
|
|
|
return super().Pack(offset)
|
2016-11-26 12:15:53 +09:00
|
|
|
|
2018-08-02 06:22:37 +09:00
|
|
|
def GetOffsets(self):
|
2020-07-10 09:39:41 +09:00
|
|
|
info = {}
|
|
|
|
if self.missing:
|
|
|
|
# Return zero offsets so that these entries get placed somewhere
|
|
|
|
if self.HasSibling('intel-me'):
|
|
|
|
info['intel-me'] = [0, None]
|
|
|
|
return info
|
2018-08-02 06:22:37 +09:00
|
|
|
offset = self.data.find(FD_SIGNATURE)
|
|
|
|
if offset == -1:
|
2019-07-09 04:18:32 +09:00
|
|
|
self.Raise('Cannot find Intel Flash Descriptor (FD) signature')
|
2016-11-26 12:15:53 +09:00
|
|
|
flvalsig, flmap0, flmap1, flmap2 = struct.unpack('<LLLL',
|
2018-08-02 06:22:37 +09:00
|
|
|
self.data[offset:offset + 16])
|
2016-11-26 12:15:53 +09:00
|
|
|
frba = ((flmap0 >> 16) & 0xff) << 4
|
|
|
|
for i in range(MAX_REGIONS):
|
|
|
|
self._regions.append(Region(self.data, frba, i))
|
|
|
|
|
2019-07-09 04:18:54 +09:00
|
|
|
# Set the offset for ME (Management Engine) and IFWI (Integrated
|
|
|
|
# Firmware Image), for now, since the others are not used.
|
2019-07-09 04:18:38 +09:00
|
|
|
if self.HasSibling('intel-me'):
|
|
|
|
info['intel-me'] = [self._regions[REGION_ME].base,
|
|
|
|
self._regions[REGION_ME].size]
|
2019-07-09 04:18:54 +09:00
|
|
|
if self.HasSibling('intel-ifwi'):
|
|
|
|
info['intel-ifwi'] = [self._regions[REGION_BIOS].base, None]
|
2019-07-09 04:18:38 +09:00
|
|
|
return info
|