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

[FEATURE REQUEST] Add a cartridge fixer #812

Open
Adamillo opened this issue Apr 30, 2023 · 4 comments
Open

[FEATURE REQUEST] Add a cartridge fixer #812

Adamillo opened this issue Apr 30, 2023 · 4 comments

Comments

@Adamillo
Copy link

As of late 3DS cartridges are starting to become corrupted, but someone called Skawo made a fork of GM9 that adds a feature called "Fix cartridge corruption". What it does is that it tries to restore the files of the game back to it's original good state. It would be great if this feature was in a mainline GM9 build. More info in how this feature works is in the fork itself: https://github.com/skawo/GodMode9-with-Cartridge-Fixer

@d0k3
Copy link
Owner

d0k3 commented Apr 30, 2023

Not a bad idea. Can we get @skawo on board for discussing a possible pull request? I first need to fully understand the issue, though. Carts should not be writeable (except for card2 saves...), So something like that shouldn't even happen.

@Adamillo
Copy link
Author

It is read only, but also not, it's a little complicated. Here's more info with the lifespan of 3DS/Switch cartridges. Both of those consoles use the same cartridge technology: https://gbatemp.net/threads/nintendo-switch-3ds-cartridge-lifespan.591607/

@skawo
Copy link

skawo commented Apr 30, 2023

While it would be awesome to add this to the main GodMode9 repo, I think you should probably rewrite the code, as mine is not great.

All my code does is essentially run the 'Verify NCCH' function, but instead of stopping as soon as it finds a mismatched hash, it sends the CTR Refresh function over and over until either the hash matches, the hash gets stuck on the same value, or the user skips that particular block.

It appears that the refresh function only affects the data that has last been read. Reading the data in smaller chunks might help, as then the refresh command is working on those smaller chunks.

As far as I understand, the refresh function is doing something akin to the following:
https://www.researchgate.net/figure/n-Place-Reprogramming-Flash-Correct-and-Refresh-Technique_fig5_351061393

The refresh function is typically run by the 3DS every time you insert a cartridge, every 10000 reads and every time the system is shut down. Godmode9 runs the function every 10000 reads, as seen here:
https://github.com/d0k3/GodMode9/blob/master/arm9/source/gamecart/command_ctr.c#L19-L23

From what has been tested, it is safe to run this function more frequently than usual - one user with a particularly bad Smash Bros. cartridge let the tool run for nearly a week, getting to 531 million refresh calls - and his cartridge still got better after the process (it was too corrupted to recover completely, but at least it managed to get into the menu, whereas before it would crash immediately). No one has yet to report that their cartridge got worse after running this process.

I have been keeping a tally of how many cartridges have been fixed using this method in this thread: https://gbatemp.net/threads/corrupted-cartridge-fixer-release.628539/

@Adamillo
Copy link
Author

Adamillo commented Oct 4, 2023

@d0k3 any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants