|
1 | 1 | using FirmwareKit.Comm.Fastboot; |
2 | | -using FirmwareKit.Comm.Fastboot.Backend.Usb; |
| 2 | +using FirmwareKit.Comm.Fastboot.Usb; |
3 | 3 |
|
4 | 4 |
|
5 | 5 | namespace FastbootCLI |
@@ -44,7 +44,7 @@ static void Main(string[] args) |
44 | 44 | sparseLimit = ParseSize(sizeStr); |
45 | 45 | } |
46 | 46 | else if (arg == "--debug") FastbootDebug.IsEnabled = true; |
47 | | - else if (arg == "--libusb") UsbManager.ForceLibUsb = true; |
| 47 | + else if (arg == "--fallback") UsbManager.ForceLibUsb = false; |
48 | 48 | else if (arg == "--version" || arg == "version") { Console.WriteLine("fastboot version 1.2.5"); return; } |
49 | 49 | else if (arg == "-h" || arg == "--help" || arg == "help") { ShowHelp(); return; } |
50 | 50 | else if (!arg.StartsWith("-")) |
@@ -75,16 +75,36 @@ static void Main(string[] args) |
75 | 75 | } |
76 | 76 |
|
77 | 77 | var devices = UsbManager.GetAllDevices(); |
78 | | - UsbDevice? target = serial != null ? devices.FirstOrDefault(d => d.SerialNumber == serial) : (devices.Count > 0 ? devices[0] : null); |
| 78 | + UsbDevice? target = null; |
| 79 | + |
| 80 | + if (serial != null) |
| 81 | + { |
| 82 | + target = devices.FirstOrDefault(d => d.SerialNumber == serial); |
| 83 | + } |
| 84 | + else if (devices.Count > 0) |
| 85 | + { |
| 86 | + target = devices[0]; |
| 87 | + } |
| 88 | + else |
| 89 | + { |
| 90 | + // Wait for device matching AOSP behavior |
| 91 | + Console.Error.WriteLine("< waiting for any device >"); |
| 92 | + while (target == null) |
| 93 | + { |
| 94 | + System.Threading.Thread.Sleep(500); |
| 95 | + devices = UsbManager.GetAllDevices(); |
| 96 | + target = devices.FirstOrDefault(); |
| 97 | + } |
| 98 | + } |
79 | 99 |
|
80 | 100 | if (target == null) |
81 | 101 | { |
82 | 102 | Console.Error.WriteLine("fastboot: error: no devices/found"); |
83 | 103 | Environment.Exit(1); |
84 | 104 | } |
85 | 105 |
|
86 | | - using FastbootUtil util = new FastbootUtil(target); |
87 | | - if (sparseLimit.HasValue) FastbootUtil.SparseMaxDownloadSize = (int)Math.Min(int.MaxValue, sparseLimit.Value); |
| 106 | + using FastbootDriver util = new FastbootDriver(target); |
| 107 | + if (sparseLimit.HasValue) FastbootDriver.SparseMaxDownloadSize = (int)Math.Min(int.MaxValue, sparseLimit.Value); |
88 | 108 |
|
89 | 109 | util.ReceivedFromDevice += (s, e) => |
90 | 110 | { |
@@ -127,7 +147,7 @@ static long ParseSize(string sizeStr) |
127 | 147 | return long.Parse(sizeStr) * multiplier; |
128 | 148 | } |
129 | 149 |
|
130 | | - static void ExecuteCommand(FastbootUtil util, string command, List<string> args) |
| 150 | + static void ExecuteCommand(FastbootDriver util, string command, List<string> args) |
131 | 151 | { |
132 | 152 | if (command == "devices") |
133 | 153 | { |
@@ -257,7 +277,6 @@ string GetPartition(string baseName) |
257 | 277 | using var fs = File.OpenRead(file); |
258 | 278 | util.FlashUnsparseImage(part, fs, fs.Length).ThrowIfError(); |
259 | 279 | } |
260 | | - if (!skipReboot && (part.StartsWith("boot") || part.StartsWith("system"))) Console.Error.WriteLine("Note: Device may need a manual reboot or use 'fastboot reboot'."); |
261 | 280 | break; |
262 | 281 |
|
263 | 282 | case "flashall": |
@@ -398,6 +417,7 @@ static void ShowHelp() |
398 | 417 | Console.Error.WriteLine(" --skip-reboot Don't reboot device after flashing all."); |
399 | 418 | Console.Error.WriteLine(" --force Force execute command (e.g. skip snapshot check)."); |
400 | 419 | Console.Error.WriteLine(" --fs-options <opt> File system options for format (e.g. casefold)."); |
| 420 | + Console.Error.WriteLine(" --fallback Use platform native USB backend instead of libusb (on Linux libusb is default)."); |
401 | 421 |
|
402 | 422 | Console.Error.WriteLine("\nbasics:"); |
403 | 423 | Console.Error.WriteLine(" devices [-l] List connected devices."); |
|
0 commit comments