def stitch_and_update(ifwi_file, ip_name, file_list, out_file): # search for firmware volume status, fw_volume = search_for_fv(ifwi_file, ip_name) # Check for error in using FMMT.exe or if firmware volume was not found. if status == 1 or fw_volume is None: to_remove = [ "tmp.fmmt.txt", "tmp.payload.bin", "tmp.obb.hash.bin", os.path.join(TOOLS_DIR, "privkey.pem") ] utils.cleanup(to_remove) if status == 0: logger.critical("\nError: No Firmware volume found") status = 1 sys.exit(status) # firmware volume was found logger.info("\nThe Firmware volume is {}\n".format(fw_volume)) # adding the path name to the output file file_list.append(os.path.abspath(out_file)) # Add firmware volume header and merge it in out_file status = merge_and_replace(file_list, ip_name, fw_volume) if status != 0: sys.exit(status)
def main(): """Entry to script.""" # files created that needs to be remove to_remove = [ "tmp.fmmt.txt", "tmp.raw", "tmp.ui", "tmp.all", "tmp.cmps", "tmp.guid", "tmp.pe32", "tmp.ffs" ] try: parser = parse_cmdline() args = parser.parse_args() outfile = Path(args.OUTPUT_FILE).resolve() outfile = utils.file_not_exist(outfile, logger) for f in (FMMT, GENFV, GENFFS, GENSEC, LZCOMPRESS, RSA_HELPER, FMMT_CFG): if not os.path.exists(f): raise FileNotFoundError( "Thirdparty tool not found ({})".format(f)) # Use absolute path because GenSec does not like relative ones IFWI_file = Path(args.IFWI_IN.name).resolve() # If input IP file is a JSON file, convert it to binary as the real input file if args.IPNAME_IN.name.lower().endswith('.json'): logger.info( "Found JSON as input file. Converting it to binary ...\n") desc = SubRegionDescriptor() desc.parse_json_data(args.IPNAME_IN.name) # Currently only creates the first file generate_sub_region_image(desc.ffs_files[0], output_file="tmp.payload.bin") IPNAME_file = Path("tmp.payload.bin").resolve() # add to remove files to_remove.append("tmp.payload.bin") else: IPNAME_file = Path(args.IPNAME_IN.name).resolve() filenames = [str(IFWI_file), str(IPNAME_file)] if args.ipname in ["gop", "gfxpeim", "vbt"]: if not args.private_key or not os.path.exists(args.private_key): logger.critical( "\nMissing RSA key to stitch GOP/PEIM GFX/VBT from command line\n" ) parser.print_help() sys.exit(2) else: key_file = Path(args.private_key).resolve() status = utils.check_key(key_file, "rsa", logger) if status != 0: sys.exit(status) filenames.append(key_file) # Verify file is not empty or the IP files are smaller than the input file status = utils.check_file_size(logger, filenames) if status != 0: sys.exit(status) # Copy key file to the required name needed for the rsa_helper.py if args.private_key: shutil.copyfile(key_file, os.path.join(TOOLS_DIR, "privkey.pem")) to_remove.append(os.path.join(TOOLS_DIR, 'privkey.pem')) filenames.remove(key_file) logger.info("*** Replacing {} ...".format(args.ipname)) stitch_and_update(args.IFWI_IN.name, args.ipname, filenames, outfile) # Update OBB digest after stitching any data inside OBB region if args.ipname in ["gop", "vbt", "gfxpeim"]: if args.ipname == "gop": ipname = "obbdxe_digest" fv_list = [GUID_FVOSBOOT, GUID_FVUEFIBOOT, GUID_FVADVANCED] else: ipname = "obbpei_digest" fv_list = [GUID_FVPOSTMEMORY, GUID_FVFSPS] digest_file = "tmp.obb.hash.bin" to_remove.append(digest_file) calculate_new_obb_digest(outfile, fv_list, digest_file) filenames = [ str(Path(f).resolve()) for f in [outfile, digest_file] ] logger.info("*** Replacing {} ...".format(ipname)) stitch_and_update(outfile, ipname, filenames, outfile) finally: utils.cleanup(to_remove)
gen_cap_cmd += [ "--signer-private-cert", args.OpenSslSignerPrivateCertFile ] gen_cap_cmd += ["--other-public-cert", args.OpenSslOtherPublicCertFile] gen_cap_cmd += [ "--trusted-public-cert", args.OpenSslTrustedPublicCertFile ] elif any([ args.OpenSslSignerPrivateCertFile, args.OpenSslOtherPublicCertFile, args.OpenSslTrustedPublicCertFile ]): print('All-or-none of the certificate files must be provided.') exit(2) gen_cap_cmd += ["-v"] if args.SigningToolPath is not None: gen_cap_cmd += ["--signing-tool-path", args.SigningToolPath] gen_cap_cmd += [sub_region_fv_file] status = utils.execute_cmds(logger, [gen_cap_cmd]) # Creating list of files to remove to_remove = glob.glob("tmp.*") to_remove.extend(glob.glob("SubRegionFv.*")) to_remove.append("SubRegionImage.bin") utils.cleanup(to_remove) sys.exit(status)