Skip to content

Commit 31dfb54

Browse files
muhomorrthestinger
authored andcommitted
[UNRESOLVED CONFLICT] don't auto-enable USB port during normal boot on Tensor Pixel devices
USB port is now enabled only after checking USB port security policy, which is done later in USB HAL and in system_server. Requires corresponding patches to tcpci_max77759 kernel module. This change doesn't apply to recovery and charger boot modes.
1 parent d053937 commit 31dfb54

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

init/first_stage_init.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,18 @@ std::string GetModuleLoadList(BootMode boot_mode, const std::string& dir_path) {
208208
}
209209

210210
#define MODULE_BASE_DIR "/lib/modules"
211+
<<<<<<< HEAD
211212
bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel,
212213
int& modules_loaded) {
213214
struct utsname uts {};
215+
||||||| parent of d05f06828 (don't auto-enable USB port during normal boot on Tensor Pixel devices)
216+
bool LoadKernelModules(bool recovery, bool want_console, bool want_parallel, int& modules_loaded) {
217+
struct utsname uts;
218+
=======
219+
bool LoadKernelModules(bool recovery, bool want_console, bool want_parallel, bool disable_usb_port,
220+
int& modules_loaded) {
221+
struct utsname uts;
222+
>>>>>>> d05f06828 (don't auto-enable USB port during normal boot on Tensor Pixel devices)
214223
if (uname(&uts)) {
215224
LOG(FATAL) << "Failed to get kernel version.";
216225
}
@@ -266,7 +275,13 @@ bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel
266275
for (const auto& module_dir : module_dirs) {
267276
std::string dir_path = MODULE_BASE_DIR "/";
268277
dir_path.append(module_dir);
278+
<<<<<<< HEAD
269279
Modprobe m({dir_path}, GetModuleLoadList(boot_mode, dir_path));
280+
||||||| parent of d05f06828 (don't auto-enable USB port during normal boot on Tensor Pixel devices)
281+
Modprobe m({dir_path}, GetModuleLoadList(recovery, dir_path));
282+
=======
283+
Modprobe m({dir_path}, GetModuleLoadList(recovery, dir_path), true, disable_usb_port);
284+
>>>>>>> d05f06828 (don't auto-enable USB port during normal boot on Tensor Pixel devices)
270285
bool retval = m.LoadListedModules(!want_console);
271286
modules_loaded = m.GetModuleCount();
272287
if (modules_loaded > 0) {
@@ -275,7 +290,13 @@ bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel
275290
}
276291
}
277292

293+
<<<<<<< HEAD
278294
Modprobe m({MODULE_BASE_DIR}, GetModuleLoadList(boot_mode, MODULE_BASE_DIR));
295+
||||||| parent of d05f06828 (don't auto-enable USB port during normal boot on Tensor Pixel devices)
296+
Modprobe m({MODULE_BASE_DIR}, GetModuleLoadList(recovery, MODULE_BASE_DIR));
297+
=======
298+
Modprobe m({MODULE_BASE_DIR}, GetModuleLoadList(recovery, MODULE_BASE_DIR), true, disable_usb_port);
299+
>>>>>>> d05f06828 (don't auto-enable USB port during normal boot on Tensor Pixel devices)
279300
bool retval = (want_parallel) ? m.LoadModulesParallel(std::thread::hardware_concurrency())
280301
: m.LoadListedModules(!want_console);
281302
modules_loaded = m.GetModuleCount();
@@ -430,9 +451,25 @@ int FirstStageMain(int argc, char** argv) {
430451

431452
boot_clock::time_point module_start_time = boot_clock::now();
432453
int module_count = 0;
454+
<<<<<<< HEAD
433455
BootMode boot_mode = GetBootMode(cmdline, bootconfig);
434456
if (!LoadKernelModules(boot_mode, want_console,
435457
want_parallel, module_count)) {
458+
||||||| parent of d05f06828 (don't auto-enable USB port during normal boot on Tensor Pixel devices)
459+
if (!LoadKernelModules(IsRecoveryMode() && !ForceNormalBoot(cmdline, bootconfig), want_console,
460+
want_parallel, module_count)) {
461+
=======
462+
463+
const bool recovery = IsRecoveryMode() && !ForceNormalBoot(cmdline, bootconfig);
464+
bool disable_usb_port = false;
465+
if (!recovery) {
466+
bool is_charger = bootconfig.find("androidboot.mode = \"charger\"") != std::string::npos ||
467+
cmdline.find("androidboot.mode=charger") != std::string::npos;
468+
disable_usb_port = !is_charger;
469+
}
470+
471+
if (!LoadKernelModules(recovery, want_console, want_parallel, disable_usb_port, module_count)) {
472+
>>>>>>> d05f06828 (don't auto-enable USB port during normal boot on Tensor Pixel devices)
436473
if (want_console != FirstStageConsoleParam::DISABLED) {
437474
LOG(ERROR) << "Failed to load kernel modules, starting console";
438475
} else {

libmodprobe/include/modprobe/modprobe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
class Modprobe {
2929
public:
3030
Modprobe(const std::vector<std::string>&, const std::string load_file = "modules.load",
31-
bool use_blocklist = true);
31+
bool use_blocklist = true, bool disable_usb_port = false);
3232

3333
bool LoadModulesParallel(int num_threads);
3434
bool LoadListedModules(bool strict = true);

libmodprobe/libmodprobe.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ void Modprobe::ParseKernelCmdlineOptions(void) {
316316
}
317317

318318
Modprobe::Modprobe(const std::vector<std::string>& base_paths, const std::string load_file,
319-
bool use_blocklist)
319+
bool use_blocklist, bool disable_usb_port)
320320
: blocklist_enabled(use_blocklist) {
321321
using namespace std::placeholders;
322322

@@ -341,6 +341,10 @@ Modprobe::Modprobe(const std::vector<std::string>& base_paths, const std::string
341341
}
342342

343343
ParseKernelCmdlineOptions();
344+
345+
if (disable_usb_port) {
346+
AddOption("tcpci_max77759", "disable_cc_toggling_by_default", "1");
347+
}
344348
}
345349

346350
std::vector<std::string> Modprobe::GetDependencies(const std::string& module) {

0 commit comments

Comments
 (0)