Skip to content

Commit

Permalink
intel tool: implement reboot-bootloader
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverBzH committed Jan 10, 2024
1 parent 52484c5 commit cba28f0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
25 changes: 23 additions & 2 deletions bumble/drivers/intel.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ class Hci_Intel_Secure_Send_Command(HCI_Command):
pass


# Please see linux/drivers/bluetooth/btintel.c for more informations.
# Intel Reset parameter description:
# reset_type : 0x00 (Soft reset), 0x01 (Hard reset)
# patch_enable: 0x00 (Do not enable), 0x01 (Enable)
# ddc_reload : 0x00 (Do not reload), 0x01 (Reload)
# boot_option: 0x00 (Current image), 0x01 (Specified boot address)
# boot_param: Boot address
@HCI_Command.command( # type: ignore
fields=[
("reset_type", 1),
Expand Down Expand Up @@ -228,6 +235,18 @@ async def download_fw_payload(host, fw: bytes, header_offset: int):
frag_len = 0


def reboot_bootloader(host): # type: ignore
host.send_command_sync( # type: ignore
Hci_Intel_Reset_Command(
reset_type=0x01,
patch_enable=0x01,
ddc_reload=0x01,
boot_option=0x00,
boot_param=0x00000000,
)
)


class Driver(common.Driver):
def __init__(self, host, version: IntelVersionTLV, firmware: bytes, fw_name: str):
self.host = host
Expand Down Expand Up @@ -378,7 +397,9 @@ async def download_firmware(host, version: IntelVersionTLV, fw: bytes):
raise ValueError("IMG_TYPE cannot be NONE")

if version.img_type[0] == OPERATIONAL_FW:
raise RuntimeError("Device needs to be reset to bootloader")
raise RuntimeError(
"Device needs to be reset to bootloader. See tools/intel_utils.py --help."
)

if version.cnvi_bt is None:
raise ValueError("CNVI Bluetooth verion cannot be None")
Expand All @@ -403,7 +424,7 @@ async def download_firmware(host, version: IntelVersionTLV, fw: bytes):
await sfi_ecdsa_header_secure_send(host, fw)
await download_fw_payload(host, fw, RSA_HEADER_LEN + ECDSA_HEADER_LEN)
await host.send_command( # type: ignore
Hci_Intel_Reset_Command( # type: ignore
Hci_Intel_Reset_Command(
reset_type=0x00,
patch_enable=0x01,
ddc_reload=0x00,
Expand Down
25 changes: 25 additions & 0 deletions tools/intel_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ async def do_info(transport: str, force: bool):
)


# -----------------------------------------------------------------------------
async def do_reboot_bootloader(transport: str, force: bool):
async with await bumbleTransport.open_transport(transport) as (
hci_source,
hci_sink,
):
# Create a host to communicate with the device
host = Host(hci_source, hci_sink) # type: ignore
if not force and not intel.Driver.check(host): # type: ignore
print("Device not supported by this Intel driver")
return

intel.reboot_bootloader(host) # type: ignore


# -----------------------------------------------------------------------------
@click.group()
def main():
Expand Down Expand Up @@ -114,6 +129,16 @@ def info(transport: str, force: bool):
asyncio.run(do_info(transport, force))


@main.command
@click.argument("transport")
@click.option(
"--force", is_flag=True, default=False, help="Force the reset in bootloader state"
)
def reboot_bootloader(transport: str, force: bool):
"""Reboot the device in bootloader state"""
asyncio.run(do_reboot_bootloader(transport, force))


# -----------------------------------------------------------------------------
if __name__ == '__main__':
main()

0 comments on commit cba28f0

Please sign in to comment.