diff options
| author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2021-03-17 16:45:19 +0100 |
|---|---|---|
| committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2021-03-17 16:45:19 +0100 |
| commit | c36a1f6ae0273486d9b7df910353a768498c0542 (patch) | |
| tree | cada40f52e72f63adad356ef9e0f1e17f333dbdf | |
| parent | 7df22520f3ce907a88e70eb691cc06f11acc88e9 (diff) | |
| download | vendor_replicant-scripts-modem-gpios-trace.tar.gz vendor_replicant-scripts-modem-gpios-trace.tar.bz2 vendor_replicant-scripts-modem-gpios-trace.zip | |
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
| -rwxr-xr-x | debug/modem-gpios-trace/modem-gpios-trace.py | 113 |
1 files changed, 72 insertions, 41 deletions
diff --git a/debug/modem-gpios-trace/modem-gpios-trace.py b/debug/modem-gpios-trace/modem-gpios-trace.py index 3c29cf8..2e23b3d 100755 --- a/debug/modem-gpios-trace/modem-gpios-trace.py +++ b/debug/modem-gpios-trace/modem-gpios-trace.py @@ -35,29 +35,68 @@ class ADB(object): def cmd(self, *args): return self.adb(('shell',) + args).removesuffix('\r\n') -class Device(object): - def __init__(self, transport): - self.transport = transport +class SSH(object): + def __init__(self, target): + self.ssh = sh.ssh.bake(target) + # TODO: try to obtimize better the latency between 2 file downloads + # by reusing an existing connection to the device + self.scp = sh.scp.bake('-o', 'IPQoS=lowdelay') + self.target = target - self.gpios = None - self.kernel = None - self.product = None + def get_root(self): + # TODO + pass - self.__identify() + # TODO: decide how to handle directories + def download(self, source, destination): + result = self.scp(self.target + ':' + source, destination) + # We need write permission to re-download the file in the same location + # By default it gets 444 + os.chmod (destination, 0o0660) + return result - def __identify(self): - results = {} - device = self.transport.cmd('getprop', 'ro.cm.device') + def cmd(self, *args): + return self.ssh(args) - if device == 'i9300': - self.product = 'Galaxy SIII (GT-I9300)' +class Device(object): + def __init__(self, transport): + self.transport = transport - # TODO: identify precisely the kernel + self.gpios = None self.kernel = {} - self.kernel['type'] = 'vendor' + self.product = None - return results + self.identify() + + def identify_device_tree(self): + model = None + + try: + model = self.transport.cmd('cat', '/sys/firmware/devicetree/base/model') + # print(model) + # print('Samsung Galaxy S3 (GT-I9300) based on Exynos4412') + # print(model == 'Samsung Galaxy S3 (GT-I9300) based on Exynos4412') + # if model == 'Samsung Galaxy S3 (GT-I9300) based on Exynos4412': + # self.product = 'Galaxy SIII (GT-I9300)' + self.product = 'Galaxy SIII (GT-I9300)' # TODO + self.kernel['type'] = 'replicant-11' + except: + if model == None: + self.kernel['type'] = 'vendor' + + def identify_android(self): + try: + device = self.transport.cmd('getprop', 'ro.cm.device') + if device == 'i9300': + self.product = 'Galaxy SIII (GT-I9300)' + except: + pass + + def identify(self): + self.identify_android() + self.identify_device_tree() + # TODO: Compare with XMMBoot wiki page def get_gpios(self): # Caching if self.gpios: @@ -65,7 +104,7 @@ class Device(object): # TODO: Add an abstraction that can make GPIOS correspond to each others # in different kernels - if self.device == 'Galaxy SIII (GT-I9300)': + if self.product == 'Galaxy SIII (GT-I9300)': # TODO: kernel_samsung_smdk4412 + 3.0.x if self.kernel['type'] == 'vendor': self.gpios = [ @@ -81,7 +120,6 @@ class Device(object): 'SLAVEWAKE', # Not in upstream kenrel? link-slavewake? 'SUS_REQ', ] - # TODO!!! elif self.kernel['type'] == 'replicant-11': self.gpios = [ 'cp-dump', @@ -94,38 +132,31 @@ class Device(object): 'reset-req', 'suspend-req', ] + else: + print("Unknown device") + return self.gpios class GPIODebug(object): - # TODO: Compare with XMMBoot wiki page - gpios = [ - 'AP_DUMP_INT', - 'CP_DUMP_INT', - 'CP_ON', - 'CP_RST', - 'HOSTWAKE', - 'LINK_ACTIVE', - 'PDA_ACTIVE', - 'PHONE_ACTIVE', - 'RESET_REQ_N', - 'SLAVEWAKE', - 'SUS_REQ', - ] - re = re.compile(' *(gpio-\d+) *\((.*)\) (.*) (.*)$') - def __init__(self, transport): - self.transport = transport + def __init__(self, device): + self.device = device + self.transport = device.transport self.transport.get_root() - self.file = "/sys/kernel/debug/gpio" + self.gpio_debug_file = "/sys/kernel/debug/gpio" + self.tmpdir = sh.mktemp('-d').removesuffix(os.linesep) # TODO self.old_gpios_state = None self.new_gpios_state = None + self.gpios = self.device.get_gpios() + print(self.gpios) + def get_timestamp(self): return self.transport.cmd('date', '+%s').removesuffix(os.linesep) @@ -175,13 +206,13 @@ class GPIODebug(object): def get(self): new_file = self.tmpdir + os.sep + "gpio" - self.transport.download(self.file, new_file) + self.transport.download(self.gpio_debug_file, new_file) gpio_file = open(new_file, 'rb') results = {} for line_bytes in gpio_file: - for gpio in GPIODebug.gpios: + for gpio in self.gpios: # We have to use bytes as sometimes with the 3.0 smdk kernel # with the GT-I9300, some GPIOs have corrupted names: # GPIOs 272-279, GPM3: @@ -200,10 +231,10 @@ class GPIODebug(object): self.old_gpios_state = self.new_gpios_state self.new_gpios_state = results -adb = ADB() -# device = Device(adb) - -debug = GPIODebug(adb) +# transport = ADB() +transport = SSH('midas-microsd-local') +device = Device(transport) +debug = GPIODebug(device) debug.get() while True: debug.get() |
