android-tools: fix typos in fastboot patch

Signed-off-by: Ookiineko <chiisaineko@protonmail.com>
This commit is contained in:
Ookiineko 2022-04-27 17:48:32 +08:00 committed by Henrik Grimler
parent 5e8c078e3d
commit 67ceadbb4e
No known key found for this signature in database
GPG Key ID: B0076E490B71616B
5 changed files with 48 additions and 48 deletions

View File

@ -3,7 +3,7 @@ TERMUX_PKG_DESCRIPTION="Android platform tools"
TERMUX_PKG_LICENSE="Apache-2.0, MIT" TERMUX_PKG_LICENSE="Apache-2.0, MIT"
TERMUX_PKG_MAINTAINER="@termux" TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=31.0.3p1 TERMUX_PKG_VERSION=31.0.3p1
TERMUX_PKG_REVISION=1 TERMUX_PKG_REVISION=2
TERMUX_PKG_SRCURL=https://github.com/nmeum/android-tools/releases/download/$TERMUX_PKG_VERSION/android-tools-$TERMUX_PKG_VERSION.tar.xz TERMUX_PKG_SRCURL=https://github.com/nmeum/android-tools/releases/download/$TERMUX_PKG_VERSION/android-tools-$TERMUX_PKG_VERSION.tar.xz
TERMUX_PKG_SHA256=0ef69f919d58a2bdff2083d2e83a9ef38df079ec82651b2544e9e48086df5ab8 TERMUX_PKG_SHA256=0ef69f919d58a2bdff2083d2e83a9ef38df079ec82651b2544e9e48086df5ab8
TERMUX_PKG_AUTO_UPDATE=true TERMUX_PKG_AUTO_UPDATE=true

View File

@ -6,7 +6,7 @@ index 0062e7e..9d2ee12 100644
#include <liblp/liblp.h> #include <liblp/liblp.h>
#include <sparse/sparse.h> #include <sparse/sparse.h>
#include <ziparchive/zip_archive.h> #include <ziparchive/zip_archive.h>
+#ifdef ANDROID +#ifdef __ANDROID__
+#include <libusb-1.0/libusb.h> +#include <libusb-1.0/libusb.h>
+#endif +#endif
@ -16,7 +16,7 @@ index 0062e7e..9d2ee12 100644
// //
// The returned Transport is a singleton, so multiple calls to this function will return the same // The returned Transport is a singleton, so multiple calls to this function will return the same
// object, and the caller should not attempt to delete the returned Transport. // object, and the caller should not attempt to delete the returned Transport.
+#ifdef ANDROID +#ifdef __ANDROID__
+static Transport* open_device(libusb_context *context) { +static Transport* open_device(libusb_context *context) {
+#else +#else
static Transport* open_device() { static Transport* open_device() {
@ -28,7 +28,7 @@ index 0062e7e..9d2ee12 100644
fprintf(stderr, "error: %s\n", error.c_str()); fprintf(stderr, "error: %s\n", error.c_str());
} }
} else { } else {
+#ifdef ANDROID +#ifdef __ANDROID__
+ transport = usb_open(match_fastboot, context); + transport = usb_open(match_fastboot, context);
+#else +#else
transport = usb_open(match_fastboot); transport = usb_open(match_fastboot);
@ -40,7 +40,7 @@ index 0062e7e..9d2ee12 100644
} }
} }
+#ifdef ANDROID +#ifdef __ANDROID__
+static void list_devices(libusb_context *context) { +static void list_devices(libusb_context *context) {
+#else +#else
static void list_devices() { static void list_devices() {
@ -48,7 +48,7 @@ index 0062e7e..9d2ee12 100644
// We don't actually open a USB device here, // We don't actually open a USB device here,
// just getting our callback called so we can // just getting our callback called so we can
// list all the connected devices. // list all the connected devices.
+#ifdef ANDROID +#ifdef __ANDROID__
+ usb_open(list_devices_callback, context); + usb_open(list_devices_callback, context);
+#else +#else
+ +
@ -61,7 +61,7 @@ index 0062e7e..9d2ee12 100644
return fb->GetVar("is-userspace", &value) == fastboot::SUCCESS && value == "yes"; return fb->GetVar("is-userspace", &value) == fastboot::SUCCESS && value == "yes";
} }
+#ifdef ANDROID +#ifdef __ANDROID__
+static void reboot_to_userspace_fastboot(libusb_context *context) { +static void reboot_to_userspace_fastboot(libusb_context *context) {
+#else +#else
static void reboot_to_userspace_fastboot() { static void reboot_to_userspace_fastboot() {
@ -73,7 +73,7 @@ index 0062e7e..9d2ee12 100644
// Give the current connection time to close. // Give the current connection time to close.
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
+#ifdef ANDROID +#ifdef __ANDROID__
+ fb->set_transport(open_device(context)); + fb->set_transport(open_device(context));
+#else +#else
fb->set_transport(open_device()); fb->set_transport(open_device());
@ -85,7 +85,7 @@ index 0062e7e..9d2ee12 100644
FlashAllTool(const ImageSource& source, const std::string& slot_override, bool skip_secondary, FlashAllTool(const ImageSource& source, const std::string& slot_override, bool skip_secondary,
bool wipe, bool force_flash); bool wipe, bool force_flash);
+#ifdef ANDROID +#ifdef __ANDROID__
+ void Flash(libusb_context *context); + void Flash(libusb_context *context);
+#else +#else
void Flash(); void Flash();
@ -97,7 +97,7 @@ index 0062e7e..9d2ee12 100644
void CollectImages(); void CollectImages();
void FlashImages(const std::vector<std::pair<const Image*, std::string>>& images); void FlashImages(const std::vector<std::pair<const Image*, std::string>>& images);
void FlashImage(const Image& image, const std::string& slot, fastboot_buffer* buf); void FlashImage(const Image& image, const std::string& slot, fastboot_buffer* buf);
+#ifdef ANDROID +#ifdef __ANDROID__
+ void UpdateSuperPartition(libusb_context *context); + void UpdateSuperPartition(libusb_context *context);
+#else +#else
void UpdateSuperPartition(); void UpdateSuperPartition();
@ -109,7 +109,7 @@ index 0062e7e..9d2ee12 100644
{ {
} }
+#ifdef ANDROID +#ifdef __ANDROID__
+void FlashAllTool::Flash(libusb_context *context) { +void FlashAllTool::Flash(libusb_context *context) {
+#else +#else
void FlashAllTool::Flash() { void FlashAllTool::Flash() {
@ -121,7 +121,7 @@ index 0062e7e..9d2ee12 100644
FlashImages(boot_images_); FlashImages(boot_images_);
// Sync the super partition. This will reboot to userspace fastboot if needed. // Sync the super partition. This will reboot to userspace fastboot if needed.
+#ifdef ANDROID +#ifdef __ANDROID__
+ UpdateSuperPartition(context); + UpdateSuperPartition(context);
+#else +#else
UpdateSuperPartition(); UpdateSuperPartition();
@ -133,7 +133,7 @@ index 0062e7e..9d2ee12 100644
do_for_partitions(image.part_name, slot, flash, false); do_for_partitions(image.part_name, slot, flash, false);
} }
+#ifdef ANDROID +#ifdef __ANDROID__
+void FlashAllTool::UpdateSuperPartition(libusb_context *context) { +void FlashAllTool::UpdateSuperPartition(libusb_context *context) {
+#else +#else
void FlashAllTool::UpdateSuperPartition() { void FlashAllTool::UpdateSuperPartition() {
@ -143,7 +143,7 @@ index 0062e7e..9d2ee12 100644
return; return;
} }
if (!is_userspace_fastboot()) { if (!is_userspace_fastboot()) {
+#ifdef ANDROID +#ifdef __ANDROID__
+ reboot_to_userspace_fastboot(context); + reboot_to_userspace_fastboot(context);
+#else +#else
reboot_to_userspace_fastboot(); reboot_to_userspace_fastboot();
@ -155,7 +155,7 @@ index 0062e7e..9d2ee12 100644
} }
static void do_update(const char* filename, const std::string& slot_override, bool skip_secondary, static void do_update(const char* filename, const std::string& slot_override, bool skip_secondary,
+#ifdef ANDROID +#ifdef __ANDROID__
+ bool force_flash, libusb_context *context) { + bool force_flash, libusb_context *context) {
+#else +#else
bool force_flash) { bool force_flash) {
@ -167,7 +167,7 @@ index 0062e7e..9d2ee12 100644
} }
FlashAllTool tool(ZipImageSource(zip), slot_override, skip_secondary, false, force_flash); FlashAllTool tool(ZipImageSource(zip), slot_override, skip_secondary, false, force_flash);
+#ifdef ANDROID +#ifdef __ANDROID__
+ tool.Flash(context); + tool.Flash(context);
+#else +#else
tool.Flash(); tool.Flash();
@ -179,13 +179,13 @@ index 0062e7e..9d2ee12 100644
} }
static void do_flashall(const std::string& slot_override, bool skip_secondary, bool wipe, static void do_flashall(const std::string& slot_override, bool skip_secondary, bool wipe,
+#ifdef ANDROID +#ifdef __ANDROID__
+ bool force_flash, libusb_context *context) { + bool force_flash, libusb_context *context) {
+#else +#else
bool force_flash) { bool force_flash) {
+#endif +#endif
FlashAllTool tool(LocalImageSource(), slot_override, skip_secondary, wipe, force_flash); FlashAllTool tool(LocalImageSource(), slot_override, skip_secondary, wipe, force_flash);
+#ifdef ANDROID +#ifdef __ANDROID__
+ tool.Flash(context); + tool.Flash(context);
+#else +#else
tool.Flash(); tool.Flash();
@ -197,7 +197,7 @@ index 0062e7e..9d2ee12 100644
} }
} }
+#ifdef ANDROID +#ifdef __ANDROID__
+int FastBootTool::Main(int argc, char* argv[]) { +int FastBootTool::Main(int argc, char* argv[]) {
+ libusb_context *context; + libusb_context *context;
+ libusb_set_option(NULL, LIBUSB_OPTION_WEAK_AUTHORITY); + libusb_set_option(NULL, LIBUSB_OPTION_WEAK_AUTHORITY);
@ -218,7 +218,7 @@ index 0062e7e..9d2ee12 100644
if (argc == 0 && !wants_wipe && !wants_set_active) syntax_error("no command"); if (argc == 0 && !wants_wipe && !wants_set_active) syntax_error("no command");
if (argc > 0 && !strcmp(*argv, "devices")) { if (argc > 0 && !strcmp(*argv, "devices")) {
+#ifdef ANDROID +#ifdef __ANDROID__
+ list_devices(context); + list_devices(context);
+#else +#else
list_devices(); list_devices();
@ -230,7 +230,7 @@ index 0062e7e..9d2ee12 100644
return show_help(); return show_help();
} }
+#ifdef ANDROID +#ifdef __ANDROID__
+ Transport* transport = open_device(context); + Transport* transport = open_device(context);
+#else +#else
Transport* transport = open_device(); Transport* transport = open_device();
@ -242,13 +242,13 @@ index 0062e7e..9d2ee12 100644
} else if (command == "flashall") { } else if (command == "flashall") {
if (slot_override == "all") { if (slot_override == "all") {
fprintf(stderr, "Warning: slot set to 'all'. Secondary slots will not be flashed.\n"); fprintf(stderr, "Warning: slot set to 'all'. Secondary slots will not be flashed.\n");
+#ifdef ANDROID +#ifdef __ANDROID__
+ do_flashall(slot_override, true, wants_wipe, force_flash, context); + do_flashall(slot_override, true, wants_wipe, force_flash, context);
+#else +#else
do_flashall(slot_override, true, wants_wipe, force_flash); do_flashall(slot_override, true, wants_wipe, force_flash);
+#endif +#endif
} else { } else {
+#ifdef ANDROID +#ifdef __ANDROID__
+ do_flashall(slot_override, skip_secondary, wants_wipe, force_flash, context); + do_flashall(slot_override, skip_secondary, wants_wipe, force_flash, context);
+#else +#else
do_flashall(slot_override, skip_secondary, wants_wipe, force_flash); do_flashall(slot_override, skip_secondary, wants_wipe, force_flash);
@ -260,7 +260,7 @@ index 0062e7e..9d2ee12 100644
if (!args.empty()) { if (!args.empty()) {
filename = next_arg(&args); filename = next_arg(&args);
} }
+#ifdef ANDROID +#ifdef __ANDROID__
+ do_update(filename.c_str(), slot_override, skip_secondary || slot_all, force_flash, context); + do_update(filename.c_str(), slot_override, skip_secondary || slot_all, force_flash, context);
+#else +#else
do_update(filename.c_str(), slot_override, skip_secondary || slot_all, force_flash); do_update(filename.c_str(), slot_override, skip_secondary || slot_all, force_flash);
@ -272,7 +272,7 @@ index 0062e7e..9d2ee12 100644
fb->RebootTo("recovery"); fb->RebootTo("recovery");
fb->WaitForDisconnect(); fb->WaitForDisconnect();
} else if (wants_reboot_fastboot) { } else if (wants_reboot_fastboot) {
+#ifdef ANDROID +#ifdef __ANDROID__
+ reboot_to_userspace_fastboot(context); + reboot_to_userspace_fastboot(context);
+#else +#else
reboot_to_userspace_fastboot(); reboot_to_userspace_fastboot();

View File

@ -6,7 +6,7 @@ index c23793a..b7c07f0 100644
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
+#ifdef ANDROID +#ifdef __ANDROID__
+#include <libusb-1.0/libusb.h> +#include <libusb-1.0/libusb.h>
+#endif +#endif
+ +
@ -15,7 +15,7 @@ index c23793a..b7c07f0 100644
class FastBootTool { class FastBootTool {
public: public:
int Main(int argc, char* argv[]); int Main(int argc, char* argv[]);
+#ifdef ANDROID +#ifdef __ANDROID__
+ int RealMain(int argc, char* argv[], libusb_context *context); + int RealMain(int argc, char* argv[], libusb_context *context);
+#endif +#endif

View File

@ -6,7 +6,7 @@ index e5f56e2..eea0075 100644
#pragma once #pragma once
+#ifdef ANDROID +#ifdef __ANDROID__
+#include <libusb-1.0/libusb.h> +#include <libusb-1.0/libusb.h>
+#endif +#endif
+ +
@ -18,7 +18,7 @@ index e5f56e2..eea0075 100644
char interface[256]; char interface[256];
+ +
+#ifdef ANDROID +#ifdef __ANDROID__
+ bool termux_usb; + bool termux_usb;
+#endif +#endif
}; };
@ -28,7 +28,7 @@ index e5f56e2..eea0075 100644
typedef int (*ifc_match_func)(usb_ifc_info *ifc); typedef int (*ifc_match_func)(usb_ifc_info *ifc);
// 0 is non blocking // 0 is non blocking
+#ifdef ANDROID +#ifdef __ANDROID__
+UsbTransport* usb_open(ifc_match_func callback, libusb_context *context, uint32_t timeout_ms = 0); +UsbTransport* usb_open(ifc_match_func callback, libusb_context *context, uint32_t timeout_ms = 0);
+#else +#else
UsbTransport* usb_open(ifc_match_func callback, uint32_t timeout_ms = 0); UsbTransport* usb_open(ifc_match_func callback, uint32_t timeout_ms = 0);

View File

@ -6,7 +6,7 @@ index 964488c..d03f3a2 100644
#include <linux/usbdevice_fs.h> #include <linux/usbdevice_fs.h>
#include <linux/version.h> #include <linux/version.h>
#include <linux/usb/ch9.h> #include <linux/usb/ch9.h>
+#ifdef ANDROID +#ifdef __ANDROID__
+#include <libusb-1.0/libusb.h> +#include <libusb-1.0/libusb.h>
+#endif +#endif
@ -16,7 +16,7 @@ index 964488c..d03f3a2 100644
struct usb_handle struct usb_handle
{ {
char fname[64]; char fname[64];
+#ifdef ANDROID +#ifdef __ANDROID__
+ int fd; + int fd;
+ bool termux_usb; + bool termux_usb;
+#endif +#endif
@ -27,7 +27,7 @@ index 964488c..d03f3a2 100644
} }
static int filter_usb_device(char* sysfs_name, static int filter_usb_device(char* sysfs_name,
+#ifdef ANDROID +#ifdef __ANDROID__
+ libusb_context *context, int fd, bool termux_usb, + libusb_context *context, int fd, bool termux_usb,
+#endif +#endif
char *ptr, int len, int writable, char *ptr, int len, int writable,
@ -37,7 +37,7 @@ index 964488c..d03f3a2 100644
info.dev_subclass = dev->bDeviceSubClass; info.dev_subclass = dev->bDeviceSubClass;
info.dev_protocol = dev->bDeviceProtocol; info.dev_protocol = dev->bDeviceProtocol;
info.writable = writable; info.writable = writable;
+#ifdef ANDROID +#ifdef __ANDROID__
+ info.termux_usb = termux_usb; + info.termux_usb = termux_usb;
+ if (termux_usb) + if (termux_usb)
@ -51,7 +51,7 @@ index 964488c..d03f3a2 100644
*/ */
info.serial_number[0] = '\0'; info.serial_number[0] = '\0';
if (dev->iSerialNumber) { if (dev->iSerialNumber) {
+#ifdef ANDROID +#ifdef __ANDROID__
+ if (termux_usb) { + if (termux_usb) {
+ libusb_device_handle *handle; + libusb_device_handle *handle;
+ unsigned char serial_num[256]; + unsigned char serial_num[256];
@ -67,7 +67,7 @@ index 964488c..d03f3a2 100644
info.serial_number[chars_read - 1] = '\0'; info.serial_number[chars_read - 1] = '\0';
} }
} }
+#ifdef ANDROID +#ifdef __ANDROID__
+ } + }
+#endif +#endif
} }
@ -77,7 +77,7 @@ index 964488c..d03f3a2 100644
info.has_bulk_in = (in != -1); info.has_bulk_in = (in != -1);
info.has_bulk_out = (out != -1); info.has_bulk_out = (out != -1);
+#ifdef ANDROID +#ifdef __ANDROID__
+ if (termux_usb) + if (termux_usb)
+ snprintf(info.interface, sizeof(info.interface), "fastboot\n"); + snprintf(info.interface, sizeof(info.interface), "fastboot\n");
+ else { + else {
@ -88,7 +88,7 @@ index 964488c..d03f3a2 100644
if (android::base::ReadFileToString(path, &interface)) { if (android::base::ReadFileToString(path, &interface)) {
snprintf(info.interface, sizeof(info.interface), "%s", interface.c_str()); snprintf(info.interface, sizeof(info.interface), "%s", interface.c_str());
} }
+#ifdef ANDROID +#ifdef __ANDROID__
+ } + }
+#endif +#endif
@ -98,7 +98,7 @@ index 964488c..d03f3a2 100644
return 0; return 0;
} }
+#ifdef ANDROID +#ifdef __ANDROID__
+static std::unique_ptr<usb_handle> find_usb_device(const char* base, libusb_context *context, ifc_match_func callback) +static std::unique_ptr<usb_handle> find_usb_device(const char* base, libusb_context *context, ifc_match_func callback)
+#else +#else
static std::unique_ptr<usb_handle> find_usb_device(const char* base, ifc_match_func callback) static std::unique_ptr<usb_handle> find_usb_device(const char* base, ifc_match_func callback)
@ -110,7 +110,7 @@ index 964488c..d03f3a2 100644
int fd; int fd;
int writable; int writable;
+#ifdef ANDROID +#ifdef __ANDROID__
+ bool linux_usb, termux_usb; + bool linux_usb, termux_usb;
+ linux_usb = termux_usb = true; + linux_usb = termux_usb = true;
+ writable = 1; + writable = 1;
@ -123,7 +123,7 @@ index 964488c..d03f3a2 100644
+#endif +#endif
+ +
std::unique_ptr<DIR, decltype(&closedir)> busdir(opendir(base), closedir); std::unique_ptr<DIR, decltype(&closedir)> busdir(opendir(base), closedir);
+#ifdef ANDROID +#ifdef __ANDROID__
+ if (busdir == 0) linux_usb = false; + if (busdir == 0) linux_usb = false;
+ +
+ bool is_linux_usb, is_termux_usb; + bool is_linux_usb, is_termux_usb;
@ -147,7 +147,7 @@ index 964488c..d03f3a2 100644
// DBG("[ scanning %s ]\n", devname); // DBG("[ scanning %s ]\n", devname);
writable = 1; writable = 1;
+#ifdef ANDROID +#ifdef __ANDROID__
+ if (is_termux_usb) lseek(fd, 0, SEEK_SET); + if (is_termux_usb) lseek(fd, 0, SEEK_SET);
+ else { + else {
+#endif +#endif
@ -158,19 +158,19 @@ index 964488c..d03f3a2 100644
continue; continue;
} }
} }
+#ifdef ANDROID +#ifdef __ANDROID__
+ } + }
+#endif +#endif
n = read(fd, desc, sizeof(desc)); n = read(fd, desc, sizeof(desc));
+#ifdef ANDROID +#ifdef __ANDROID__
+ if (filter_usb_device(de->d_name, context, fd, is_termux_usb, desc, n, writable, callback, &in, &out, &ifc) == 0) { + if (filter_usb_device(de->d_name, context, fd, is_termux_usb, desc, n, writable, callback, &in, &out, &ifc) == 0) {
+#else +#else
if (filter_usb_device(de->d_name, desc, n, writable, callback, &in, &out, &ifc) == 0) { if (filter_usb_device(de->d_name, desc, n, writable, callback, &in, &out, &ifc) == 0) {
+#endif +#endif
usb.reset(new usb_handle()); usb.reset(new usb_handle());
+#ifdef ANDROID +#ifdef __ANDROID__
+ usb->fd = fd; + usb->fd = fd;
+ usb->termux_usb = is_termux_usb; + usb->termux_usb = is_termux_usb;
+#else +#else
@ -183,7 +183,7 @@ index 964488c..d03f3a2 100644
return 0; return 0;
} }
+#ifdef ANDROID +#ifdef __ANDROID__
+UsbTransport* usb_open(ifc_match_func callback, libusb_context *context, uint32_t timeout_ms) { +UsbTransport* usb_open(ifc_match_func callback, libusb_context *context, uint32_t timeout_ms) {
+ std::unique_ptr<usb_handle> handle = find_usb_device("/sys/bus/usb/devices", context, callback); + std::unique_ptr<usb_handle> handle = find_usb_device("/sys/bus/usb/devices", context, callback);
+#else +#else
@ -197,13 +197,13 @@ index 964488c..d03f3a2 100644
{ {
double deadline = now() + WAIT_FOR_DISCONNECT_TIMEOUT; double deadline = now() + WAIT_FOR_DISCONNECT_TIMEOUT;
while (now() < deadline) { while (now() < deadline) {
+#ifdef ANDROID +#ifdef __ANDROID__
+ if(handle_->termux_usb) { + if(handle_->termux_usb) {
+ if (fcntl(handle_->fd, F_GETFD) == -1) return 0; + if (fcntl(handle_->fd, F_GETFD) == -1) return 0;
+ } else { + } else {
+#endif +#endif
if (access(handle_->fname, F_OK)) return 0; if (access(handle_->fname, F_OK)) return 0;
+#ifdef ANDROID +#ifdef __ANDROID__
+ } + }
+#endif +#endif
std::this_thread::sleep_for(50ms); std::this_thread::sleep_for(50ms);