Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: DJ Omnimaga on May 12, 2010, 11:10:13 pm

Title: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: DJ Omnimaga on May 12, 2010, 11:10:13 pm
Ok, since SirCmpwn cannot visit any TI site until Summer 2011, I am relaying his request for him:

He would like to ask if someone has a routine to lock/unlock flash memory? He also wants to know which pages would this affect?
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: _player1537 on May 12, 2010, 11:14:16 pm
maybe ask brandon for one, I know he has used it.  But he says it is pretty dangerous iirc
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: Galandros on May 13, 2010, 05:19:45 am
This has been questioned and answered in some UTI topics. mapar007 should have one routine for that and calcmaniac84 probably will (for his TI-Boy SE).

I know he can not visit the TI forums but we can save the pages and send to him. Or see WikiTI ports documentation, I have saw there code to unlock flash.
And Brandon Wilson has the most up to date method to unlock flash (if there is some bcall we can use or details in the instructions to unlock flash) and even knows details in the emulated TI-84+ SE in a Nspire unlock flash.
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: mapar007 on May 13, 2010, 06:11:22 am
I'll do my duty, then :P

The 'universal exploit' that works on all OS versions. (c) Brandon Wilson

Code: [Select]

UnlockFlash:
;Unlocks Flash protection.
;Destroys: appBackUpScreen
;          pagedCount
;          pagedGetPtr
;          arcInfo
;          iMathPtr5
;          pagedBuf
;          ramCode
        in a,(6)
        push af
        ld a,7Bh
        call translatePage
        out (6),a
        ld hl,5092h
        ld e,(hl)
        inc hl
        ld d,(hl)
        inc hl
        ld a,(hl)
        call translatePage
        out (6),a
        ex de,hl
        ld a,0CCh
        ld bc,0FFFFh
        cpir
        ld e,(hl)
        inc hl
        ld d,(hl)
        push de
        pop ix
        ld hl,9898h
        ld (hl),0C3h
        inc hl
        ld (hl),returnPoint & 11111111b
        inc hl
        ld (hl),returnPoint >> 8
        ld hl,pagedBuf
        ld (hl),98h
        ld de,pagedBuf+1
        ld bc,49
        ldir
        ld (iMathPtr5),sp
        ld hl,(iMathPtr5)
        ld de,9A00h
        ld bc,50
        ldir  
        ld de,(iMathPtr5)
        ld hl,-12
        add hl,de
        ld (iMathPtr5),hl
        ld iy,0056h-25h
        ld a,50
        ld (pagedCount),a
        ld a,8
        ld (arcInfo),a
        jp (ix)
translatePage:
        ld b,a
        in a,(2)
        and 80h
        jr z,_is83P
        in a,(21h)
        and 3
        ld a,b
        ret nz
        and 3Fh
        ret
_is83P: ld a,b
        and 1Fh
        ret
returnPoint:
        ld iy,flags
        ld hl,(iMathPtr5)
        ld de,12
        add hl,de
        ld sp,hl
        ex de,hl
        ld hl,9A00h
        ld bc,50
        ldir
        pop af
        out (6),a
        ret

EDIT:

To answer the second question: unlocking flash enables writing on all pages of the Flash memory (except the boot code, of course), and additionally grants access to the certificate page (7Eh).
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: DJ Omnimaga on May 13, 2010, 09:41:36 am
OOOH RIGHT! The last part is the one that can be the most dangerous. I think this is what Brandon talked about. When unlocking flash, be VERY careful to not overwrite the certificate, otherwise, big "OOPS".
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: mapar007 on May 13, 2010, 10:00:32 am
Yup. But it's hard to do that unintentionally. Brandon screwed up his calc while he was modifying the certificate on purpose, but he messed up endianness and the whole thing failed. => calc bricked (needs 1337 brandon wizardry to unlock :P )
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: SirCmpwn on May 13, 2010, 03:35:06 pm
Thanks for the help, but I was hoping for the routine in hex. ;)
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: calc84maniac on May 13, 2010, 04:05:18 pm
What are you going to do with it?
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: DJ Omnimaga on May 13, 2010, 04:28:20 pm
Thanks for the help, but I was hoping for the routine in hex. ;)
A SirCmpwn drew near? o.o
/me hopes he can find easy ways to get on in the future.

He is working on some project that isn't a game but I think it's secret so I can't tell much.

He just need to be VERY careful with that Flash unlocking routine. He should really test on a computer first if he can.
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: calcdude84se on May 13, 2010, 05:09:00 pm
Spoiler For Spoiler:
I can't think of any reason why you'd need to directly write to flash from a user program...
Only an OS should need to do that, in which case you don't need to bother with a hack, since it's your OS.
The only reason for which it could be needed is if you need to create an app directly on-calc. But to do that, you'd have to mess w/the certificate too, and that is just a very bad idea.
Anybody have a better guess?
Edit: Apparently what is above can be construed as rude and careless. I have apologized below. I still feel bad... :(
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: DJ Omnimaga on May 13, 2010, 05:27:48 pm
I would say why he might need that, but I don't know if I am allowed to do it. I would need his permission first.

I personally do not like when people say things like "why do you need that?" or "why do you want to do that?" when someone asks for a routine or programming help, because it sounds like it implies any use of it would be pointless or that his idea makes no sense or something, while in fact, the programmer may have something special in mind. Why prevent someone from doing something he wants? Plus he might want to keep his ideas secret until he's certain it will work out, anyway.

If everyone cancelled their help requests everytime they got told that in the past, half of the POTY poll choices on ticalc would never have happened. Illusiat 13 would have never been possible, same for Metroid II (the first person to ever want to write a XCOPY/Resource style routine and asked help for it was hit by that question in the past).

All he needs to make sure is to be careful to what he does with the help people provides him.

Let's not get into a "MaxCoderz 2003-04" mentality here
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: calcdude84se on May 13, 2010, 05:39:31 pm
I was just curious, I'm sorry... :( If I put a damper on anybody's attempts, for goodness's sake, please tell me to stop.
I apologize for anything I may have done. Let me delete that post...
(meh, I feel bad now.)
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: Galandros on May 13, 2010, 05:41:23 pm
I can't think of any reason why you'd need to directly write to flash from a user program...
Only an OS should need to do that, in which case you don't need to bother with a hack, since it's your OS.
The only reason for which it could be needed is if you need to create an app directly on-calc. But to do that, you'd have to mess w/the certificate too, and that is just a very bad idea.
Anybody have a better guess?
Flash unlocking is unusual unless you are writing an OS or patching something.
But he might want only to experiment something, nothing more.

I personally do not like when people say things like "why do you need that?" or "why do you want to do that?" when someone asks for a routine or programming help, because it sounds like it implies any use of it would be pointless or that his idea makes no sense or something, while in fact, the programmer may have something special in mind. Why prevent someone from doing something he wants?
You are right. But sometimes asking why can help can be to give better help or support, not this case, though.
calcdude84se is intrigued and maybe curious. I am curious, too, but I will simply wait for SirCmpwn. :P
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: DJ Omnimaga on May 13, 2010, 05:46:08 pm
Well the issue is that the person might not want to reveal anything about his project. If the condition to get help is that he reveals it then it won't work x.x

But yeah just making sure we won't get into a closed-minded mentality about calc development. I still remember the days where if you asked help to do stuff like what Calc84maniac did without revealing your project, you were almost a weirdo x.x, and since Omnimaga activity increased a lot, especially on the ASM side lately, I need to make sure we don't fall back into that mentality so people can still continue progressing in calc dev.
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: Quigibo on May 13, 2010, 06:59:57 pm
Regardless of what this will be used for, although I think I have an idea, I still say that this is very dangerous.  No one is being close minded here, the routine was already posted that he requested.  We are just discouraging it becasue no one wants to accidentally brick their calculator, you really really have to know what you're doing.  The fact that the routine was asked for in hex makes me think that this is not going to be written in pure assembly.  If that's the case, I would definitely stay away from the flash, there's a lot more to it than just unlocking it.  You still need to swap pages, read things into registers, swap them back into buffers, and other things that really have to be done in assembly.
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: DJ Omnimaga on May 13, 2010, 07:05:47 pm
I think he's planning to use some inline ASM in there too. Regardless, he should test on emulators first, in case, and if he's planning to use it for what I think, then first, he really needs to make sure the user won't be able to access the certificate stuff and that the rest of the non-RAM stuff appears to the user only in read-only state (in the program). For what he wants to do (providing this is what me and Quigibo are thinking about), he will really need to be certain his If condition logic operations really works perfectly before loading anything on his calc, so he won't accidentally go out of bounds then cause nasty stuff.
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: ztrumpet on May 13, 2010, 08:48:34 pm
I really hope he's not going to brick calcs.  This is some serious stuff, and when added together actually has me scared for his calc.  Good luck Sircmpwn! :)
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: Builderboy on May 13, 2010, 08:52:13 pm
Interesting, i cant wait to see what this is for.  Although i am a bit worried that something bad might happen O.O make sure to test all your code on an emulator!  Or else calc bricking might occur....
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: DJ Omnimaga on May 14, 2010, 12:43:40 am
Btw our mutual friend would prefer this routine in HEX format rather than z80 so he can use it directly as inline assembly in Axe
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: Quigibo on May 14, 2010, 12:53:26 am
It uses a absolute calling, so you can't have a pure hex version unless you know the exact address this code is going to be inserted.
Title: Re: A routine to lock/unlock flash? (Request by Sir, relayed by me)
Post by: DJ Omnimaga on May 14, 2010, 01:05:01 am
Ok I will tell SirCmpwn via e-mail, then.