ClockSelect / myevic

This is myevic Custom Firmware.
GNU General Public License v3.0
299 stars 101 forks source link

Primo support #328

Closed MicroSur closed 6 years ago

MicroSur commented 7 years ago

I`m newbie in C programming but like open source myevic project. I try to support the primo mod (1 and 2), but I need tests and fixes from professionals.

Take a look at https://github.com/MicroSur/sur_myevic

fOmey commented 7 years ago

Have you actually tested this on a primo ?

I'm finding your commits a little hard to follow, try leaving detailed comments for changes. Looking at someone else's code and trying to understand reasoning/logic tends to be very difficult.

I'm very interested in the reasoning for the following in "megpio.c", are these educated guesses or are you confident with the current configuration:

        if ( ISPRIMO1 || ISPRIMO2 )
    {
            //?
                //SYS->GPD_MFPL &= ~SYS_GPD_MFPL_PD0MFP_Msk;
        //SYS->GPD_MFPL |= SYS_GPD_MFPL_PD0MFP_GPIO;
        PD1 = 0;
        GPIO_SetMode( PD, GPIO_PIN_PIN1_Msk, GPIO_MODE_OUTPUT );
}
    if ( ISRX300 || ISPRIMO1 || ISPRIMO2 )
    {
        SYS->GPD_MFPL &= ~(SYS_GPD_MFPL_PD0MFP_Msk|SYS_GPD_MFPL_PD1MFP_Msk);
        SYS->GPD_MFPL |= SYS_GPD_MFPL_PD0MFP_GPIO|SYS_GPD_MFPL_PD1MFP_GPIO;
}
        else if ( ISPRIMO1 || ISPRIMO2 )
        {
        PA3 = 0;
        GPIO_SetMode( PA, GPIO_PIN_PIN3_Msk, GPIO_MODE_OUTPUT );
        PA2 = 0;
        GPIO_SetMode( PA, GPIO_PIN_PIN2_Msk, GPIO_MODE_OUTPUT );            
}
    else if ( !ISCUBOID && !ISCUBO200 && !ISRX200S && !ISRX23 && !ISRX300 && !ISPRIMO1 && !ISPRIMO2 )
    {
        GPIO_SetMode( PD, GPIO_PIN_PIN7_Msk, GPIO_MODE_INPUT );
        GPIO_EnableInt( PD, 7, GPIO_INT_RISING );
        GPIO_ENABLE_DEBOUNCE( PD, GPIO_PIN_PIN7_Msk );
}

I own a primo mini and was considering to start working on support, so it's interesting timing that you posted this.. although I must admit my motivation has been a little slack..

MicroSur commented 7 years ago

I have a Primo v1 and it works. I'm looking for a similar code in the firmware for already supported mods. Marked with a question mark - I'm not sure ... It's a hobby for me.

fOmey commented 7 years ago

Ah right, I also have some questions.. I was hoping you would be able to answer.

I am trying to figure out what PA2, PA3 etc. is used for..

MicroSur commented 7 years ago

pins to the batteries...

fOmey commented 7 years ago

Sure, although how do we identify what pins are used for what.. I'm worried if I declare wrong pins I'll burn out chip you know..

On 4 Jul. 2017 8:33 pm, "Alexander" notifications@github.com wrote:

pins to the batteries...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ClockSelect/myevic/issues/328#issuecomment-312844675, or mute the thread https://github.com/notifications/unsubscribe-auth/AE0UqQEf8EFhzEzzyajfiy3f9muw1nzzks5sKhT1gaJpZM4OMpHD .

MicroSur commented 7 years ago

Primo mini InitGPIO code from firmware does not differ from the VTwo mini, except of this

    if ( ISRX300 || ISPRIMO1 || ISPRIMO2 || ISPRIMOmini )
    {
        SYS->GPD_MFPL &= ~(SYS_GPD_MFPL_PD0MFP_Msk|SYS_GPD_MFPL_PD1MFP_Msk);
        SYS->GPD_MFPL |= SYS_GPD_MFPL_PD0MFP_GPIO|SYS_GPD_MFPL_PD1MFP_GPIO;
    }
fOmey commented 7 years ago

Right, how did you figure that tho ? I'm still trying to wrap my head around how you figured out battery pins for example.. process of elimination ? Copy and paste current code RX code ? Reverse stock firmware ? Can you explain how you did it ?

I'm trying to understand how to expand device compatibility, I'll be honest I'm a little lost.. I don't understand how ClockSelect figured out how to declare these pins as output etc. I don't want to have to rely on existing code to get the job done you know ?

I hate looking at code I don't entirely understand.. I especially don't want to be guessing my way through battery pin declaration code either.

Does that make sense or am I being to worrisome ? haha..

MicroSur commented 7 years ago

Reverse stock firmware of course. With IDA Pro and understanding ARM assembler code. Do You know how to do this?

fOmey commented 7 years ago

I have no experience with ARM, however I have some experience with PowerPC from my PS3 modding days.. I would like to pick your brain and have a proper conversation about this..

If you are willing to give me some guidance would be appreciated.. do you use discord by any chance ?

Join discord chat: https://discord.gg/Ajw5vt6

On 5 Jul. 2017 3:32 pm, "Alexander" notifications@github.com wrote:

Reverse stock firmware of course. With IDA Pro and understanding ARM assembler code. Do You know how to do this?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ClockSelect/myevic/issues/328#issuecomment-313000184, or mute the thread https://github.com/notifications/unsubscribe-auth/AE0UqfoQliV0uUl5TevjZEDbmrTI_wz6ks5sKx_ygaJpZM4OMpHD .

MicroSur commented 7 years ago

Chat with google translate... no thank you ) My native language is russian.

I've been trying to learn ARM for more than a year and a half... Install IDA (I have v.6.6...), try to load stock firmware, then may be I can help... https://i.imgur.com/iLhlGJB.jpg

fOmey commented 7 years ago

Fair enough.. This is what has been troubling me: capture

As per this, I believe I am correct:

    ROM (rx)  : ORIGIN = 0x00000000, LENGTH = 128K
    RAM (rwx) : ORIGIN = 0x20000000, LENGTH =  32K

Also is there any chance firmware can be obfusicated ? If so what are you using to de-obfusicate ?

I think we should document this process properly to attract more developers to this project.. there is very little information on this subject on google.

MicroSur commented 7 years ago

I just press Ok without any changes here.

These are my working files with function names and some comments, it can be useful in learning: ida_idb

fOmey commented 7 years ago

This is great, thank you very much. This will help alot, now I can see where I am going wrong.

I just downloaded evic primo mini software from joyetech website and compared the hex to your's and noticed its definately different, do joyetech encrypt their firmware ? If so how are you decrypting ?

MicroSur commented 7 years ago

You must decrypt joyetech firmware of course. I thought you knew this... Use my FWUpdater or NFE to do this first. My software here

fOmey commented 7 years ago

I had a feeling it was obfusicated, Now everything has become clear.. thank you.

Haha you must pardon my ignorance, I only started attempting to reverse firmware when I replied to this thread.. so I am learning as I go along.

Thank you for your help.