Skip to content
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

Updated STLink-v1 driver for macOS #964

Merged
merged 3 commits into from
May 28, 2020
Merged

Updated STLink-v1 driver for macOS #964

merged 3 commits into from
May 28, 2020

Conversation

Nightwalker-87
Copy link
Member

@Nightwalker-87 Nightwalker-87 commented May 23, 2020

  • Updated Xcode project settings to Xcode v11.3.1
  • Removed old deprecated Xcode project settings
  • Removed support for macOS 10.6-10.12
  • Compiled new kexts for macOS 10.13-10.15
  • Moved instructions to separate README
  • Updated installation instructions

Special thanks to @dot4qu for testing on macOS Catalina!

(Closes #735)

@Nightwalker-87
Copy link
Member Author

I really hope that this rework is mainly functional. We definitely need either old hardware or at least one person to test.

  • The first task would be to go through the install instructions to see if everything works out as expected on macOS 10.13/10.14/10.15.
  • The second step would be a verification that the hardware is accessible and usable.

- Updated xcode project settings v11.3.1
- Removed support for 10.6-10.12
- Compiled new kexts for macOS 10.13-10.15
- Moved instructions to separate README
- Updated installation instructions
@Nightwalker-87
Copy link
Member Author

Nightwalker-87 commented May 26, 2020

We have a STM32VL DISCOVERY (STM32F100RB) board now which contains an onboard ST-Link/V1 module (I shot an original one (2010) on ebay for cheap).

I have found some additional time to test the kext on a macOS 10.13 and 10.14 machine. They install as expected with csrutil (SIP) disabled. Thus I will not test the kext with 10.15, but safely assume it will install as flawlessly as the other ones do. Instead I am going to do a hw-test with the STM32VL once it arrives to see if it is accessible. However it would still be useful if there was any feedback from the user side as well.

@Nightwalker-87
Copy link
Member Author

@dot4qu: Can you test something for us here on Catalina?

@second-string
Copy link
Collaborator

second-string commented May 27, 2020

Yes absolutely! Don't have a V1 though, just an ST-LINK/V2 usb stick

@Nightwalker-87
Copy link
Member Author

Nightwalker-87 commented May 27, 2020

@dot4qu: Thx for raising your hand. That does not really matter for what I intend to ask for. In fact you should not need any hardware at all apart from a Mac with Catalina itself. The intention is to see if the driver for the legacy STLink-v1 installs correctly on macOS.

The task would be to:

  1. go through our /doc/compiling.md tutorial for macOS just up to the subsection "Building"
  2. do git checkout develop and then sudo make install
  3. continue with /stlinkv1_macos_driver/README (don't bother about step 4)

Note: You are able to roll back all changes to the original state later on (I may give some additional advice), so don't be afraid to loose track of any temporary changes to your system settings. I've gone through this on a 10.14 (Mojave) test system and would just like to see if we get the same results on the newer version.

@second-string
Copy link
Collaborator

You want me to checkout develop or macos_kext? The former isn't possible to run the install script on since it isn't merged.

Running sudo make install on both develop and macos_kext completes fine, but then running sudo sh install.sh from the stlinkv1_macos_driver dir fails. I tried it with and without SIP on, and it's the same failure both times:

xxxx@xxxxx-mbp stlinkv1_macos_driver 299 (macos_kext) $ sudo sh install.sh 
cp: /System/Library/Extensions/stlink_shield.kext: Read-only file system
cp: stlink_shield_10_15.kext: unable to copy extended attributes to /System/Library/Extensions/stlink_shield.kext: Read-only file system
cp: /System/Library/Extensions/stlink_shield.kext/Contents: No such file or directory
cp: stlink_shield_10_15.kext/Contents: unable to copy extended attributes to /System/Library/Extensions/stlink_shield.kext/Contents: No such file or directory
cp: /System/Library/Extensions/stlink_shield.kext/Contents/_CodeSignature: No such file or directory
cp: stlink_shield_10_15.kext/Contents/_CodeSignature: unable to copy extended attributes to /System/Library/Extensions/stlink_shield.kext/Contents/_CodeSignature: No such file or directory
cp: /System/Library/Extensions/stlink_shield.kext/Contents/_CodeSignature/CodeResources: No such file or directory
cp: /System/Library/Extensions/stlink_shield.kext/Contents/MacOS: No such file or directory
cp: stlink_shield_10_15.kext/Contents/MacOS: unable to copy extended attributes to /System/Library/Extensions/stlink_shield.kext/Contents/MacOS: No such file or directory
cp: /System/Library/Extensions/stlink_shield.kext/Contents/MacOS/stlink_shield_10_15: No such file or directory
cp: /System/Library/Extensions/stlink_shield.kext/Contents/Info.plist: No such file or directory
cp: /System/Library/Extensions/stlink_shield.kext/Contents/PkgInfo: No such file or directory
Requesting load of /System/Library/Extensions/stlink_shield.kext.
/System/Library/Extensions/stlink_shield.kext failed to load - (libkern/kext) not found; check the system/kernel logs for errors or try kextutil(8).
touch: /System/Library/Extensions: Read-only file system

@Nightwalker-87
Copy link
Member Author

Nightwalker-87 commented May 27, 2020

My request solely targeted the macos_kext branch. Install will not succeed with SIP enabled, that is well known, so one should focus on the alternative case. Let me think about the filesystem issue for a moment, that is interesting.

@Nightwalker-87
Copy link
Member Author

Nightwalker-87 commented May 27, 2020

This is the verification that an STLink-v1 (real HW) is recognised correctly on macOS 10.13 now:

MacBook-Pro-VM:stlink $USER$ /usr/local/bin/st-info --probe
setting new configuration (0 -> 1)
Found 1 stlink programmers
 serial:     303030303030303030303031
 hla-serial: "\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x31"
 flash:      131072 (pagesize: 1024)
 sram:       8192
 chipid:     0x0420
 descr:      F1xx Value Line

MacBook-Pro-VM:stlink $USER$ /usr/local/bin/st-flash erase
st-flash 1.6.0-347-g230497c
2020-05-28T00:02:06 INFO common.c: F1xx Value Line: 8 KiB SRAM, 128 KiB flash in at least 1 KiB pages.
Mass erasing

However there still is an issue with st-util causing the device to crash in such a way that a complete wipe with the official ST-LINK Utility seems the only option to recover it:

MacBook-Pro-VM:stlink $USER$ /usr/local/bin/st-util
st-util
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_VERSION
libusb: error [submit_bulk_transfer] bulk transfer failed (dir = Out): pipe is stalled (code = 0xe000404f)
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_VERSION
libusb: error [submit_bulk_transfer] bulk transfer failed (dir = Out): pipe is stalled (code = 0xe000404f)
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_CURRENT_MODE
libusb: error [submit_bulk_transfer] bulk transfer failed (dir = Out): pipe is stalled (code = 0xe000404f)
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_CURRENT_MODE
libusb: error [submit_bulk_transfer] bulk transfer failed (dir = Out): pipe is stalled (code = 0xe000404f)
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_ENTER
libusb: error [submit_bulk_transfer] bulk transfer failed (dir = Out): pipe is stalled (code = 0xe000404f)
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_RESETSYS
libusb: error [submit_bulk_transfer] bulk transfer failed (dir = Out): pipe is stalled (code = 0xe000404f)
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_READCOREID
2020-05-28T00:08:10 ERROR common.c: Failed to read core_id
libusb: error [submit_bulk_transfer] bulk transfer failed (dir = Out): pipe is stalled (code = 0xe000404f)
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_JTAG_READDEBUG_32BIT
2020-05-28T00:08:10 WARN common.c: Invalid flash type, please check device declaration
2020-05-28T00:08:10 ERROR gdb-server.c: Unsupported Target (Chip ID is 0000000000, Core ID is 0000000000).

MacBook-Pro-VM:stlink $USER$ /usr/local/bin/st-info --probe
libusb: warning [darwin_transfer_status] transfer error: timed out
[!] send_recv send request failed: LIBUSB_ERROR_TIMEOUT
[!] send_recv STLINK_GET_VERSION
libusb: error [submit_bulk_transfer] bulk transfer failed (dir = Out): pipe is stalled (code = 0xe000404f)
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_VERSION
libusb: error [submit_bulk_transfer] bulk transfer failed (dir = Out): pipe is stalled (code = 0xe000404f)
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_CURRENT_MODE
libusb: error [submit_bulk_transfer] bulk transfer failed (dir = Out): pipe is stalled (code = 0xe000404f)
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_GET_CURRENT_MODE
libusb: error [submit_bulk_transfer] bulk transfer failed (dir = Out): pipe is stalled (code = 0xe000404f)
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_ENTER
libusb: error [submit_bulk_transfer] bulk transfer failed (dir = Out): pipe is stalled (code = 0xe000404f)
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_RESETSYS
libusb: error [submit_bulk_transfer] bulk transfer failed (dir = Out): pipe is stalled (code = 0xe000404f)
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_DEBUG_READCOREID
libusb: error [submit_bulk_transfer] bulk transfer failed (dir = Out): pipe is stalled (code = 0xe000404f)
[!] send_recv send request failed: LIBUSB_ERROR_PIPE
[!] send_recv STLINK_JTAG_READDEBUG_32BIT
Found 1 stlink programmers
 serial:     553f6d06483f48534641213f
 hla-serial: "\x55\x3f\x6d\x06\x48\x3f\x48\x53\x46\x41\x21\x3f"
 flash:      0 (pagesize: 0)
 sram:       0
 chipid:     0x0000
 descr:      unknown device

... but that seems to be a non-related problem to me, as I have experienced this with this specific board on Debian as well. I'll open a new ticket for this to allow for further investigation.

@Nightwalker-87
Copy link
Member Author

Nightwalker-87 commented May 27, 2020

@dot4qu: The reason for the failures at your side is the read-only filesystem introduced for the system partition with Catalina. You can try sudo mount -uw / in terminal and retry. This should at least last until the next reboot. Please let me know if that is an option for you.

@second-string
Copy link
Collaborator

Requesting load of /System/Library/Extensions/stlink_shield.kext.
/System/Library/Extensions/stlink_shield.kext loaded successfully (or already loaded).

yep, looks like it's all good

@chenguokai
Copy link
Collaborator

chenguokai commented May 28, 2020

Kinda busy recently, sorry for the late response.

If the kext works well under /Library/Extensions, I would recommend using this path instead of S/L/E

@Nightwalker-87
Copy link
Member Author

@chenguokai: That's ok. Yes, I have been thinking about to try that yesterday as I read about this option recently. I'll give it a try. It may also solve the read-only filesystem issue in Catalina. The /S/L/E setting still derives from the old kext version. Looks like we can conclude testing soon then... 🎉

@Nightwalker-87
Copy link
Member Author

Nightwalker-87 commented May 28, 2020

@dot4qu: Thx for your feedback. Now you can do a first clean-up on your system:

sudo kextunload /System/Library/Extensions/stlink_shield.kext
sudo rm -R /System/Library/Extensions/stlink_shield.kext

This will cleanly remove the kext in /S/L/E again. I'll let you know as soon as we can continue.

@Nightwalker-87
Copy link
Member Author

Nightwalker-87 commented May 28, 2020

This is the verification that an STLink-v1 is recognised correctly on macOS 10.13 & 10.14:

MacBook-Pro-VM:stlink $USER$ sudo /usr/local/bin/st-info --probe
Password:
setting new configuration (0 -> 1)
Found 1 stlink programmers
 serial:     303030303030303030303031
 hla-serial: "\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x31"
 flash:      131072 (pagesize: 1024)
 sram:       8192
 chipid:     0x0420
 descr:      F1xx Value Line
MacBook-Pro-VM:stlink $USER$ sudo /usr/local/bin/st-flash erase
st-flash 1.6.0-348-g71011a3
2020-05-28T11:35:14 INFO common.c: F1xx Value Line: 8 KiB SRAM, 128 KiB flash in at least 1 KiB pages.
Mass erasing

Note: This is with the kext installed to /Library/Extensions.
Update: After testing on macOS 10.14, I obtain the same result for 10.13.

@Nightwalker-87
Copy link
Member Author

@dot4qu: After rebooting your system, you may now retry sudo sh install.sh with the latest macos_kext branch (check /stlinkv1_macos_driver/README again). With the recent change I expect the read-only problem to disappear. The last mentioned step can still be skipped at your side.

@Nightwalker-87
Copy link
Member Author

@chenguokai: The observed problem #964 (comment) vanishes again when the board is connected under reset (Reset button pressed). It does not seem to be a general problem (thus not necessary every time the board is connected), but recovers the onboard STM32F100RB, if it has run into this kind of frozen state.

@Nightwalker-87
Copy link
Member Author

Thx @chenguokai. So let's wait for @dot4qu 's feedback.
I'll merge straight away as soon as there is a positive result on 10.15 as well.

@second-string
Copy link
Collaborator

Yep, you're correct. Still the kext loading error as expected with SIP back enabled, but no read-only problems now.

/Library/Extensions/stlink_shield.kext failed to load - (libkern/kext) not loadable (reason unspecified); check the system/kernel logs for errors or try kextutil(8).

@Nightwalker-87
Copy link
Member Author

@dot4qu: That's good news. Thank you very much for testing.

Here are the instructions for rolling back everything on your macOS:

  1. kext:
sudo kextunload /Library/Extensions/stlink_shield.kext
sudo rm -R /Library/Extensions/stlink_shield.kext
  1. Reboot
  2. Recovery-Mode: Reactivate SIP via csrutil enable --> Reboot
  3. Go to your local stlink repository:
sudo make uninstall && sudo make clean
cd .. && sudo rm -R stlink && cd ..
  1. No further git repos present, if applicable:
    cd .. && sudo rm -R git

  2. a) Clean uninstall MacPorts, if desired:
    --> https://guide.macports.org/chunked/installing.macports.uninstalling.html

  3. b) Otherwise: Rollback of installed packages (git gcc9 llvm-9.0 cmake libusb gtk3) only:
    --> https://guide.macports.org/chunked/using.html

That should ensure there are no leftovers on your local machine.
Please let me know if you have any further questions.

@Nightwalker-87 Nightwalker-87 merged commit 1ae86f0 into develop May 28, 2020
@Nightwalker-87 Nightwalker-87 deleted the macos_kext branch May 28, 2020 17:05
@Nightwalker-87 Nightwalker-87 changed the title Updated stlink-v1 driver for macOS Updated STLink-v1 driver for macOS May 28, 2020
@stlink-org stlink-org locked as resolved and limited conversation to collaborators Jun 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[macOS] Support for ST-Link-v1 in macOS High Sierra? (Kernel Extension)
3 participants