|
|
import subprocess from pathlib import Path
from patches import PATCH_DATA
TOP_ROM_TYPE = "MX25L3206E/MX25L3208E" BOTTOM_ROM_TYPE = "MX25L6406E/MX25L6408E" PROGRAMMER = "ch341a_spi"
UEFIPATCH_LOCATION = "./UEFIPatch_0.28.0_mac/UEFIPatch"
LOG_FILE_NAME = "x230patch.log"
class ROMError(Exception): pass
def log(text): with open(LOG_FILE_NAME, 'a') as f: f.write(text)
def check_rom(chip_loc): if chip_loc == "top": chip = TOP_ROM_TYPE elif chip_loc == "bottom": chip = BOTTOM_ROM_TYPE fr = subprocess.run(["flashrom", "-p", PROGRAMMER, "-c", chip], capture_output=True) log(fr.stdout.decode('ascii')) if fr.returncode != 0: raise ROMError("ROM not found.")
def read_rom(chip_loc, save_dir, file_name): if chip_loc == "top": chip = TOP_ROM_TYPE elif chip_loc == "bottom": chip = BOTTOM_ROM_TYPE fr = subprocess.run(["flashrom", "-p", PROGRAMMER, "-c", chip, "-r", file_name], cwd=save_dir, capture_output=True) log(fr.stdout.decode('ascii')) if fr.returncode != 0: raise ROMError def write_rom(chip_loc, open_dir, file_name): if chip_loc == "top": chip = TOP_ROM_TYPE elif chip_loc == "bottom": chip = BOTTOM_ROM_TYPE fr = subprocess.run(["flashrom", "-p", PROGRAMMER, "-c", chip, "-w", file_name], cwd=open_dir, capture_output=True) log(fr.stdout.decode('ascii')) if fr.returncode != 0: raise ROMError def patch_rom(patches, open_path, save_path): patches_path = save_path.parent / "patches.txt" with open(patches_path, 'w') as patches_file: for patch in patches: patches_file.write(PATCH_DATA[patch]) up = subprocess.run([UEFIPATCH_LOCATION, open_path, patches_path, "-o", save_path], capture_output=True) log(up.stdout.decode('ascii')) if up.returncode != 0: raise ROMError("Patching failed.")
|