X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/waydroid.git/blobdiff_plain/4434f1120459fb65ffd5b48280c6ec10046b633d..20d3c5e2cf4fd91e35205a1abfae24456c05fc2e:/tools/helpers/drivers.py diff --git a/tools/helpers/drivers.py b/tools/helpers/drivers.py index 69ee56a..31005a5 100644 --- a/tools/helpers/drivers.py +++ b/tools/helpers/drivers.py @@ -3,6 +3,8 @@ import logging import os import glob +import fcntl +import struct import tools.config import tools.helpers.run @@ -33,6 +35,31 @@ def isBinderfsLoaded(args): return False +def allocBinderNodes(args, binder_dev_nodes): + NRBITS = 8 + TYPEBITS = 8 + SIZEBITS = 14 + NRSHIFT = 0 + TYPESHIFT = NRSHIFT + NRBITS + SIZESHIFT = TYPESHIFT + TYPEBITS + DIRSHIFT = SIZESHIFT + SIZEBITS + WRITE = 0x1 + READ = 0x2 + + def IOC(direction, _type, nr, size): + return (direction << DIRSHIFT) | (_type << TYPESHIFT) | (nr << NRSHIFT) | (size << SIZESHIFT) + + def IOWR(_type, nr, size): + return IOC(READ|WRITE, _type, nr, size) + + BINDER_CTL_ADD = IOWR(98, 1, 264) + binderctrlfd = open('/dev/binderfs/binder-control','rb') + + for node in binder_dev_nodes: + node_struct = struct.pack( + '256sII', bytes(node, 'utf-8'), 0, 0) + fcntl.ioctl(binderctrlfd.fileno(), BINDER_CTL_ADD, node_struct) + def probeBinderDriver(args): binder_dev_nodes = [] has_binder = False @@ -56,31 +83,29 @@ def probeBinderDriver(args): if len(binder_dev_nodes) > 0: if not isBinderfsLoaded(args): - devices = ','.join(binder_dev_nodes) - command = ["modprobe", "binder_linux", "devices=\"{}\"".format(devices)] - output = tools.helpers.run.root(args, command, check=False, output_return=True) + command = ["modprobe", "binder_linux"] + output = tools.helpers.run.user(args, command, check=False, output_return=True) if output: - logging.error("Failed to load binder driver for devices: {}".format(devices)) + logging.error("Failed to load binder driver") logging.error(output.strip()) if isBinderfsLoaded(args): command = ["mkdir", "-p", "/dev/binderfs"] - tools.helpers.run.root(args, command, check=False) + tools.helpers.run.user(args, command, check=False) command = ["mount", "-t", "binder", "binder", "/dev/binderfs"] - tools.helpers.run.root(args, command, check=False) + tools.helpers.run.user(args, command, check=False) + allocBinderNodes(args, binder_dev_nodes) command = ["ln", "-s"] command.extend(glob.glob("/dev/binderfs/*")) command.append("/dev/") - tools.helpers.run.root(args, command, check=False) - else: - return -1 + tools.helpers.run.user(args, command, check=False) return 0 def probeAshmemDriver(args): if not os.path.exists("/dev/ashmem"): command = ["modprobe", "ashmem_linux"] - output = tools.helpers.run.root(args, command, check=False, output_return=True) + output = tools.helpers.run.user(args, command, check=False, output_return=True) if output: logging.error("Failed to load ashmem driver") logging.error(output.strip())