-
Notifications
You must be signed in to change notification settings - Fork 65
snagrecover: imx: add support for the i.MX95 #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
YanAkkI2S
wants to merge
1
commit into
bootlin:main
Choose a base branch
from
YanAkkI2S:imx95
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
| from snagrecover.utils import prettify_usb_addr | ||
| import glob | ||
| import usb | ||
| from usb.backend.libusb1 import LIBUSB_ERROR_NO_DEVICE | ||
| import os | ||
| import platform | ||
| import select | ||
|
|
@@ -111,7 +112,7 @@ def get_hidraw_device(self): | |
|
|
||
| return hidraw_path | ||
|
|
||
| def __init__(self, usb_dev: usb.core.Device): | ||
| def __init__(self, usb_dev: usb.core.Device, prefer_libusb: bool = False): | ||
| pretty_addr = prettify_usb_addr((usb_dev.bus, usb_dev.port_numbers)) | ||
| if not is_hid(usb_dev): | ||
| raise IOError(f"Device {pretty_addr}, is USB but not HID!") | ||
|
|
@@ -135,9 +136,11 @@ def __init__(self, usb_dev: usb.core.Device): | |
| ) | ||
| self.usb_dev.set_configuration(self.main_cfg.bConfigurationValue) | ||
|
|
||
| if platform.system() == "Linux" and self.usb_dev.is_kernel_driver_active( | ||
| self.main_intf.bInterfaceNumber | ||
| ): | ||
| kernel_driver_active = platform.system() == "Linux" and ( | ||
| self.usb_dev.is_kernel_driver_active(self.main_intf.bInterfaceNumber) | ||
| ) | ||
|
|
||
| if kernel_driver_active and not prefer_libusb: | ||
| # The kernel driver in question should be usbhid | ||
| hidraw_path = self.get_hidraw_device() | ||
| if hidraw_path is None: | ||
|
|
@@ -151,6 +154,9 @@ def __init__(self, usb_dev: usb.core.Device): | |
| logger.info(f"HID device {pretty_addr} has hidraw dev {hidraw_path}") | ||
|
|
||
| else: | ||
| if kernel_driver_active: | ||
| self.usb_dev.detach_kernel_driver(self.main_intf.bInterfaceNumber) | ||
|
rgantois marked this conversation as resolved.
|
||
|
|
||
| # This case is for systems which don't | ||
| # have usbhid loaded for some reason. | ||
| # It is also suitable for Windows. if | ||
|
|
@@ -230,7 +236,15 @@ def close(self): | |
| if self.hidraw: | ||
| self.hidraw.close() | ||
| else: | ||
| usb.util.release_interface(self.usb_dev, self.main_intf.bInterfaceNumber) | ||
| try: | ||
| usb.util.release_interface( | ||
| self.usb_dev, self.main_intf.bInterfaceNumber | ||
| ) | ||
| except usb.USBError as err: | ||
| # the device may already be gone (re-enumerated after jumping to firmware) | ||
| # and don't silently ignore any other errors | ||
| if err.backend_error_code != LIBUSB_ERROR_NO_DEVICE: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use e.errno instead? That way you don't have to assume a particular USB backend. |
||
| raise | ||
|
|
||
| def hidraw_read(self, length: int, timeout: int): | ||
| r, w, e = select.select([self.hidraw], [], [], timeout) | ||
|
|
@@ -244,7 +258,7 @@ def hidraw_read(self, length: int, timeout: int): | |
| def libusb_write(self, data: bytes): | ||
| # Use Interrupt OUT endpoint if available | ||
| if self.intr_out: | ||
| return self.usb_dev.write(self.intr_out, data) | ||
| return self.usb_dev.write(self.intr_out, data, timeout=5000) | ||
|
|
||
| report_id = data[0] | ||
| self.set_report(report_id, data) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,8 @@ tested: | |
| family: imx | ||
| imx93: | ||
| family: imx | ||
| imx95: | ||
| family: imx | ||
| keembay: | ||
| family: keembay | ||
| r8: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| flash-bin: | ||
| path: imx-boot |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't assume that libusb1 is being used.