UltimateHackingKeyboard / agent

Ultimate Hacking Keyboard configurator
https://ultimatehackingkeyboard.github.io/agent/
Other
702 stars 77 forks source link

blhost segfaults on Mac (original report) #718

Closed clarkema closed 6 years ago

clarkema commented 6 years ago

As the title, I'm trying to update my UHK to the latest firmware to see if that fixes an issue I'm having with booting. The keyboard is plugged directly into a USB A port on my Macbook Pro, with no other USB devices connected.

The update output is:

Start flashing firmware [22:07:43.801] [UhkHidDevice] Available devices unchanged [22:07:43.802] [UhkHidDevice] Used device: {"vendorId":7504,"productId":24866,"path":"IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/XHC1@14/XHC1@14000000/PRT2@14200000/Ultimate Hacking Keyboard@14200000/IOUSBHostInterface@0/IOUSBHostHIDDevice@14200000,0","serialNumber":"","manufacturer":"Ultimate Gadget Laboratories","product":"Ultimate Hacking Keyboard","release":257,"interface":-1,"usagePage":128,"usage":129}

[22:07:43.822] [UhkHidDevice] USB[R]: 00 00 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [22:07:43.823] [DeviceOperation] USB[T]: Read left module version information [22:07:43.823] [UhkHidDevice] USB[W]: 0e 01 00 [22:07:43.829] [UhkHidDevice] USB[R]: 00 01 04 00 00 00 00 00 08 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [22:07:43.830] [DeviceOperation] USB[T]: Read right module version information [22:07:43.830] [UhkHidDevice] USB[W]: 00 01 [22:07:43.837] [UhkHidDevice] USB[R]: 00 08 00 02 00 00 00 04 00 03 00 00 00 04 00 00 00 00 00 04 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [22:07:43.838] Device right firmware version: 8.2.0 [22:07:43.838] Device left firmware version: 8.2.0 [22:07:43.840] New firmware version: 8.2.5 [22:07:43.841] [UhkOperations] Operating system: Darwin 17.6.0 x64 [22:07:43.841] [UhkOperations] Start flashing right firmware [22:07:43.842] [UhkHidDevice] Start reenumeration, mode: Bootloader [22:07:43.954] [UhkHidDevice] USB[T]: Enumerate device. Mode: Bootloader [22:07:43.954] [UhkHidDevice] USB[W]: 01 00 88 13 00 00 [22:07:44.348] [UhkHidDevice] reenumeration devices up [22:07:44.349] [UhkHidDevice] Device communication closing. [22:07:44.349] [UhkHidDevice] Device communication closed. [22:07:44.350] [blhost] RUN: /Applications/UHK Agent.app/Contents/Resources/packages/blhost/mac/blhost --usb 0x1d50,0x6120 flash-security-disable 0403020108070605 [22:07:44.389] [blhost] EXIT_CODE: null [22:07:44.389] [blhost] FINISHED: null [22:07:44.631] [DeviceService] updateFirmware error { message: 'blhost error code:null', stack: 'Error: blhost error code:null\n at finish (/Applications/UHK Agent.app/Contents/Resources/app.asar/webpack:/uhk-usb/src/uhk-blhost.ts:53:35)\n at ChildProcess.childProcess.on.code (/Applications/UHK Agent.app/Contents/Resources/app.asar/webpack:/uhk-usb/src/uhk-blhost.ts:36:17)\n at emitTwo (events.js:125:13)\n at ChildProcess.emit (events.js:213:7)\n at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)' } [22:07:44.637] [UhkHidDevice] Available devices: [22:07:44.637] {"vendorId":1452,"productId":611,"path":"IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/EHC1@1D/EHC1@1d000000/PRT1@1d100000/IOUSBHostDevice@1d100000/AppleUSB20InternalIntelHub@1d100000/PRT8@1d180000/IOUSBHostDevice@1d180000/AppleUSB20InternalSMSCHub@1d180000/PRT2@1d182000/Apple Internal Keyboard / Trackpad@1d182000/Touchpad@1/AppleUSBMultitouchDriver@1d182000,1","serialNumber":"","manufacturer":"Apple Inc.","product":"Apple Internal Keyboard / Trackpad","release":546,"interface":-1,"usagePage":65280,"usage":1} [22:07:44.637] {"vendorId":1133,"productId":50732,"path":"IOService:/IOResources/ConnexionVirtual/ConnexionVirtualHID","serialNumber":"1","manufacturer":"3Dconnexion","product":"ConnexionHID","release":1,"interface":-1,"usagePage":65280,"usage":65280} [22:07:44.637] {"vendorId":1452,"productId":611,"path":"IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/EHC1@1D/EHC1@1d000000/PRT1@1d100000/IOUSBHostDevice@1d100000/AppleUSB20InternalIntelHub@1d100000/PRT8@1d180000/IOUSBHostDevice@1d180000/AppleUSB20InternalSMSCHub@1d180000/PRT2@1d182000/Apple Internal Keyboard / Trackpad@1d182000/Apple Internal Keyboard@0/AppleUSBTCKeyboard@1d182000,0","serialNumber":"","manufacturer":"Apple Inc.","product":"Apple Internal Keyboard / Trackpad","release":546,"interface":-1,"usagePage":1,"usage":6} [22:07:44.638] {"vendorId":1452,"productId":611,"path":"IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/EHC1@1D/EHC1@1d000000/PRT1@1d100000/IOUSBHostDevice@1d100000/AppleUSB20InternalIntelHub@1d100000/PRT8@1d180000/IOUSBHostDevice@1d180000/AppleUSB20InternalSMSCHub@1d180000/PRT2@1d182000/Apple Internal Keyboard / Trackpad@1d182000/Touchpad@2/AppleUSBTCButtons@1d182000,2","serialNumber":"","manufacturer":"Apple Inc.","product":"Apple Internal Keyboard / Trackpad","release":546,"interface":-1,"usagePage":1,"usage":2} [22:07:44.638] {"vendorId":7504,"productId":24864,"path":"IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/XHC1@14/XHC1@14000000/PRT2@14200000/UHK Bootloader@14200000/MCU HID GENERIC DEVICE@0/IOUSBHostHIDDevice@14200000,0","serialNumber":"","manufacturer":"Ultimate Gadget Laboratories","product":"UHK Bootloader","release":2,"interface":-1,"usagePage":65280,"usage":1} [22:07:44.638] {"vendorId":0,"productId":0,"path":"IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/SBUS@1F,3/AppleSMBusPCI/BUS0@0/AppleSMBusControllerICH/MKY0/AppleMikeyDriver/AppleMikeyHIDDriver","serialNumber":"","manufacturer":"","product":"Apple Mikey HID Driver","release":0,"interface":-1,"usagePage":12,"usage":1} [22:07:44.638] {"vendorId":5824,"productId":10203,"path":"IOService:/IOResources/org_pqrs_driver_Karabiner_VirtualHIDDevice_VirtualHIDRoot_v060800/org_pqrs_driver_Karabiner_VirtualHIDDevice_VirtualHIDRoot_UserClient_v060800/org_pqrs_driver_Karabiner_VirtualHIDDevice_VirtualHIDKeyboard_v060800","serialNumber":"pqrs.org:org_pqrs_driver_Karabiner_VirtualHIDDevice_VirtualHIDKeyboard_v060800","manufacturer":"pqrs.org","product":"Karabiner VirtualHIDKeyboard","release":0,"interface":-1,"usagePage":1,"usage":6} [22:07:44.639] [DeviceService] Read hardware modules information failed Error: [UhkHidDevice] Device is not connected at Promise (/Applications/UHK Agent.app/Contents/Resources/app.asar/webpack:/uhk-usb/dist/src/uhk-hid-device.js:92:1) at Promise () at UhkHidDevice. (/Applications/UHK Agent.app/Contents/Resources/app.asar/webpack:/uhk-usb/dist/src/uhk-hid-device.js:89:1) at Generator.next () at /Applications/UHK Agent.app/Contents/Resources/app.asar/webpack:/uhk-usb/dist/src/uhk-hid-device.js:7:1 at Promise () at __awaiter (/Applications/UHK Agent.app/Contents/Resources/app.asar/webpack:/uhk-usb/dist/src/uhk-hid-device.js:3:1) at UhkHidDevice.write (/Applications/UHK Agent.app/Contents/Resources/app.asar/webpack:/uhk-usb/dist/src/uhk-hid-device.js:88:1) at UhkHidDevice. (/Applications/UHK Agent.app/Contents/Resources/app.asar/webpack:/uhk-usb/dist/src/uhk-hid-device.js:134:1) at Generator.next ()

[22:07:44.640] [blhost] CLOSE_CODE: null [22:07:45.146] [DeviceService] Device connection state changed to: { bootloaderActive: true, connected: false, hasPermission: true } blhost error code:null

mondalaci commented 6 years ago

Can you try all the USB ports one by one?

clarkema commented 6 years ago

There's only one other USB port -- I've just tried that with exactly the same result.

mondalaci commented 6 years ago

You hit issue #681. The strange thing is that the Mac version of blhost worked on every Mac so far. Looks like we'll have to rebuild blhost on Mac too which will hopefully resolve your issue. I'll follow up about this.

kareltucek commented 6 years ago

Not so surprising if we assume that the included blhost was built on an older-than-average machine. It is logical that a newer CPU usually supports superset of features of an older CPU. (And that's it - by default (i.e., if march is not specified), gcc uses all features (i.e., instructions) of the CPU on which you build.)

Also, newer instructions are typically rather exotic instructions, so they will actually be used only on rare occasions. So the more likely an instruction is to cause the problem, the less likely it is to be actually present in the binary compiled with unrestricted instruction set.

mondalaci commented 6 years ago

@kareltucek Thanks for the insight!

@clarkema Given that only your Mac exhibits this issue, I'll actually need your help. First up, please consider this line of the firmware update log:

[22:07:44.350] [blhost] RUN: /Applications/UHK Agent.app/Contents/Resources/packages/blhost/mac/blhost --usb 0x1d50,0x6120 flash-security-disable 0403020108070605

Here you can see where blhost is located. Please execute blhost and paste its output. It should segfault.

clarkema commented 6 years ago

@mondalaci Thanks — I'm happy to run whatever tests are helpful. It does indeed segfault.

$ /Applications/UHK\ Agent.app/Contents/Resources/packages/blhost/mac/blhost --usb 0x1d50,0x6120 flash-security-disable 0403020108070605 zsh: segmentation fault /Applications/UHK\ Agent.app/Contents/Resources/packages/blhost/mac/blhost

mondalaci commented 6 years ago

Thanks for your help! Let's try to rebuild blhost, so that it won't segfault on OSX anymore. Please run the following:

git clone https://github.com/UltimateHackingKeyboard/bootloader.git
cd bootloader/validation/blhost/gcc
make
Release/blhost

The build may fail on your system. Please paste the output and let's move on from there.

clarkema commented 6 years ago

5028 bootloader/validation/blhost/gcc:master> make
Compiling src/blfwk/src/Blob.cpp Compiling src/blfwk/src/Bootloader.cpp Compiling src/blfwk/src/BusPal.cpp Compiling src/blfwk/src/BusPalPeripheral.cpp Compiling src/blfwk/src/Command.cpp Compiling src/blfwk/src/DataSource.cpp Compiling src/blfwk/src/DataSourceImager.cpp Compiling src/blfwk/src/DataTarget.cpp Compiling src/blfwk/src/ELFSourceFile.cpp Compiling src/blfwk/src/ExcludesListMatcher.cpp Compiling src/blfwk/src/GHSSecInfo.cpp Compiling src/blfwk/src/GlobMatcher.cpp Compiling src/blfwk/src/IntelHexSourceFile.cpp Compiling src/blfwk/src/Logging.cpp Compiling src/blfwk/src/SBSourceFile.cpp Compiling src/blfwk/src/SRecordSourceFile.cpp Compiling src/blfwk/src/SearchPath.cpp Compiling src/blfwk/src/SerialPacketizer.cpp Compiling src/blfwk/src/SourceFile.cpp Compiling src/blfwk/src/StELFFile.cpp Compiling src/blfwk/src/StExecutableImage.cpp Compiling src/blfwk/src/StIntelHexFile.cpp Compiling src/blfwk/src/StSRecordFile.cpp Compiling src/blfwk/src/UartPeripheral.cpp Compiling src/blfwk/src/Updater.cpp Compiling src/blfwk/src/UsbHidPacketizer.cpp Compiling src/blfwk/src/UsbHidPeripheral.cpp Compiling src/blfwk/src/Value.cpp Compiling src/blfwk/src/format_string.cpp Compiling src/blfwk/src/hid-linux.c /Users/clarkema/git/bootloader/src/blfwk/src/hid-linux.c:41:10: fatal error: 'linux/hidraw.h' file not found

include <linux/hidraw.h>

     ^~~~~~~~~~~~~~~~

1 error generated. make: *** [/Users/clarkema/git/bootloader/validation/blhost/gcc/Release/obj/src/blfwk/src/hid-linux.o] Error 1

mondalaci commented 6 years ago

Any ideas, @iprok?

mondalaci commented 6 years ago

I'm just realizing that the makefile was hardly meant for OSX. There's an Xcode project in validation/blhost.xcodeproj. Can you build it? If so, what happens when you execute the built blhost binary?

In any case, in order to make the resulting binary work on all OSX versions, the build options should be modified to make blhost statically linked and not use special instructions. Just like https://github.com/UltimateHackingKeyboard/bootloader/commit/85892581f7568b7831376de21f385913485ea24f but for OSX.

iprok commented 6 years ago

I have mac, I can test something on it, but I'm completely unfamiliar with compilation for OSX. Sorry.

clarkema commented 6 years ago

@iprok Likewise -- I have the XCode toolchain installed, but I'm not really an OS X developer, so I'm not familiar with it at all. I have managed to build a version of blhost using it (without changing any options) that runs without segfaulting and just gives me some usage help -- I'm not sure where to go from there in terms of either testing or flashing my board.

mondalaci commented 6 years ago

@clarkema Would you attach your compiled blhost binary here?

clarkema commented 6 years ago

Attached.

blhost.gz

mondalaci commented 6 years ago

Thanks! Now try to update the firmware again. It will fail, but you'll see a line like

[22:07:44.350] [blhost] RUN: /Applications/UHK Agent.app/Contents/Resources/packages/blhost/mac/blhost --usb 0x1d50,0x6120 flash-security-disable 0403020108070605

in the firmware update log which contains the path of blhost which is /Applications/UHK Agent.app/Contents/Resources/packages/blhost/mac/blhost in this example. Now overwrite blhost with your version and retry the firmware update in Agent.

Please let me know how it works.

clarkema commented 6 years ago

Still segfaults I'm afraid, both when I copy my blhost into the bundle and when I run it directly as ./blhost --usb 0x1d50,0x6120 flash-security-disable 0403020108070605

mondalaci commented 6 years ago

Gotcha. No worries, I'll build a blhost binary for Mac, or if I fail miserably, I'll ask somebody.

mondalaci commented 6 years ago

I'm closing this issue in favor of #747 which summarizes the issue, making it easier for people to help solving it.