import plib
import cdalib
import config

def switch_device_to_brom_mode(device: plib.Device):
    if config.BROM_ENTER_METHOD == "crash":
        try:
            device.read32(0)
        except:
            pass
    elif config.BROM_ENTER_METHOD == "agent":
        try:
            device.bootcda()
        except:
            pass
        
        device = cdalib.Device(config.AG_DEV_PATH, True)
        try:
            device.enter_bootrom()
        except:
            pass
    else:
        raise RuntimeError("BROM_ENTER_METHOD invalid")