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

Compile with 10.11 sdk #78

Closed
Wouter1 opened this issue Jun 6, 2016 · 74 comments
Closed

Compile with 10.11 sdk #78

Wouter1 opened this issue Jun 6, 2016 · 74 comments

Comments

@Wouter1
Copy link
Owner

Wouter1 commented Jun 6, 2016

Maybe the code can work again properly with low latency if we compile against the 10.11 SDK

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 6, 2016

I worked a bit on this already in #70

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 6, 2016

Plan is to keep code compilable on XCode 5 as it was, with SDK 10.9 and deploy target 10.9

But to also make it compilable with XCode 7 using SDK 10.11 and deploy target 10.11

The idea is to make adapters for several classes in 10.11, so that I do not have to modify the main bulk of the code. 10.9 does not need the adapters but in 10.11 the driver calls would be rerouted through the adapters that map the old 10.9 calls into the new 10.11 calls

So far for the rough plan. The details will have some problems, I can not really see how far and rough that will get.

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 6, 2016

I put in adapters for IOUSBPipe, IOUSBDevice, IOUSBInterface, IOUSBController,

and a bunch of structures in USB.h: IOUSBIsocFrame, IOUSBLowLatencyIsocFrame, IOUSBLowLatencyIsocCompletionAction, IOUSBLowLatencyIsocCompletion, IOUSBEndpointDescriptor, IOUSBConfigurationDescriptor, IOUSBCompletionAction, IOUSBIsocCompletionAction, IOUSBIsocCompletion, IOUSBCompletion, IOUSBDevRequest, IOUSBDevRequestDesc

This long list in USB.h might become the most troublesome part, as these are raw structures where the first ones are more or less function-based objects.

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 7, 2016

guessing the new versions of old structures

old new
IOUSBLowLatencyIsocFrame IOUSBHostIsochronousFrame
IOUSBLowLatencyIsocCompletion IOUSBHostIsochronousCompletion
IOUSBLowLatencyIsocCompletionAction IOUSBHostIsochronousCompletionAction

It looks like in general the USB.h file has been replaced with IOUSBHostIOSource.h

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 7, 2016

These structures look comparable but have slight differences.

Eg

struct IOUSBLowLatencyIsocFrame {
    IOReturn                        frStatus;
    UInt16                          frReqCount;
    UInt16                          frActCount;
    AbsoluteTime            frTimeStamp;
};

versus

struct IOUSBHostIsochronousFrame
{
    IOReturn     status;
    uint32_t     requestCount;
    uint32_t     completeCount;
    AbsoluteTime timeStamp;
};

@lofiatunes
Copy link

Big thx Man! good news in morning)
am on Yosmite(last upd) and its works great for me. am a guitar player a long time and my EMU0404 USB is my friend from 2004) many years playing in many clubs in russia and nothing cant stop my EMU.
I want to say THANK YOU!!! for Your job for us.
cheers)

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 8, 2016

@digdelu thanks! On Yosemite the driver indeed was already working fine. This ticket is a working ticket for me to get it compile on El Capitan, in an attempt to get the low-latency connection back with El Capitan.

Wouter1 added a commit that referenced this issue Jun 13, 2016
Wouter1 added a commit that referenced this issue Jun 13, 2016
Wouter1 added a commit that referenced this issue Jun 13, 2016
Wouter1 added a commit that referenced this issue Jun 13, 2016
Wouter1 added a commit that referenced this issue Jun 13, 2016
Wouter1 added a commit that referenced this issue Jun 13, 2016
Wouter1 added a commit that referenced this issue Jun 13, 2016
Wouter1 added a commit that referenced this issue Jun 13, 2016
Wouter1 added a commit that referenced this issue Jun 13, 2016
@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 14, 2016

apple changed the low latency 'busy' status from kUSBLowLatencyIsochTransferKey ('llit') to kIOReturnInvalid. It would not surprise me if this were the heart of the problem

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 14, 2016

Trying to find substitute for IOUSBInterface#getInterfaceStringIndex()

Checking Apple's source code

http://opensource.apple.com//source/IOUSBFamily/IOUSBFamily-205.3.5/IOUSBFamily/Classes/IOUSBInterface.cpp

where I see

UInt8  
IOUSBInterface::GetInterfaceStringIndex() 
{ 
    return _iInterface; 
}
    _iInterface = _interfaceDesc->iInterface;

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 14, 2016

s

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 14, 2016

mBus in EMUUSBAudioDevice was not even used. Removed.

Wouter1 added a commit that referenced this issue Jun 14, 2016
Wouter1 added a commit that referenced this issue Jun 16, 2016
@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 16, 2016

Trouble replacing FindNextPipe was in IOUSBInterface but not in USBHostInterface.
In IOUSBHostInterface it says

// Replacement: getInterfaceDescriptor and StandardUSB::getNextAssociatedDescriptorWithType to find an endpoint descriptor,
// then use copyPipe to retrieve the pipe object

which is too vague to use directly

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 16, 2016

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 16, 2016

the old struct specifying the required pipe properties was this

typedef struct {
    UInt8 type;
    UInt8 direction;
    UInt16 maxPacketSize;
    UInt8 interval;
} IOUSBFindEndpointRequest;

The suggested getNextEndpointDescriptor takes

    struct ConfigurationDescriptor
    {
        uint8_t     bLength;
        uint8_t     bDescriptorType;
        uint16_t    wTotalLength;
        uint8_t     bNumInterfaces;
        uint8_t     bConfigurationValue;
        uint8_t     iConfiguration;
        uint8_t     bmAttributes;
        uint8_t     bMaxPower;
    }

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 16, 2016

This is the source code of the old FindNextPipe

http://opensource.apple.com//source/IOUSBFamily/IOUSBFamily-210.4.5/IOUSBFamily/Classes/IOUSBInterface.cpp



IOUSBPipe*
IOUSBInterface::FindNextPipe(IOUSBPipe *current,
                                IOUSBFindEndpointRequest *request)
{
    const IOUSBController::Endpoint *   endpoint;
    IOUSBPipe *             pipe;
    int                 numEndpoints;
    int                 i;

    numEndpoints = _bNumEndpoints;

    if (request == 0)
        return NULL;

    if(current != 0) 
    {
        for(i=0;i < numEndpoints; i++) 
        {
            if(_pipeList[i] == current) 
            {
        i++; // Skip the one we just did
                break;
            }
    }
    }
    else
        i = 0;  // Start at beginning.

    for ( ;i < numEndpoints; i++) {
        pipe = _pipeList[i];
        if(!pipe)
            continue;
        endpoint = pipe->GetEndpoint();

        // check the request parameters
        if (request->type != kUSBAnyType &&
            request->type != endpoint->transferType)
            pipe = 0;       // this is not it
        else if (request->direction != kUSBAnyDirn &&
            request->direction != endpoint->direction)
            pipe = 0;       // this is not it

        if (pipe == 0)
            continue;

        request->type = endpoint->transferType;
        request->direction = endpoint->direction;
        request->maxPacketSize = endpoint->maxPacketSize;
        request->interval = endpoint->interval;
        return(pipe);
    }

    return(0);
}

@Wouter1 Wouter1 closed this as completed Jun 16, 2016
@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 30, 2016

Just guessed that the lib would have the name com.apple.kpi.vfs with version 13.4 minimum

However that doesn't work

EMUUSBAudio.kext - dependency 'com.apple.kpi.vfs' not found.

    No kexts found for these libraries: 
        com.apple.kpi.vfs

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 30, 2016

And I probably now need to link against IOUSBHostFamily, not IOUSBFamily, in the same plist OSBundleLibraries.

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 30, 2016

Mmm, that gives

EMUUSBAudio.kext - no compatible dependency found for com.apple.iokit.IOUSBHostFamily.

...
    Only incompatible kexts found for these libraries: 
        com.apple.iokit.IOUSBHostFamily

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 30, 2016

kextstat gives a list of the actually loaded kexts, with version nrs

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 30, 2016

IOUSBHostFamil has version 1.0.1. Maybe that's why it didn't load

   38   13 0xffffff7f814af000 0x69000    0x69000    com.apple.iokit.IOUSBHostFamily (1.0.1) 4C8B5BB6-6AE4-313E-B79C-AC07A4E31A2D <37 7 5 4 3 1>
   39    5 0xffffff7f81555000 0x9a000    0x9a000    com.apple.iokit.IOUSBFamily (900.4.1) 7B5AC81A-D0B6-3F3D-87C7-AFD78F4686DB <38 12 7 5 4 3 1>

@Wouter1
Copy link
Owner Author

Wouter1 commented Jun 30, 2016

That gives me

kxld[com.emu.driver.EMUUSBAudio]:   IOUSBDevice::metaClass
kxld[com.emu.driver.EMUUSBAudio]:   IOUSBInterface::metaClass

But the other errs are now gone. Maybe this is the right track and that I have some refs, or implemented some stub incorrectly

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

There is a ref to IOUSBInterface in the plist. Maybe that should be IOUSBHostDevice on 10.11

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

Trying to figure out where the IOUSBDevice reference comes from

Using nm I see these refs in this order

000000000002eee0 s __ZL11kDB_To_Gain
0000000000011680 t __ZN10Completion3setEPvPFvS0_S0_ijES0_
0000000000023ef0 T __ZN10StreamInfo14getNextFrameNrEv
0000000000023d50 T __ZN10StreamInfo4initEv
0000000000023e30 T __ZN10StreamInfo5resetEv
0000000000023d70 T __ZN10StreamInfo5startEy
                 U __ZN11IOUSBDevice9metaClassE
                 U __ZN11OSMetaClass21_RESERVEDOSMetaClass0Ev
                 U __ZN11OSMetaClass21_RESERVEDOSMetaClass1Ev
                 U __ZN11OSMetaClass21_RESERVEDOSMetaClass2Ev
                 U __ZN11OSMetaClass21_RESERVEDOSMetaClass3Ev
                 U __ZN11OSMetaClass21_RESERVEDOSMetaClass4Ev
                 U __ZN11OSMetaClass21_RESERVEDOSMetaClass5Ev
                 U __ZN11OSMetaClass21_RESERVEDOSMetaClass6Ev
                 U __ZN11OSMetaClass21_RESERVEDOSMetaClass7Ev
                 U __ZN11OSMetaClassC2EPKcPKS_j
                 U __ZN11OSMetaClassD2Ev
0000000000002820 t __ZN11OSMetaClassdlEPvm
0000000000023d00 t __ZN11OSMetaClassdlEPvm
0000000000024eb0 t __ZN11OSMetaClassdlEPvm
000000000000f980 t __ZN11OSMetaClassdlEPvm
00000000000246e0 t __ZN11OSMetaClassdlEPvm
0000000000006f10 t __ZN11OSMetaClassdlEPvm
000000000001a260 t __ZN11OSMetaClassdlEPvm
0000000000023650 t __ZN11RingBufferTIhEC2Ev
00000000000236d0 t __ZN11RingBufferTIjEC2Ev
0000000000012110 t __ZN12IOUSBDevice111isHighSpeedEv
0000000000019df0 t __ZN12IOUSBDevice114getFrameNumberEv

The StreamInfo refs probably come from StreamInfo.cpp

The next thing I recognise in the names is the IOUSBDevice1 code.

Could it be that the ending on "1" confuses the linker ?

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

StreamInfo code in start could be generalized with

ReturnIf(startUsbFrame < streamInterface->getDevice1()->getFrameNumber() + 10, kIOReturnTimeout);

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

Seems I screwed up something, 10.11 does not compile anymore.
The errors come from utfconv.h, this is a systme file?!?!?

Seems XCode damaged the file, the modification time is today. All other files are from 27 aug 2015

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

Thanks to the open source on

http://opensource.apple.com//source/xnu/xnu-3248.20.55/bsd/sys/utfconv.h?txt

I could figure out that 'utf8_encodestr' had been erased in my file, leaving jjust a list of parameters ....

I dont understand why these files are writable. Will try to change that...

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

When I compile for 10.9 and run kextutil -n I get a few warnings:

Warnings: 
    Dependency lacks appropriate value for OSBundleRequired and may not be availalble during early boot: 
        com.apple.kec.Libm - OSBundleRequired not set
        com.apple.vecLib.kext - OSBundleRequired not set
        com.apple.iokit.IOAudioFamily - OSBundleRequired not set

I should fix those

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

The above warnings do not occur in 10.9. Must be that 10.11 has stricter check.

on 10.9, there are these kext's

  112    3 0xffffff7f81e27000 0x2f000    0x2f000    com.apple.iokit.IOAudioFamily (1.9.7fc2) <111 5 4 3 1>
  113    1 0xffffff7f825db000 0x2f000    0x2f000    com.apple.vecLib.kext (1.0.0) <6 5 4 3>

There IS NO Libm.

Additionally, IOAudioFamily IS ALREADY requested, as version 1.9.7f2.

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

I added vecLib to the OSBundleLibraries but still get the same error.

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/KEXTConcept/Articles/infoplist_keys.html#//apple_ref/doc/uid/TP40009481-SW2

OSBundleRequired is a separate element for the plist, which is not there currently.

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

The OSBundleRequired property informs the system that your kext must be available for loading during early boot. Kexts that don’t set this property can’t load during early boot. You can specify one of the following values for this property:

This driver is not needed during early boot. Not sure why the warnings are there but we probably can ignore them...

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

If I only change in OSBundleLibraries the IOUSBFamily to IOUSBHostFamily, I get only these errors

kxld[com.emu.driver.EMUUSBAudio]: The following symbols are unresolved for this kext:
kxld[com.emu.driver.EMUUSBAudio]:   IOUSBPipe::Write(IOMemoryDescriptor*, unsigned long long, unsigned int, LowLatencyIsocFrame*, LowLatencyCompletion*, unsigned int)
kxld[com.emu.driver.EMUUSBAudio]:   _utf8_encodestr

Strange, the other errors ::metaClass are now gone

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

Changed all occurences of IOUSBPipe to USBPipe just to be sure

The problem with the linker complaint about Write stays. Strange that the compiler doesn't complain

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

The problem is that the Write function is declared but not implemented.

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

IOUSBHostPipe#io is replacing both read and write! I guess buffer->getDirection determines if it's read or write, but I could not find this documented.

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

I need to find some solution for that plist. Having both this in the OSBundleLibraries

com.apple.iokit.IOUSBFamily 683.4

and

|com.apple.iokit.IOUSBHostFamily | 1.0.1 |

is not an option.

Hacking it in every time you compile for 10.11 is not nice either.

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

Only remaining problem loading the kext is this

kxld[com.emu.driver.EMUUSBAudio]: The following symbols are unresolved for this kext:
kxld[com.emu.driver.EMUUSBAudio]:   _utf8_encodestr

Wouter1 added a commit that referenced this issue Jul 1, 2016
@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

After some trial and error, the utf8_encodestr appears to be in the

com.apple.kpi.bsd

version 15.4.0 works but maybe I should use lower version nr in final version.

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

The kext now is installing properly. Added a 2nd plist for 10.11

@Wouter1
Copy link
Owner Author

Wouter1 commented Jul 1, 2016

Compilation works, the driver loads. It doesn't work but I made a new ticket for that #80. Closing this

@Wouter1 Wouter1 closed this as completed Jul 1, 2016
Repository owner locked and limited conversation to collaborators Oct 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants