]>
glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/helpers/lxc.py
6e6398c85b3ab18111730799f64a9ac7a8ef0616
1 # Copyright 2021 Erfan Abdi
2 # SPDX-License-Identifier: GPL-3.0-or-later
11 import tools
.helpers
.run
14 def get_lxc_version(args
):
15 if shutil
.which("lxc-info") is not None:
16 command
= ["lxc-info", "--version"]
17 version_str
= tools
.helpers
.run
.user(args
, command
, output_return
=True)
18 return int(version_str
[0])
23 def generate_nodes_lxc_config(args
):
24 def make_entry(src
, dist
=None, mnt_type
="none", options
="bind,create=file,optional 0 0", check
=True):
25 if check
and not os
.path
.exists(src
):
27 entry
= "lxc.mount.entry = "
32 entry
+= mnt_type
+ " "
39 make_entry("tmpfs", "dev", "tmpfs", "nosuid 0 0", False)
40 make_entry("/dev/zero")
41 make_entry("/dev/full")
42 make_entry("/dev/ashmem", check
=False)
43 make_entry("/dev/fuse")
44 make_entry("/dev/ion")
45 make_entry("/dev/char", options
="bind,create=dir,optional 0 0")
48 make_entry("/dev/kgsl-3d0")
49 make_entry("/dev/mali0")
50 make_entry("/dev/pvr_sync")
51 make_entry("/dev/pmsg0")
52 make_entry("/dev/fb0")
53 make_entry("/dev/graphics/fb0")
54 make_entry("/dev/fb1")
55 make_entry("/dev/graphics/fb1")
56 make_entry("/dev/fb2")
57 make_entry("/dev/graphics/fb2")
58 make_entry("/dev/dri", options
="bind,create=dir,optional 0 0")
61 make_entry("/dev/" + args
.BINDER_DRIVER
, "dev/binder", check
=False)
62 make_entry("/dev/" + args
.VNDBINDER_DRIVER
, "dev/vndbinder", check
=False)
63 make_entry("/dev/" + args
.HWBINDER_DRIVER
, "dev/hwbinder", check
=False)
65 if args
.vendor_type
!= "MAINLINE":
66 if not make_entry("/dev/hwbinder", "dev/host_hwbinder"):
67 raise OSError('Binder node "hwbinder" of host not found')
68 make_entry("/vendor", "vendor_extra", options
="bind,optional 0 0")
70 # Necessary device nodes for adb
71 make_entry("none", "dev/pts", "devpts", "defaults,mode=644,ptmxmode=666,create=dir 0 0", False)
72 make_entry("/dev/uhid")
74 # Low memory killer sys node
75 make_entry("/sys/module/lowmemorykiller", options
="bind,create=dir,optional 0 0")
78 make_entry("tmpfs", "mnt", "tmpfs", "mode=0755,uid=0,gid=1000", False)
79 make_entry(tools
.config
.defaults
["data"], "data", options
="bind 0 0", check
=False)
81 # Mount host permissions
82 make_entry(tools
.config
.defaults
["host_perms"],
83 "vendor/etc/host-permissions", options
="bind,optional 0 0")
85 # Recursive mount /run to provide necessary host sockets
86 make_entry("/run", options
="rbind,create=dir 0 0")
88 # Necessary sw_sync node for HWC
89 make_entry("/dev/sw_sync")
90 make_entry("/sys/kernel/debug", options
="rbind,create=dir,optional 0 0")
92 # Media dev nodes (for Mediatek)
93 make_entry("/dev/Vcodec")
94 make_entry("/dev/MTK_SMI")
95 make_entry("/dev/mdp_sync")
96 make_entry("/dev/mtk_cmdq")
98 # Media dev nodes (for Qcom)
99 make_entry("/dev/video32")
100 make_entry("/dev/video33")
105 def set_lxc_config(args
):
106 lxc_path
= tools
.config
.defaults
["lxc"] + "/waydroid"
107 config_file
= "config_2"
108 lxc_ver
= get_lxc_version(args
)
110 raise OSError("LXC is not installed")
112 config_file
= "config_1"
113 config_path
= tools
.config
.tools_src
+ "/data/configs/" + config_file
115 command
= ["mkdir", "-p", lxc_path
]
116 tools
.helpers
.run
.root(args
, command
)
117 command
= ["cp", "-fpr", config_path
, lxc_path
+ "/config"]
118 tools
.helpers
.run
.root(args
, command
)
119 command
= ["sed", "-i", "s/LXCARCH/{}/".format(platform
.machine()), lxc_path
+ "/config"]
120 tools
.helpers
.run
.root(args
, command
)
122 nodes
= generate_nodes_lxc_config(args
)
123 config_nodes_tmp_path
= args
.work
+ "/config_nodes"
124 config_nodes
= open(config_nodes_tmp_path
, "w")
126 config_nodes
.write(node
+ "\n")
128 command
= ["mv", config_nodes_tmp_path
, lxc_path
]
129 tools
.helpers
.run
.root(args
, command
)
132 def make_base_props(args
):
133 def find_hal(hardware
):
135 "ro.hardware." + hardware
,
140 for p
in hardware_props
:
141 prop
= tools
.helpers
.props
.host_get(args
, p
)
144 for lib
in ["lib", "lib64"]:
145 hal_file
= "/vendor/" + lib
+ "/hw/" + hardware
+ "." + prop
+ ".so"
146 command
= ["readlink", "-f", hal_file
]
147 hal_file_path
= tools
.helpers
.run
.root(args
, command
, output_return
=True).strip()
148 if os
.path
.isfile(hal_file_path
):
149 hal_prop
= re
.sub(".*" + hardware
+ ".", "", hal_file_path
)
150 hal_prop
= re
.sub(".so", "", hal_prop
)
158 gralloc
= find_hal("gralloc")
161 props
.append("ro.hardware.egl=mesa")
162 props
.append("debug.stagefright.ccodec=0")
163 props
.append("ro.hardware.gralloc=" + gralloc
)
165 egl
= tools
.helpers
.props
.host_get(args
, "ro.hardware.egl")
167 props
.append("ro.hardware.egl=" + egl
)
169 media_profiles
= tools
.helpers
.props
.host_get(args
, "media.settings.xml")
170 if media_profiles
!= "":
171 media_profiles
= media_profiles
.replace("vendor/", "vendor_extra/")
172 media_profiles
= media_profiles
.replace("odm/", "odm_extra/")
173 props
.append("media.settings.xml=" + media_profiles
)
175 ccodec
= tools
.helpers
.props
.host_get(args
, "debug.stagefright.ccodec")
177 props
.append("debug.stagefright.ccodec=" + ccodec
)
179 ext_library
= tools
.helpers
.props
.host_get(args
, "ro.vendor.extension_library")
180 if ext_library
!= "":
181 ext_library
= ext_library
.replace("vendor/", "vendor_extra/")
182 ext_library
= ext_library
.replace("odm/", "odm_extra/")
183 props
.append("ro.vendor.extension_library=" + ext_library
)
185 vulkan
= find_hal("vulkan")
187 props
.append("ro.hardware.vulkan=" + vulkan
)
189 opengles
= tools
.helpers
.props
.host_get(args
, "ro.opengles.version")
192 props
.append("ro.opengles.version=" + opengles
)
194 props
.append("waydroid.system_ota=" + args
.system_ota
)
195 props
.append("waydroid.vendor_ota=" + args
.vendor_ota
)
196 props
.append("waydroid.tools_version=" + tools
.config
.version
)
198 base_props
= open(args
.work
+ "/waydroid_base.prop", "w")
200 base_props
.write(prop
+ "\n")
204 def setup_host_perms(args
):
205 sku
= tools
.helpers
.props
.host_get(args
, "ro.boot.product.hardware.sku")
208 glob
.glob("/vendor/etc/permissions/android.hardware.nfc.*"))
209 if os
.path
.exists("/vendor/etc/permissions/android.hardware.consumerir.xml"):
210 copy_list
.append("/vendor/etc/permissions/android.hardware.consumerir.xml")
212 glob
.glob("/odm/etc/permissions/android.hardware.nfc.*"))
213 if os
.path
.exists("/odm/etc/permissions/android.hardware.consumerir.xml"):
214 copy_list
.append("/odm/etc/permissions/android.hardware.consumerir.xml")
217 glob
.glob("/odm/etc/permissions/sku_{}/android.hardware.nfc.*".format(sku
)))
218 if os
.path
.exists("/odm/etc/permissions/sku_{}/android.hardware.consumerir.xml".format(sku
)):
220 "/odm/etc/permissions/sku_{}/android.hardware.consumerir.xml".format(sku
))
222 if not os
.path
.exists(tools
.config
.defaults
["host_perms"]):
223 os
.mkdir(tools
.config
.defaults
["host_perms"])
225 for filename
in copy_list
:
226 shutil
.copy(filename
, tools
.config
.defaults
["host_perms"])
229 command
= ["sudo", "lxc-info", "-P", tools
.config
.defaults
["lxc"], "-n", "waydroid", "-sH"]
230 return subprocess
.run(command
, stdout
=subprocess
.PIPE
).stdout
.decode('utf-8').strip()
233 command
= ["lxc-start", "-P", tools
.config
.defaults
["lxc"],
234 "-F", "-n", "waydroid", "--", "/init"]
235 tools
.helpers
.run
.root(args
, command
, output
="background")
238 command
= ["lxc-stop", "-P",
239 tools
.config
.defaults
["lxc"], "-n", "waydroid", "-k"]
240 tools
.helpers
.run
.root(args
, command
)
243 command
= ["lxc-freeze", "-P", tools
.config
.defaults
["lxc"], "-n", "waydroid"]
244 tools
.helpers
.run
.root(args
, command
)
247 command
= ["lxc-unfreeze", "-P",
248 tools
.config
.defaults
["lxc"], "-n", "waydroid"]
249 tools
.helpers
.run
.root(args
, command
)
252 if status(args
) != "RUNNING":
253 logging
.error("WayDroid container is {}".format(status(args
)))
255 command
= ["lxc-attach", "-P", tools
.config
.defaults
["lxc"],
256 "-n", "waydroid", "--"]
258 command
.append(args
.COMMAND
)
260 command
.append("/system/bin/sh")
261 subprocess
.run(command
)
264 if status(args
) != "RUNNING":
265 logging
.error("WayDroid container is {}".format(status(args
)))
267 command
= ["lxc-attach", "-P", tools
.config
.defaults
["lxc"],
268 "-n", "waydroid", "--", "/system/bin/logcat"]
269 subprocess
.run(command
)