Skip to content

Commit 704ce36

Browse files
muhomorrthestinger
authored andcommitted
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 6c7c4b4 commit 704ce36

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

init/first_stage_init.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ std::string GetModuleLoadList(BootMode boot_mode, const std::string& dir_path) {
209209
}
210210

211211
#define MODULE_BASE_DIR "/lib/modules"
212-
bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel,
212+
bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel, bool disable_usb_port,
213213
int& modules_loaded) {
214-
struct utsname uts {};
214+
struct utsname uts{};
215215
if (uname(&uts)) {
216216
LOG(FATAL) << "Failed to get kernel version.";
217217
}
@@ -267,7 +267,7 @@ bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel
267267
for (const auto& module_dir : module_dirs) {
268268
std::string dir_path = MODULE_BASE_DIR "/";
269269
dir_path.append(module_dir);
270-
Modprobe m({dir_path}, GetModuleLoadList(boot_mode, dir_path));
270+
Modprobe m({dir_path}, GetModuleLoadList(boot_mode, dir_path), true, disable_usb_port);
271271
bool retval = m.LoadListedModules(!want_console);
272272
modules_loaded = m.GetModuleCount();
273273
if (modules_loaded > 0) {
@@ -276,7 +276,7 @@ bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel
276276
}
277277
}
278278

279-
Modprobe m({MODULE_BASE_DIR}, GetModuleLoadList(boot_mode, MODULE_BASE_DIR));
279+
Modprobe m({MODULE_BASE_DIR}, GetModuleLoadList(boot_mode, MODULE_BASE_DIR), true, disable_usb_port);
280280
bool retval = (want_parallel) ? m.LoadModulesParallel(std::thread::hardware_concurrency())
281281
: m.LoadListedModules(!want_console);
282282
modules_loaded = m.GetModuleCount();
@@ -432,8 +432,9 @@ int FirstStageMain(int argc, char** argv) {
432432
boot_clock::time_point module_start_time = boot_clock::now();
433433
int module_count = 0;
434434
BootMode boot_mode = GetBootMode(cmdline, bootconfig);
435+
bool disable_usb_port = boot_mode == BootMode::NORMAL_MODE;
435436
if (!LoadKernelModules(boot_mode, want_console,
436-
want_parallel, module_count)) {
437+
want_parallel, disable_usb_port, module_count)) {
437438
if (want_console != FirstStageConsoleParam::DISABLED) {
438439
LOG(ERROR) << "Failed to load kernel modules, starting console";
439440
} else {

libmodprobe/include/modprobe/modprobe.h

+1-1
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

+5-1
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)