Attention is currently required from: Pratikkumar V Prajapati.
Shuo Liu has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/86577?usp=email )
Change subject: util/inteltool: Add gen_coreboot_ifd.py ......................................................................
util/inteltool: Add gen_coreboot_ifd.py
This tool takes an UEFI IFWI, extract the IFD and update its content to support 16MB+ BIOS region.
DoC ID referred to: 642713
Change-Id: Ieb01e295ea1fbb08a1c7d19a536a55e4dcd6f9c1 Signed-off-by: Shuo Liu shuo.liu@intel.com --- A util/inteltool/gen_coreboot_ifd.py 1 file changed, 71 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/77/86577/1
diff --git a/util/inteltool/gen_coreboot_ifd.py b/util/inteltool/gen_coreboot_ifd.py new file mode 100644 index 0000000..99ea0a6 --- /dev/null +++ b/util/inteltool/gen_coreboot_ifd.py @@ -0,0 +1,71 @@ +#! /usr/bin/env python3 +# +# SPDX-License-Identifier: BSD-3-Clause + +import sys +import getopt + +def ifd_replace(input_file, output_file, bios_size): + # + # Extract the first 4K of UEFI IFWI binary + # + with open(input_file,"rb") as input: + first_4k = input.read(4 * 1024) + with open(output_file,"wb") as output: + output.write(first_4k) + + # + # Replace the data + # + with open(output_file,"r+b") as file: + # 1. 0x15 -- Number of Components + # Chapter 4.1.1.2 of Doc#642713 + data = b'\x00' + hex_offset = '0x15' + offset=int(hex_offset,16) + file.seek(offset) + file.write(data) + + # 2. 0x44 -- Flash Region Base Address (BIOS) + # Chapter 4.1.3.2 of Doc#642713 + if bios_size == '16M': + data = b'\x00\x30\xFF\x3F' + elif bios_size == '32M': + data = b'\x00\x20\xFF\x3F' + elif bios_size == '48M': + data = b'\x00\x10\xFF\x3F' + hex_offset = '0x44' # FRBA + 004h + offset=int(hex_offset,16) + file.seek(offset) + file.write(data) + + # 3. 0x48-0x7F -- Flash Region Base Address (Reserved) + # Chapter 4.1.3.3 of Doc#642713 + num = 14 # Number of Flash Region + data = b'\xFF\x7F\x00\x00' # 7FFFh is not used data + hex_offset = '0x48' # FRBA + 008h + offset=int(hex_offset,16) + file.seek(offset) + # Go through flash region from 2 to 15 + for _ in range(num): + file.write(data) + + print(output_file + ' is generated.') + +if __name__ == '__main__': + print('Creating Flash Descriptor...') + argv = sys.argv[1:] + try: + opts, args = getopt.getopt(argv, "b:") + except: + print ('ERROR: Incorrect arguments! -b <UEFI IFWI>') + print ('For example: gen_coreboot_ifd.py -b BHSDCRB1.xxx_SP_1.bin') + sys.exit(2) + + for opt, arg in opts: + if opt in ['-b']: + binary = arg + + ifd_replace(binary, 'descriptor_16m.bin','16M') + ifd_replace(binary, 'descriptor_32m.bin','32M') + ifd_replace(binary, 'descriptor_48m.bin','48M')