adb.fastboot module

A libusb1-based fastboot implementation.

Contents

adb.fastboot.CLASS = 255

From fastboot.c

adb.fastboot.DEFAULT_MESSAGE_CALLBACK(m)

TODO

adb.fastboot.DeviceIsAvailable(device)

TODO

class adb.fastboot.FastbootCommands[source]

Bases: object

Encapsulates the fastboot commands.

_images/adb.fastboot.FastbootCommands.__init__.CALLER_GRAPH.svg
_handle

TODO

Type

TODO, None

_protocol

TODO

Type

TODO, None

Close()[source]

TODO

ConnectDevice(port_path=None, serial=None, default_timeout_ms=None, chunk_kb=1024, **kwargs)[source]

Convenience function to get an adb device from usb path or serial.

Parameters
  • port_path (TODO, None) – The filename of usb port to use.

  • serial (TODO, None) – The serial number of the device to use. If serial specifies a TCP address:port, then a TCP connection is used instead of a USB connection.

  • default_timeout_ms (TODO, None) – The default timeout in milliseconds to use.

  • chunk_kb (int) – Amount of data, in kilobytes, to break fastboot packets up into

  • **kwargs (dict) – Keyword arguments

  • handle (adb.common.TcpHandle, adb.common.UsbHandle) – Device handle to use

  • banner (TODO) – Connection banner to pass to the remote device

  • rsa_keys (list[adb_protocol.AuthSigner]) – List of AuthSigner subclass instances to be used for authentication. The device can either accept one of these via the Sign method, or we will send the result of GetPublicKey from the first one if the device doesn’t accept any of them.

  • auth_timeout_ms (TODO) – Timeout to wait for when sending a new public key. This is only relevant when we send a new public key. The device shows a dialog and this timeout is how long to wait for that dialog. If used in automation, this should be low to catch such a case as a failure quickly; while in interactive settings it should be high to allow users to accept the dialog. We default to automation here, so it’s low by default.

Returns

self – TODO

Return type

FastbootCommands

Continue()[source]

Continues execution past fastboot into the system.

_images/adb.fastboot.FastbootCommands.Continue.CALL_GRAPH.svg
Returns

TODO

Return type

TODO

classmethod Devices()[source]

Get a generator of UsbHandle for devices available.

Returns

TODO

Return type

TODO

Download(source_file, source_len=0, info_cb=<function <lambda>>, progress_callback=None)[source]

Downloads a file to the device.

_images/adb.fastboot.FastbootCommands.Download.CALLER_GRAPH.svg
Parameters
  • source_file (TODO) – A filename or file-like object to download to the device.

  • source_len (int) – Optional length of source_file. If source_file is a file-like object and source_len is not provided, source_file is read into memory.

  • info_cb (TODO) – Optional callback accepting FastbootMessage for text sent from the bootloader.

  • progress_callback (TODO, None) – Optional callback called with the percent of the source_file downloaded. Note, this doesn’t include progress of the actual flashing.

Returns

Response to a download request, normally nothing.

Return type

TODO

Erase(partition, timeout_ms=None)[source]

Erases the given partition.

_images/adb.fastboot.FastbootCommands.Erase.CALL_GRAPH.svg
Parameters
  • partition (TODO) – Partition to clear.

  • timeout_ms (TODO, None) – TODO

Flash(partition, timeout_ms=0, info_cb=<function <lambda>>)[source]

Flashes the last downloaded file to the given partition.

_images/adb.fastboot.FastbootCommands.Flash.CALL_GRAPH.svg_images/adb.fastboot.FastbootCommands.Flash.CALLER_GRAPH.svg
Parameters
  • partition (TODO) – Partition to overwrite with the new image.

  • timeout_ms (int) – Optional timeout in milliseconds to wait for it to finish.

  • info_cb (TODO) – See FastbootCommands.Download(). Usually no messages.

Returns

Response to a download request, normally nothing.

Return type

TODO

FlashFromFile(partition, source_file, source_len=0, info_cb=<function <lambda>>, progress_callback=None)[source]

Flashes a partition from the file on disk.

_images/adb.fastboot.FastbootCommands.FlashFromFile.CALL_GRAPH.svg_images/adb.fastboot.FastbootCommands.FlashFromFile.CALLER_GRAPH.svg
Parameters
  • partition (TODO) – Partition name to flash to.

  • source_file (TODO) – Filename to download to the device.

  • source_len (int) – Optional length of source_file, uses os.stat if not provided.

  • info_cb (TODO) – See Download.

  • progress_callback (TODO) – See Download.

Returns

Download and flash responses, normally nothing.

Return type

TODO

Getvar(var, info_cb=<function <lambda>>)[source]

Returns the given variable’s definition.

_images/adb.fastboot.FastbootCommands.Getvar.CALL_GRAPH.svg
Parameters
  • var (TODO) – A variable the bootloader tracks. Use ‘all’ to get them all.

  • info_cb (TODO) – See FastbootCommands.Download(). Usually no messages.

Returns

Value of var according to the current bootloader.

Return type

TODO

Oem(command, timeout_ms=None, info_cb=<function <lambda>>)[source]

Executes an OEM command on the device.

_images/adb.fastboot.FastbootCommands.Oem.CALL_GRAPH.svg
Parameters
  • command (TODO) – Command to execute, such as ‘poweroff’ or ‘bootconfig read’.

  • timeout_ms (TODO, None) – Optional timeout in milliseconds to wait for a response.

  • info_cb (TODO) – See FastbootCommands.Download(). Messages vary based on command.

Returns

Return type

The final response from the device.

Reboot(target_mode=b'', timeout_ms=None)[source]

Reboots the device.

_images/adb.fastboot.FastbootCommands.Reboot.CALL_GRAPH.svg
Parameters
  • target_mode (bytes) – Normal reboot when unspecified. Can specify other target modes such as ‘recovery’ or ‘bootloader’.

  • timeout_ms (TODO, None) – Optional timeout in milliseconds to wait for a response.

Returns

Usually the empty string. Depends on the bootloader and the target_mode.

Return type

TODO

RebootBootloader(timeout_ms=None)[source]

Reboots into the bootloader, usually equiv to Reboot(‘bootloader’).

_images/adb.fastboot.FastbootCommands.RebootBootloader.CALL_GRAPH.svg
Parameters

timeout_ms (TODO, None) – TODO

Returns

TODO

Return type

TODO

_FastbootCommands__reset()

TODO

_images/adb.fastboot.FastbootCommands.__reset.CALL_GRAPH.svg
_SimpleCommand(command, arg=None, **kwargs)[source]

TODO

_images/adb.fastboot.FastbootCommands._SimpleCommand.CALL_GRAPH.svg_images/adb.fastboot.FastbootCommands._SimpleCommand.CALLER_GRAPH.svg
Parameters
  • command (TODO) – TODO

  • arg (TODO, None) – TODO

  • **kwargs (dict) – Keyword arguments

  • TODO – TODO

Returns

TODO

Return type

TODO

property usb_handle

TODO

Returns

self._handle – TODO

Return type

TODO

exception adb.fastboot.FastbootInvalidResponse(message, *args)[source]

Bases: adb.usb_exceptions.FormatMessageWithArgumentsException

Fastboot responded with a header we didn’t expect.

_images/adb.fastboot.FastbootInvalidResponse.CALL_GRAPH.svg
class adb.fastboot.FastbootMessage(message, header)

Bases: tuple

FastbootMessage

_fields_defaults = {}
class adb.fastboot.FastbootProtocol(usb, chunk_kb=1024)[source]

Bases: object

Encapsulates the fastboot protocol.

_images/adb.fastboot.FastbootProtocol.__init__.CALLER_GRAPH.svg
Parameters
chunk_kb

Packet size. For older devices, 4 may be required.

Type

int

usb

adb.common.UsbHandle instance.

Type

adb.common.UsbHandle

FINAL_HEADERS = {b'DATA', b'OKAY'}
HandleDataSending(source_file, source_len, info_cb=<function <lambda>>, progress_callback=None, timeout_ms=None)[source]

Handles the protocol for sending data to the device.

_images/adb.fastboot.FastbootProtocol.HandleDataSending.CALL_GRAPH.svg_images/adb.fastboot.FastbootProtocol.HandleDataSending.CALLER_GRAPH.svg
Parameters
  • source_file (TODO) – File-object to read from for the device.

  • source_len (TODO) – Amount of data, in bytes, to send to the device.

  • info_cb (TODO) – Optional callback for text sent from the bootloader.

  • progress_callback (TODO, None) – Callback that takes the current and the total progress of the current file.

  • timeout_ms (TODO, None) – Timeout in milliseconds to wait for each response.

Returns

OKAY packet’s message.

Return type

TODO

Raises
HandleSimpleResponses(timeout_ms=None, info_cb=<function <lambda>>)[source]

Accepts normal responses from the device.

_images/adb.fastboot.FastbootProtocol.HandleSimpleResponses.CALL_GRAPH.svg_images/adb.fastboot.FastbootProtocol.HandleSimpleResponses.CALLER_GRAPH.svg
Parameters
  • timeout_ms (TODO, None) – Timeout in milliseconds to wait for each response.

  • info_cb (TODO) – Optional callback for text sent from the bootloader.

Returns

OKAY packet’s message.

Return type

TODO

SendCommand(command, arg=None)[source]

Sends a command to the device.

_images/adb.fastboot.FastbootProtocol.SendCommand.CALL_GRAPH.svg
Parameters
  • command (str) – The command to send.

  • arg (str) – Optional argument to the command.

_AcceptResponses(expected_header, info_cb, timeout_ms=None)[source]

Accepts responses until the expected header or a FAIL.

_images/adb.fastboot.FastbootProtocol._AcceptResponses.CALLER_GRAPH.svg
Parameters
  • expected_header (TODO) – OKAY or DATA

  • info_cb (TODO) – Optional callback for text sent from the bootloader.

  • timeout_ms (TODO) – Timeout in milliseconds to wait for each response.

Returns

OKAY packet’s message.

Return type

TODO

Raises
static _HandleProgress(total, progress_callback)[source]

Calls the callback with the current progress and total.

_images/adb.fastboot.FastbootProtocol._HandleProgress.CALLER_GRAPH.svg
Parameters
  • total (TODO) – TODO

  • progress_callback (TODO) – TODO

_Write(data, length, progress_callback=None)[source]

Sends the data to the device, tracking progress with the callback.

_images/adb.fastboot.FastbootProtocol._Write.CALL_GRAPH.svg_images/adb.fastboot.FastbootProtocol._Write.CALLER_GRAPH.svg
Parameters
  • data (TODO) – TODO

  • length (TODO) – TODO

  • progress_callback (TODO, None) – TODO

property usb_handle

TODO

Returns

self.usbadb.common.UsbHandle instance.

Return type

adb.common.UsbHandle

exception adb.fastboot.FastbootRemoteFailure(message, *args)[source]

Bases: adb.usb_exceptions.FormatMessageWithArgumentsException

Remote error.

_images/adb.fastboot.FastbootRemoteFailure.CALL_GRAPH.svg
exception adb.fastboot.FastbootStateMismatch(message, *args)[source]

Bases: adb.usb_exceptions.FormatMessageWithArgumentsException

Fastboot and uboot’s state machines are arguing. You Lose.

_images/adb.fastboot.FastbootStateMismatch.CALL_GRAPH.svg
exception adb.fastboot.FastbootTransferError(message, *args)[source]

Bases: adb.usb_exceptions.FormatMessageWithArgumentsException

Transfer error.

_images/adb.fastboot.FastbootTransferError.CALL_GRAPH.svg
adb.fastboot.PROTOCOL = 3

From fastboot.c

adb.fastboot.SUBCLASS = 66

From fastboot.c

adb.fastboot.VENDORS = {1105, 1282, 1478, 2389, 2996, 4046, 6353, 8888, 8980, 16700, 32903}

From fastboot.c