Compare commits

..

1456 Commits

Author SHA1 Message Date
ZeroSkill1
cf1cb1cfc5 fix a few cases of improper varg usage in luaL_error 2025-04-26 14:38:59 +02:00
ihaveahax
9ae4351bce
Lua documentation fixes (#910)
* lua-doc: Fix fs.find_all documentation

It returns an array, not a string. Also document return information.

* lua-doc: Remove TODO for fs.verify_with_sha_file

No reason to add fs.read_file errors here as that function gets
pcall-ed. If it fails, nil gets returned.

* lua-doc: Consistently refer to tables/arrays as tables

That's what they're called within Lua all the time.

* lua-doc: fix incorrect references to util module
2025-04-26 14:38:25 +02:00
ihaveahax
99f1abd7a4 lua io: fix incorrect mode detection
string.find has pattern matching by default, so it was incorrectly
reading "r+" when the mode was supposed to be "r". So this disables the
pattern matching and does a plain substring search.
2025-04-26 14:37:46 +02:00
ihaveahax
15eb3b1ebe
GM9Megascript: remove "Un-install Hax" (#916)
This option is confusing because despite it saying "will completely
remove CFW", it is not sufficient to actually fully remove custom
firmware. It doesn't, and can't, detect everything like region changes,
modified system titles, and other things that could brick a stock
console.

There have been numerous cases of bricked consoles because someone saw
this, thinking it would do everything needed to restore a console back
to an unmodified state, and getting a bricked console that needs a
flashcart purchase to fix.

(There is also a issue where, even if everything else was in order, it
can still brick a console due to a bad SD card. For some reason it
copies the FIRM to the SD card, where it can potentially get corrupted
if a counterfeit card was used.)

A proper uninstall guide is required, and we have one here:
https://3ds.hacks.guide/uninstall-cfw
2025-04-26 14:36:36 +02:00
ihaveahax
4424c37a89
Fix fs.list_dir not closing directory (#902)
I forgot fvx_closedir oops!
2025-03-24 17:11:46 +01:00
TophattedWasTaken
bc84780036
Lua examples: Small error corrections (#898)
* HelloScript.lua: Correct typos

* Lua docs: fget corresponds to fs.read_file
2025-03-24 17:08:53 +01:00
d0k3
712df196f1 Updated 9th anniversary splash 2025-03-22 14:06:35 +01:00
d0k3
a20c955e2a Updated readme credits 2025-03-22 14:06:27 +01:00
Pk11
7b20581fce
Update translations with Lua strings (#893) 2025-03-21 13:00:41 +01:00
ihaveahax
ba0272ff5d
Lua support (#878)
* Test implementation of lua

* Trust that lua knows what its doing with this

Silence warnings

* actually update top screen when Thingy is called, disable unnecessary ShowPrompt calls

* readme

* change init for a simple test, print error on top screen too

* Readme

* change init for a simple test, print error on top screen too

* enable more lua libs, edit init.lua with string examples

* one more readme edit before bed

* Readme

* change init for a simple test, print error on top screen too

* enable more lua libs, edit init.lua with string examples

* make lua a proper file type, add test UI library with two functions, remove luacmd command

* remove old attempts at editing lauxlib and liolib

* README

* README

* FS lib, new UI stuff

* consistency with "type* ptr" maybe

* add custom package searcher, reset package.path

* new functions for UI including basic print output buffer, add "Lua scripts..." option to home/power menu

* build vram0.tar including subdirs of data

* move default path to GM9LUA_DEFAULT_PATH

* FS_FileGetData

* testfgd, add GM9VERSION global, update README, fix indentation

* FS_FileGetData will return a nil instead if it fails

* it's actually luaL_pushfail

* os

* use luaL_tolstring instead of lua_tostring

* fix test/remove debugging showprompt

* os.clock float attempt

* fix print for real

* fix swapped offset and size for FileGetData

* finish OS stuff

* fix os.clock

* shorten table in/out

* remove .vscode dir

* enum test

* support building without lua

* NO_LUA hides menu options (except when you directly select a lua file)

* update UI lib to better match the ideas on #1

* dockermake

* add DrawPNG function

* whoops its ShowPNG

* minor fixes, add DrawPNG

* fix AskPrompt, add all showprompts mentioned in #1

* add newly added functions to readme

* try to keep separate code and data

* update lua to 5.4.7

* remove test libraries now that i want to attempt to implement in a real api

* add nix flake for building

* add various lua functions, some of them taken from the old attempt but with new names

* add dev shell to flake.nix

* remove test lua scripts in root

* add test lua scripts in data/luascripts

* add a whole bunch more lua functions and stuff

* add more test lua scripts

* add more functions, add preload script, add test io compatibility module

* add more functions and test scripts

* more functions and stuff

* more functions and stuff

* more functions and stuff, plus a wip ctrcheck reimpl

* yet more functions and stuff

* even more functions and stuff

* command comparison table.ods

* update command comparison table.ods

* update command comparison table.ods

* Add files via upload

* update command comparison table.ods

* update ui.show_text to use DrawStringCenter, update ctrcheck rewrite

* Split up the ARM9 code (.text, .vectors) and data (.rodata, .data, .bss) sections into their own ELFs.

This allows us to use more ARM9 WRAM while leaving the 128k BootROM mirror intact.

* use the makefile definition

* add title module, move around some functions, update command comparison table

* add readme for lua

* remove liolib.c and loslib.c

* more functions and things, use CheckWritePermissionsLuaError in place of more manual checks, update command comparison table

* add missing constant

* set CURRDIR to nil instead of "(null)" if not found

* remove gm9enum (unused since the restart)

* add ui.check_key

* split fs module to lua overlay and _fs internal module, and add a check for fs.write_file in lua

* add fs.ask_select_file and fs.ask_select_dir

* add fs.key_dump, replace overwrite_all and append_all with overwrite and append

* add fs.cart_dump and sys.emu_base

* add ctrtool, update flake.lock

* add io append mode

* make sure io.open with write mode starts with an empty file, add os.remove and os.rename aliases

* properly implement os.remove compatibility

* add fs.verify_with_sha_file, fix PathIsDirectory by using stat instead of opendir

* add util.running_as_module (untested)

* move scripts over to https://github.com/ihaveamac/GM9-lua-script-experiments

* remove ods and dockermake.sh

* remove data/scripts

* add lua autorun (untested)

* fix syntax error

* add sys.check_embedded_backup

* remove accidental symlink

* add sys.check_raw_rtc

* fix ui.show_file_text_viewer not freeing memory or reporting an error if OOM happens

* add todo notes for ui

* work-in-progress lua doc

* formatting fix

* up heading level for all sections

* Revert "up heading level for all sections"

This reverts commit 6ef14b619536b4253e341ba40b4dea728358979d.

* separators

* fix name and error for fs.move

* do explicit permission checks in fs.move

* fix error string for fs.copy

* fix function name for fs.dir_info

* fix error string for fs.find and fs.find_not

* fix function name for fs.img_umount

* partial fs doc

* finished fs doc, string fixes for fs module

* document fs.cart_dump encrypted opt, remove stat from fs.verify_with_sha_file

* title doc

* sys doc, error string updates

* util doc

* add json.lua to lua-doc

* add fs.find_all

* add 3dstool to flake

* make fs.find_all recursive actually recursive, document fs.find_all

* add "for" to comparison table

* change fs.find to return nil if no path was found, instead of raising an error

* change ui.echo to automatically word wrap (untested)

* Revert "change ui.echo to automatically word wrap (untested)"

This reverts commit 2524e7707708e9818162c31f9f004b6301a3061b.

* switch devkitNix to upstream

* flake.lock: Update

Flake lock file updates:

• Updated input 'devkitNix':
    'github:ihaveamac/devkitNix/883d173b94e3da8dc4cc0860cdda8c36b738817c' (2024-12-05)
  → 'github:bandithedoge/devkitNix/95fd44f4ac7cecf24edf22daa899a516df73c6b7' (2025-01-11)
• Updated input 'devkitNix/nixpkgs':
    'github:NixOS/nixpkgs/566e53c2ad750c84f6d31f9ccb9d00f823165550' (2024-12-03)
  → 'github:NixOS/nixpkgs/4bc9c909d9ac828a039f288cf872d16d38185db8' (2025-01-08)
• Updated input 'hax-nur':
    'github:ihaveamac/nur-packages/c570b3830f7dd4d655afb109300529c896cd8855' (2024-12-05)
  → 'github:ihaveamac/nur-packages/cd49afba206c2eb10a349d92470fdf2cc942ae23' (2025-01-11)
• Updated input 'hax-nur/nixpkgs':
    'github:NixOS/nixpkgs/2c15aa59df0017ca140d9ba302412298ab4bf22a' (2024-12-02)
  → 'github:NixOS/nixpkgs/4bc9c909d9ac828a039f288cf872d16d38185db8' (2025-01-08)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/566e53c2ad750c84f6d31f9ccb9d00f823165550' (2024-12-03)
  → 'github:NixOS/nixpkgs/32af3611f6f05655ca166a0b1f47b57c762b5192' (2025-01-09)

* flake.lock: Update

Flake lock file updates:

• Updated input 'devkitNix':
    'github:bandithedoge/devkitNix/95fd44f4ac7cecf24edf22daa899a516df73c6b7' (2025-01-11)
  → 'github:bandithedoge/devkitNix/a344b0200a044f2d2ff99685f13ff7c53106428e' (2025-02-06)
• Updated input 'devkitNix/nixpkgs':
    'github:NixOS/nixpkgs/4bc9c909d9ac828a039f288cf872d16d38185db8' (2025-01-08)
  → 'github:NixOS/nixpkgs/5b2753b0356d1c951d7a3ef1d086ba5a71fff43c' (2025-02-05)
• Updated input 'hax-nur':
    'github:ihaveamac/nur-packages/cd49afba206c2eb10a349d92470fdf2cc942ae23' (2025-01-11)
  → 'github:ihaveamac/nur-packages/2ce890cab4e948109ad1ad82ba18e69240a0d352' (2025-02-06)
• Updated input 'hax-nur/nixpkgs':
    'github:NixOS/nixpkgs/4bc9c909d9ac828a039f288cf872d16d38185db8' (2025-01-08)
  → 'github:NixOS/nixpkgs/8532db2a88ba56de9188af72134d93e39fd825f3' (2025-02-02)
• Added input 'hax-nur/treefmt-nix':
    'github:numtide/treefmt-nix/bebf27d00f7d10ba75332a0541ac43676985dea3' (2025-01-28)
• Added input 'hax-nur/treefmt-nix/nixpkgs':
    follows 'hax-nur/nixpkgs'
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/32af3611f6f05655ca166a0b1f47b57c762b5192' (2025-01-09)
  → 'github:NixOS/nixpkgs/5b2753b0356d1c951d7a3ef1d086ba5a71fff43c' (2025-02-05)

* make devkitNix and hax-nur inputs follow nixpkgs

* Also dump section headers on .dis file

* prepare for upstream merge

* Restore original README.
* Remove flake, was only used for my own testing

* fix accidental removal of LIBS

* copy lua-doc.md into release archive

* README: update to mention Lua in place of GM9Script, add credits

* lua-doc: fix typo

* add sample HelloScript

* lua-doc: remove wip notice, since all gm9script features are replicated

* remove accidental inclusion of language.inl

* Fix mixture of tabs and spaces

* remove accidental nix leftover

* re-add @ for add2tar command

---------

Co-authored-by: luigoalma <luigoalma@hotmail.com>
Co-authored-by: Gruetzig <florianavilov@gmail.com>
Co-authored-by: Florian <88926852+Gruetzig@users.noreply.github.com>
Co-authored-by: Wolfvak <soherrera1@hotmail.com>
2025-03-21 08:25:04 +01:00
Wolfvak
50270a820c
Split up the ARM9 code and data sections (#883)
* Split up the ARM9 code (.text, .vectors) and data (.rodata, .data, .bss) sections into their own ELFs.

This allows us to use more ARM9 WRAM while leaving the 128k BootROM mirror intact.

* use the makefile definition

* Also dump section headers on .dis file
2025-03-15 14:25:23 +01:00
Pk11
61c79e3e3f Add Fusion font for Chinese 2025-03-13 13:37:54 +01:00
Pk11
ab222de6b1 Update translations
- New! Chinese (Simplified) 100%
- German 100%
- French 94%
- Dutch 46%
- Spanish 41%
- Italian 27%
- Ryukyuan 18%
- Indonesian still 100%, but changed
2025-03-13 13:37:54 +01:00
Wolfvak
143fcf0d6b Display hours in ETA if the remaining seconds is >= 3600 2025-03-12 17:12:02 +01:00
Wolfvak
157848c770 Add .vscode to the gitignore 2025-03-09 17:06:18 -03:00
Pk11
8cde50e091
Automate translation files (#880)
* Automate language.inl file

* Move version number to JSON file

Better than being a magic number somewhere in the code, source code gets it from source.json

* Automate creation of .trf translation files
2024-11-30 08:24:15 -03:00
profi200
105f4ae5f7
Increased CTRCARD clock from 4.18 to 13.4 MHz on ROM reads. (#873) 2024-11-26 19:32:51 -03:00
ZeroSkill1
9e7df4c52d 'update CI to use upload-artifacts v4' 2024-11-14 12:49:09 +01:00
ZeroSkill1
208f12bde7 Fix multi RedNAND 2x not being set up properly 2024-11-14 12:49:09 +01:00
Wolfvak
7b6b478582
Use VA start and end linker symbols instead of length (#865) 2024-06-19 16:19:45 -03:00
Fra
eee63dd155
Fix fcram boot bug (#864)
Fixed old bug that appeared regarding the fcram boot failing.
2024-06-15 15:37:11 -03:00
Ricca665
dab90a9162 Update Makefile
Fixes python3 not found when running make on windows
2024-04-04 15:25:50 +02:00
Luís Marques
26990ca23a
Key 0x2C is different per platform (#842)
Change KeyY to generate same KeyNormal on dev
2024-03-17 11:27:27 -03:00
Pk11
338a2aa98a
Fix crashing in script runner mode (#840) 2024-02-20 15:13:57 -03:00
Luís Marques
399740b50e
Undefined behavior fix on ticket.c (#838)
Stack garbage is always a luck of the draw
This was causing issues on non-LTO build.
LTO was just lucky.
2024-01-25 11:28:03 +01:00
ihaveahax
ad8b5e0a8c
arm9/arm11 Makefile: Fix building with spaces in path (#828)
This quotes $(CURDIR) which fixes an issue with building GM9 in a path
with spaces, which Windows users are likely to have.
2023-08-25 21:58:22 -03:00
Wolfvak
14b390a943
Move the start of AHBWRAM to be immediately after the VECTORS (#827) 2023-08-23 10:51:35 -03:00
Wolfvak
031762a1fe
Embed the VRAM tar data in the ARM9 executable (#824)
* Embed the VRAM tar data in the ARM9 executable

* Fix Makefile dependency order

* Use address difference instead of absolute word for the VRAM drive limit
2023-07-24 10:17:37 -03:00
Danny Tsai
8b362c977a
Correct installable address whitelist (#816)
* Correct installable address whitelist

blacklist is stored at 0xb088~0xb0bf, which is ulong[14] in
{start(inclusive), end(exclusive)} pair.
one thing to note is that boot9 use inclusive comparing with
blacklist start for both section load address and
section load address + section size (comparing logic is
at 0xa42e~0xa449), so if the firm fits perfectly at the end
of the space right before the blacklisted range,
it'll also be rejected.

* shrink vram drive size to avoid bleeding into blacklisted range
2023-07-21 21:39:08 -03:00
Nemris
11b05d7a3d Fix leftover typo 2023-07-20 12:58:36 +02:00
Nemris
3008bfed61 Reduce noise and drop dataclasses 2023-07-20 12:58:36 +02:00
Nemris
f7a9b3eec8 Refactor to improve modularity
This commit adds documentation and type annotations, and allows the
script to be imported as a module.
2023-07-20 12:58:36 +02:00
Pk11
e1fa23a031 Update translations
- Spanish: 31%
- Japanese (kana only): New, 27%
- Ryukyuan (Uchinaaguchi): New, 18%
2023-07-10 16:35:42 +02:00
Pk11
8006fbd5db Update translations
- Improvements to Indonesian
2023-07-10 16:35:42 +02:00
Pk11
b4f04d3620 Update translations
- Indonesian: New and DONE!
- Italian: New, 11%
- Spanish, French, Dutch: Fairly minor improvements
2023-07-10 16:35:42 +02:00
Pk11
eb37a21354 Remove untranslated trailing strings 2023-07-10 16:35:42 +02:00
Pk11
a68d7d0cb7 Update translations
Added the date/time and number formats
I just did these myself since I wanted to test them more thoroughly, based on JavaScript's Intl
2023-07-10 16:35:42 +02:00
Pk11
87f9b82cd3 Update translations
- Added 3 new strings, only Japanese translated so far
2023-07-10 16:35:42 +02:00
Pk11
a293c008d5 Update translations
- Japanese: Improved
- German: 66%
- French: 53%
- Dutch: 27%
2023-07-10 16:35:42 +02:00
Pk11
780016933c Update translations
Japanese 100%!!
2023-07-10 16:35:42 +02:00
Pk11
041ff61d41 Update translations
- Japanese: 71%
- French: 39%
- 10 strings edited
2023-07-10 16:35:42 +02:00
Pk11
1fd15657d8 Update default font, add Japanese font 2023-07-10 16:35:42 +02:00
Pk11
0971b3d9fa Add translations
Spanish, French, Japanese, Dutch, Polish, and Russian
2023-07-10 16:35:42 +02:00
Danny Tsai
b7c97af144
Update README.md to match current VRAM drive info (#815) 2023-06-02 18:13:09 -03:00
Wolfvak
723529e2d8
Fix compilation warnings on dkA r60 (#808)
Mostly just switched out the bound strn* functions for their unbound variants when the string is a known constant
2023-04-25 10:13:28 -03:00
Wolfvak
b5fca3bc7e
Use the correct MCU LED period for calculations (#807)
Fixes #772
2023-04-25 10:13:07 -03:00
Pk11
620e5061c5 Add font/language info to README, Pk11 to credits 2023-04-15 12:54:02 +02:00
Pk11
5aaac66eef Use sizeof in snprintf where possible, ensure UTF_BUFFER_BYTESIZE
This commit looks a lot bigger than it really is, I noticed a couple spots where with these issues so I ran a regex to find all possible occurrences and switched all that could be, after manually ensuring it was actually correct

Using sizeof on the buffer (as long as the buffer is a char *array*, not a pointer!!) greatly reduces the chance of something having the wrong size because of a later change to the buffer, notably a couple snprintfs were missed in the UTF_BUFFER_BYTESIZE change
2023-04-15 12:54:02 +02:00
Pk11
439e06334b Add language selection on first load & from HOME 2023-04-15 12:54:02 +02:00
Pk11
8303440c19 Add loading translations from TRF
Reduce pointer magic use

Both translations and fonts
2023-04-15 12:54:02 +02:00
Pk11
93ee590cad Make strings translatable 2023-04-15 12:54:02 +02:00
Pk11
cae3d272d3
Only reserve space in trimmed NDS files for RSA key if it exists (#804) 2023-04-09 15:38:35 -03:00
ZeroSkill1
64414e12ab fix buffer overflow
This would cause exceptions when encrypting/decrypting CIA files to
`0:/gm9/out`.
2023-03-23 16:57:47 +01:00
Pk11
9514755989 Update Cyrillic homoglyphs
Whoops, forgot to update a couple of the Cyrillic letters where I changed their Latin homoglyphs
2023-01-31 13:21:52 +01:00
Pk11
ccd21984b2 Remake ASCII part of font
Actually a little more than ASCII, everything that was previously from the Linux kernel font
Linux is GPL2, GM9 is GPL3, thus this is sorta kinda maybe in violation of that
It's complicated since typefaces cannot be copyrighted in many countries, so arguably it's fine
2023-01-31 13:21:52 +01:00
d0k3
a23ba0e14b Fix a typo 2022-11-28 09:12:56 +01:00
d0k3
3710ed975b Enable compatibility with mGBA RTS savegames 2022-11-28 09:11:57 +01:00
Pk11
9416ec5ac0 Make select prompt scroll if too many options
Also a little cleanup to the file browse one for consistency
2022-10-24 14:35:04 +02:00
Myriachan
c9d792cb27 Add Brazil to SysInfo serial number recognition. 2022-09-27 16:59:57 +02:00
d0k3
096e6c3cb7 Add padding byte value to cart info file
Fixes #780
2022-07-22 21:43:23 +02:00
Gabriel Marcano
b11194397a
use sizeof with snprintf when target is an array (#778)
- GCC warned of a case when the size specified in a snprintf call was
   larger than the size of a target buffer. To fix, when possible use
   sizeof() to match buffer size.
2022-06-23 17:37:19 -03:00
aspargas2
658c9b491c use --use-blx linker argument
makes firm about 500 bytes smaller for free
2022-04-16 18:40:47 -04:00
d0k3
f611b31c0c Sixth Anniversary splash 2022-03-22 19:42:06 +01:00
d0k3
c13bba4cfe Fixed a boatload of compiler warnings 2022-03-22 19:40:47 +01:00
d0k3
d95a606ec2 Fix bad trimming of certain NDS dumps
Fixes #763
2022-03-08 18:47:32 +01:00
Pk11
586d30fafa Improve DSiWare save generation 2022-02-21 23:57:02 -06:00
aspargas2
682b570ef7 scripting: don't initialize dynamic env vars until they're needed
this should fix the long delay on loading any script
2022-01-12 11:33:04 -05:00
aspargas2
8d1557191f fix conflicting move/copy flags 2022-01-08 19:07:53 -05:00
aspargas2
cb11db6f1b fix crashes when showing certain error messages 2021-12-02 18:33:53 -05:00
aspargas2
1554aac4e1 fix hexeditor instructions formatting 2021-12-02 14:22:13 -05:00
aspargas2
fdbca10773 add format attribute to printf-like functions 2021-12-01 17:07:46 -05:00
d0k3
1f8de2af99 Add new default splash logo 2021-11-21 13:13:42 +01:00
d0k3
1b8bd121b6 Added raw cart dumper (R+A on cart drive) 2021-11-14 22:14:59 +01:00
d0k3
ba10ce96c3 Scripting: added cartdump command 2021-11-14 22:14:59 +01:00
d0k3
25bf8b3f93 Added installer for cifinish.bin files 2021-11-14 22:14:59 +01:00
Pk11
07cb94d99a Add 美咲ゴシック (Misaki Gothic) 8x8 Japanese font 2021-11-14 22:14:59 +01:00
Pk11
1ffbca7d46 Allow loading FRF fonts up to 0x20000 bytes 2021-11-14 22:14:59 +01:00
Pk11
942e67e507 Add Unicode hex input 2021-11-14 22:14:58 +01:00
Pk11
830479f50c Fix multibyte letters in keyboard and input prompt 2021-11-14 22:14:58 +01:00
Pk11
0275a85121 Convert old escapes to Unicode
Only does the ones below ASCII (0x00 - 0x1F), hopefully none of the high ones are important because they'll conflict with Unicode codepoints
2021-11-14 22:14:58 +01:00
Pk11
3eb92754bc Use lookup table for ASCII to avoid binary search 2021-11-14 22:14:58 +01:00
Pk11
77fc7af2f2 Use macro for UTF-8 byte count
Makes it more clear why all of the buffers are being multiplied by 4

Fix UTF-8 bytesize macro

Before UTF_BUFFER_BYTESIZE(str_width - 10)] would multiply the 10, not the whole number, by UTF_MAX_BYTES_PER_RUNE

Do (rune_count + 1) * 4 in UTF-8 bytesize macro

Fix Resize/Truncate String snprintf size

Before it would break if the last character was multi-byte
2021-11-14 22:14:53 +01:00
Pk11
b366200d4b Switch to a RIFF font format
Fix height of ラ character

I accidentally made it 1px too tall before

Add Cyrillic to default font

Make Я more like latin R

Right after I commit, looking at my screenshot I notice I forgot to tweak the Я to be more angled like this font's latin R...

Improve the default font's Kana

derp fix

Properly handle invalid UTF-8

Fix conversion PBMs with non-byte aligned rows

Rename font extension to .frf

For Font RiFf

Re-add PBM font support

Default converting to CP-437 and try guess size

Revert "Default converting to CP-437 and try guess size"

Reverts 2c9a47d224b28cbb51a3ee335fd9970265201b72 as I think the old behaviour works better given PBM font support being kept

Re-add mapping file for CP-437

Automatically use mapping file with same name as image

ex. for "font_6x10.pbm" it will use "font_6x10.txt" in the same directory
2021-11-14 22:13:55 +01:00
Pk11
13eb4f8869 Proper handling of UTF-8
Note: This commit may be slightly broken, I'm just splitting up it and the next one at the end.
2021-11-14 22:13:32 +01:00
TimmSkiller
55385a5502
Fixed inability to install a larger/smaller ticket when a smaller/large one is installed (#733)
* Fixed inability to install a larger ticket when a smaller one is installed

* improved AddBDRIEntry checks, formatting and added define for REPLACE_SIZE_MISMATCH
2021-10-23 13:19:13 +02:00
TimmSkiller
0dbe70928f
fix #729 - building titlekeys.bin files
* fix #729

* Improved code layout & show NAND type when building support files
2021-10-23 13:14:53 +02:00
aspargas2
7feeb51a65 split SHA-1 evenly over two lines (like SHA-256) 2021-10-21 18:22:07 -04:00
d0k3
c966acc851 Display SHA-1 over two lines (like SHA-256) 2021-10-09 11:58:47 +02:00
BuildTools
e042886db4 add user-facing sha1 support 2021-10-09 11:58:47 +02:00
d0k3
ddf577b88c Fix #739 2021-10-09 11:13:51 +02:00
d0k3
3124d944a6 Reenable searhcing titlekeys from illegit tickets
Fixes #595
2021-10-09 10:51:52 +02:00
Balint Kovacs
27e316571d Add a new type of flash chips, from Art Academy
It adds a new chip type, that works like regular 3DS saves. It
presumably is manufactured by Macronix as well.

Thank you for your help, @FerozElMejor on Discord and @Epicpkmn11
2021-09-26 16:36:19 +02:00
d0k3
0e46d4fca8 Ammend the borked previous commit 2021-08-31 13:36:57 +02:00
d0k3
33d59f6d3a Add 0x88 to NDS cart dumps trimmed size 2021-08-19 21:09:13 +02:00
lifehackerhansol
d85023b173 Append 0x88 to ntr_rom_size to preserve RSA keys 2021-08-12 20:39:18 +02:00
d0k3
4dc96d37e8 Fix #720 2021-07-23 14:01:19 +02:00
d0k3
c9b6a335f7 Add LARGEDLC mode for titles with > 1024 contents
Fixes #703 and is only active with `make LARGEDLC=1` and will break compatibility with other titles and CIAs. Thanks @luigoalma for new ticket builder code!
2021-07-07 18:00:11 +02:00
d0k3
33a115b75c Fix strings -> chars 2021-07-06 18:48:04 +02:00
TimmSkiller
ef161bce42 Fix NDS / DSi names being cut off when renaming to good name 2021-07-06 17:14:44 +02:00
WaluigiWare64
d8d43c14f3 Detect transparent pixels in DS icon and set them to white 2021-06-23 18:46:39 +01:00
Wolfvak
37c8c50097
fix the "conact" typo (#709)
also adds a direct link to the irc channel
2021-06-02 09:03:37 -03:00
Wolfvak
c2d96c0d9c add a "contact info" section in readme
contains both irc and discord links, and removes the discord link at the bottom
2021-06-01 20:07:02 +02:00
luigoalma
41d36c620f Make safe for editing certificate function
As long memory max bounds are still respected
2021-05-22 14:12:19 +02:00
luigoalma
4b5ac1a8e0 Certificate provide signature verification call 2021-05-22 14:12:19 +02:00
luigoalma
be289b4c55 Just search both nands for certs on callee
Since in all cases that LoadCertFromCertDb is called
is always twice, one for sysnand and another for emunand
just make it a single call and quit early when cert found.
2021-05-22 14:12:19 +02:00
luigoalma
3bfb9ef6ec Make cert bundle building nicer
At least in the caller perspective.
Also break down some functionalities into separate funcs,
interally calling them on cert.c to avoid too many checks.
And tried to avoid too much repeated code.
2021-05-22 14:12:19 +02:00
luigoalma
1f96b5e9e6 Certificate static storage
Decrease repeated load times
At least for retail/dev certs
2021-05-22 14:12:19 +02:00
luigoalma
8427e0776c Adjusting ticket.h
Just because there's a more neat to look at definition
on types.h for packed and aligned
2021-05-22 14:12:19 +02:00
luigoalma
61c17e491f Load from certs.db more accordingly
Also extra cert handling code
2021-05-22 14:12:19 +02:00
d0k3
236d2dc09c Fix CIA good renaming (add version) 2021-04-29 20:50:13 +02:00
d0k3
8680358aa1 Fix #702 2021-04-29 19:58:12 +02:00
d0k3
7e01954e48 Properly handle emanuals in update images 2021-04-01 09:29:49 +02:00
d0k3
0825139cb2 Scripting: add SDSIZE, SDFREE and NANDFREE global variables
fixes #691
2021-03-31 17:33:05 +02:00
clach04
9f431a5fde
helper text for SysNAND backup size
https://3ds.hacks.guide/finalizing-setup Section VIII, 3 - recommends 1.3 Gb free

On a Japanese firmware 11.10.0-43J - needed 950Mb free.
2021-03-31 17:07:01 +02:00
Balint Kovacs
cc99734fac Fix IR card support
This is based on the latest update of GBATEK.
2021-03-31 17:01:32 +02:00
Balint Kovacs
6799b24730 Fix a bug on 512B EEPROM saves
Fixes #690
2021-03-31 17:01:32 +02:00
Balint Kovacs
adb8ad260f Add some documentation to cart types, and remove old exports 2021-03-31 17:01:32 +02:00
Balint Kovacs
5c2ab6958c I found a new type of flash chip on a bootleg cart 2021-03-31 17:01:32 +02:00
Balint Kovacs
7af76b91bb Detect save size by the last byte of JEDEC id, if possible
This is my second attempt to resolve #553

Props to @wwylele for pointing out that the last byte of the JEDEC ID is
just the exponent of the size (base 2)
2021-03-31 17:01:31 +02:00
d0k3
ce50bd63a8 Add 5th anniversary splash screen 2021-03-22 17:43:33 +01:00
d0k3
1a27dcb1e8 Remove possibly faulty tickets when installing CIAs
fixes #685
2021-03-22 17:42:31 +01:00
d0k3
c20911047a Don't allow ticket installations from mounted media 2021-03-22 17:37:24 +01:00
d0k3
fd8c5d1897 Show title id & game icon in file handler menu 2021-03-18 22:44:33 +01:00
d0k3
0bbbc7c324 gamecart.c: fix indentation, a small merging mistake 2021-03-18 00:33:58 +01:00
Balint Kovacs
9f52deedad Card-2 saves: Detect save size from ExHeader
This also limits the save blanking to the actual save area. This way
every byte of the cart can be read again.
2021-03-18 00:28:44 +01:00
Balint Kovacs
60f2c5192d Add save chip JEDEC ID to gamecard info 2021-03-18 00:28:44 +01:00
Balint Kovacs
f2e52bd1c7 Initial support for CARD2 read
Can I get card2 writing to work?

Am I _that_ good?

Will I break by copy of X?

I won't know until I try!
2021-03-18 00:28:44 +01:00
Balint Kovacs
dfb2dff352 Some groundwork for CARD2 save support 2021-03-18 00:28:44 +01:00
d0k3
1cb72a87e1 Allow verifying incomplete DLCs 2021-03-18 00:08:14 +01:00
Margen67
3952de3a1e ci.yml: changes
Change image to ubuntu-latest.
Remove redundant :latest from container.
Make python3 pip install into one less line.
Add -j to make to speed it up.
Replace cd with working-directory and remove unneeded cd.
Add if-no-files-found: error to upload-artifact.
2021-03-14 14:59:05 +01:00
d0k3
294890057f Display full filename in file info (for long filenames) 2021-03-14 14:56:35 +01:00
d0k3
4e00b8b7b6 Include version number in renamed CIA / titles 2021-03-14 14:56:35 +01:00
d0k3
ddfdf81cf7 Combine & improve game info and CIA/title checker 2021-03-11 20:24:39 +01:00
SirNapkin1334
8b5af2c22f Update Discord Link :/ 2021-03-11 08:39:28 +01:00
MechanicalDragon
445688c5fb fix clear friendlist script missing end statement 2021-03-09 18:04:27 +01:00
d0k3
8fa85437dd Added ability to dump tickets in title manager 2021-03-08 23:52:55 +01:00
d0k3
2cd6acb31e Enabled title checker tool in Title Manager 2021-03-08 18:35:49 +01:00
Garrett Holmstrom
c70a7db0f3 Include scripts in ntr firms
Unless the SD card happens to both be accessible and contain a
`gm9/scripts` directory, a system booted with a NTR cartridge isn't going
to have access to the stock scripts and will just show an error upon
going to the menu and selecting `Scripts...`.  This patch adds scripts
to the vram tarball only for ntr builds so they can be available even
on completely untouched systems.  It shouldn't be necessary when we've
booted from something else because in those cases we've already written
GodMode9.firm to flash using some other means and could have copied all
the scripts then.

One might argue this is sub-optimal because the menu will point there
even if a scripts directory happens to exist on the SD card.  One might
instead argue that that behavior is preferable because there's no telling
what gm9 version the scripts on the SD card were intended for.
2021-03-08 18:31:40 +01:00
d0k3
7bdd01738a Show a wait... message when uninstalling a single title 2021-02-27 12:18:39 +01:00
d0k3
152c6c4d5a Allow in-place encryption/decryption only on SD card 2021-02-27 12:18:14 +01:00
d0k3
32936345a6 Change support file recommendations 2021-02-23 16:10:44 +01:00
d0k3
30c5e1fd67 Add firstrun instructions to software keyboard
Adresses #601
2021-02-23 16:10:10 +01:00
d0k3
3f7eb872b8 Remove aeskeydb.bin warning for entrypoints other than b9s
Fixes #676
2021-02-23 15:45:09 +01:00
d0k3
bea16124a4 Readme updates 2021-02-22 17:12:07 +01:00
d0k3
71e3b6f73c Trimming functionality for GBA cart dumps 2021-02-22 16:41:21 +01:00
d0k3
ee43fe328f Fix a compiler warning 2021-02-21 14:40:33 +01:00
Wolfvak
31389687ab event model seems to work
refactors all the ugly "pendingX" atomic operations into a single "Event" subsystem/interface thing with two operations

moves all existing code to use this instead

also changes the "bkpt" macro to also indicate unreachable code
2021-02-21 14:40:33 +01:00
Wolfvak
eadc1ab6b9 simplify the sharedmem buffers
also made the wait on boot unconditional
2021-02-21 14:40:33 +01:00
Wolfvak
9ecb90a2ba make interrupt handlers more lazy, most processing is done in interruptible context now
- completely moved MCU interrupt handling outside of the critical section
- refactored a bit of the PXI code and command names
- merge the I2C read and write cmds to be one
- remove SET_VMODE cmd, now it's always initialized to BGR565 on boot and to RGB565 on firmlaunch
- atomic-ize more stuff
2021-02-21 14:40:33 +01:00
Wolfvak
a6e20c641a initial mcu events implementation
- backlight power control is reinstated but currently buggy, for some reason the __builtin_trap is tripped on GFX_powerOnBacklights and GFX_powerOffBacklights

- also refactored a bunch of other code pertaining to mcu and other hw init, moved the gpu init to a later point since lcd init now depends on mcu events
2021-02-21 14:40:32 +01:00
d0k3
c4b3b582a7 Improved good renamer
... includes better naming for CIAs
2021-02-21 13:14:08 +01:00
d0k3
c31737c257 Title info and CIA metadata handling for encrypted CIA/CDN content 2021-02-20 12:21:40 +01:00
d0k3
2f61722aa4 Replace Tabs -> Spaces 2021-02-18 19:06:31 +01:00
d0k3
ab4316fd4e Prevent titleentry deletion in title manager 2021-02-18 18:55:36 +01:00
d0k3
24195c319a Install, build CIA, verify handling for TWL CDN content 2021-02-18 18:34:20 +01:00
d0k3
f9408a9c10 Improved CIA building, proper names for legit CIAs 2021-02-17 15:50:52 +01:00
d0k3
8114a0bd26 Higher level warning for editing 0:/Nintendo 3DS/ folder 2021-02-15 17:58:59 +01:00
d0k3
7620310b73 Build CIA and verify handling for TADs 2021-02-12 15:02:55 +01:00
d0k3
1e9fb36582 Check TMD signature when attempting legit CIA build 2021-02-12 12:50:23 +01:00
d0k3
9191a3244f Fix splash title underline for long build names 2021-02-09 19:14:24 +01:00
d0k3
af5e1a218e Show title id in title info 2021-02-08 19:04:12 +01:00
d0k3
667a1bf2c0 Install, verify, info handling for tickets 2021-02-06 14:47:40 +01:00
d0k3
48347c947a Reset to default splash.png 2021-02-05 13:16:01 +01:00
d0k3
e41b098843 Misc code improvements 2021-02-05 13:16:01 +01:00
d0k3
58fb9913d5 Fix possible overwriting of memory in vff.c 2021-02-01 18:59:55 +01:00
d0k3
899c8a8816 Updated mounted ticket.db categories
Fixes #641
2021-01-31 14:29:48 +01:00
d0k3
203cf7f9e3 Include obfuscated AES key database 2021-01-30 13:22:05 +01:00
d0k3
8ebb74b0bc Allow dumping NDS carts with secure area encrypted
Fixes #417
2021-01-30 13:22:05 +01:00
d0k3
af14376c84 Scripting: Allow escaping quotes with \"
Fixes #632
2021-01-30 13:21:20 +01:00
d0k3
647d5722aa gamecart: Replaced ID file with info file 2020-12-24 15:53:59 +01:00
David Korth
25a22d30d0 gamecart: Added a gamecart_id.bin file.
This contains the 4-byte chip ID.
2020-12-24 15:53:59 +01:00
d0k3
2f2b7faeb4 Disable title manager for mounted images 2020-12-24 15:53:59 +01:00
d0k3
efcfed31b3 Add title manager shortcuts 2020-12-24 15:53:59 +01:00
d0k3
7f6f6db410 Add title manager (replaces title search) 2020-12-24 15:53:59 +01:00
d0k3
e9599aad1c Fix building CIA from CDN files
fixes #661
2020-12-23 18:00:34 +01:00
d0k3
46a9a5819a System info: add UK as a sales region
Fixes #658
2020-12-23 16:32:57 +01:00
Wolfvak
65f6748dc1 Fix uninitialized variable on unaligned SPI Xfer
We use a stack-allocated u32 to store a temporary word that gets memcpy'd from a potentially unaligned buffer, but the size of the copy could be less than 4 bytes, therefore leaving garbage in the upper bits of said word. This fixes CODEC in Corgi3DS.
2020-12-23 14:56:18 +01:00
David Korth
d63db4bc6d gamecart: Use the chip ID's TWL flag to check if we should do TWL secure area init.
It's possible to flash a TWL-enhanced ROM image to an NTR dev cart.
This cart would function properly as a Nintendo DS game, but might
have issues on a DSi or 3DS.

GodMode9 couldn't dump this type of cartridge before because the ROM
header indicates TWL, but the cartridge doesn't understand the 0x3D
TWL secure area init command, so key exchange failed.
2020-12-09 21:53:43 +01:00
David Korth
cadd21508f gamecart: Use the chip ID to determine the ROM size.
Some development carts have an incorrect ROM header, but the cart ID
is always correct, so prefer the chip ID. If the chip ID is invalid
(unlikely), then fall back to the ROM header.
2020-12-09 21:53:30 +01:00
d0k3
01dd46ced3 Fix CMAC handling for TWLN and IMGNAND
Fixes #653
2020-11-25 23:48:36 +01:00
d0k3
e95e0fe90c Fix saves being deleted on uninstall 2020-11-25 23:08:00 +01:00
d0k3
608cf39e12 Fix #601
This adds SELECT as a shortcut ot the old button based input tool in the software keyboard
2020-11-11 00:07:09 +01:00
d0k3
df4619b213 Fix building standard CIA from TMD 2020-11-10 23:58:58 +01:00
aspargas2
cebc43792e
remove travis CI configuration 2020-10-28 18:40:26 -04:00
aspargas2
89be93384d
enable github workflows CI 2020-10-28 18:29:27 -04:00
d0k3
145bf6de54 Improve ticket searching functions
This is applies to encTitlekeys.db / decTitlekeys.bin builders as well as to to legit CIA building
2020-10-28 00:01:36 +01:00
d0k3
355519285a Verify TMD when installing / building CIA 2020-10-28 00:01:36 +01:00
d0k3
ae32e63074 Handle seed crypto when installing game images 2020-10-28 00:01:36 +01:00
d0k3
d5db8c7216 Fix signed integer sXX types
Greetings from 2017 @Wolfvak  /s
2020-10-28 00:01:36 +01:00
d0k3
f2876b2a61 Fix #628 2020-10-28 00:01:36 +01:00
d0k3
3b59b0bbfb Properly clear system saves on uninstall 2020-10-28 00:01:36 +01:00
aspargas2
bd7658a808 revert megascript refactor
because the refactor didn't work at all. my screwup.
2020-10-04 14:30:29 +00:00
aspargas2
7c01e1dfe9
allow exiting the megascript by pressing B 2020-09-26 15:27:22 -04:00
aspargas2
8e2d1d465e
update the SD cleanup section of the megascript 2020-09-24 22:09:09 -04:00
Gabriel Marcano
d010f2858b Remove trailing white space
- Removed trailing whitespace from all source code files (.c, .h. and
   .s) and the README.md
2020-08-26 23:01:58 +02:00
Gabriel Marcano
d682a65df6
Fix GCC warning, snprintf limit too long (#623)
- One snprintf in arm9/source/godmode.c call had a limit that was past
   the size of the datestr variable it was writing into. Fixed to match
   the size of the variable.
2020-08-24 23:42:56 -03:00
Wolfvak
1f2514f19e forgot to update non-FIXED_BRIGHTNESS mode 2020-08-22 17:15:10 -03:00
Wolfvak
a2e574a451 fix #622 2020-08-22 16:37:27 -03:00
aspargas2
9189320e8b
fix installing from CDN files 2020-08-20 14:31:16 -04:00
d0k3
896d548851 Additional functionality for .tie files 2020-08-20 19:43:52 +02:00
d0k3
df9b84fc66 Installer: show an error message for missing .dbs 2020-08-20 19:43:52 +02:00
d0k3
f7c229b424 Properly handle TWL saves when installing 2020-08-20 19:43:52 +02:00
d0k3
253cb2849c CIA building / installing: also take over SRL flags 2020-08-20 19:43:52 +02:00
d0k3
158fa78a5d Properly take over extdata ID when installing 2020-08-20 19:43:52 +02:00
d0k3
62fd3e93c5 TitleDB entries: add NCCH version only if DLP exists
Thanks @ihaveamac & @TurdPooCharger
2020-08-20 19:43:52 +02:00
d0k3
ffeb551a3f Don't allow game installs from images 2020-08-20 19:43:52 +02:00
d0k3
c7f10be1b4 CIA installer: only fix console ID when different 2020-08-20 19:43:51 +02:00
d0k3
f48bb58bac TicketDB mount: show console ID as big endian 2020-08-20 19:43:51 +02:00
d0k3
15bf632143 Fix building CIA from TMD 2020-08-20 19:43:51 +02:00
d0k3
50e3e1f19a Properly remount last image after searching tickets 2020-08-20 19:43:51 +02:00
d0k3
99b69754b2 Handle cleanup before installs and after failed installs 2020-08-20 19:43:51 +02:00
aspargas2
4af0268e5a visual fix 2020-08-20 19:43:51 +02:00
aspargas2
e5ffa885b6 fix directly remounting the file which is already mounted 2020-08-20 19:43:51 +02:00
d0k3
f0ad45dd60 Basic uninstaller support for title.db entries 2020-08-20 19:43:51 +02:00
d0k3
6eb546dfab Game installer: Misc code improvements 2020-08-20 19:43:51 +02:00
d0k3
18e6d9f0db Basic support for handling title.db entries
"Show title info"
2020-08-20 19:43:51 +02:00
d0k3
0af181ac6a Check for import.db and title.db before attempting install 2020-08-20 19:43:51 +02:00
d0k3
3aa9a1633a Fix game image installs to SD
Yes, I broke this (again)
2020-08-20 19:43:51 +02:00
Wolfvak
ce498103e1
change barrier ids
should allow old and bugged GM9 versions to boot the newer ones
2020-08-20 09:59:52 -03:00
Wolfvak
7edf8a998b
Merge pull request #620 from d0k3/barrier_racefix
add another pxi barrier for firmlaunch
2020-08-20 08:47:42 -03:00
Wolfvak
68a4ceac5b add another pxi barrier for firmlaunch
fixes a race condition when booting gm9 from itself (especially noticeable on new3DS consoles)
2020-08-19 23:11:45 -03:00
d0k3
0038e7d0ab Fix building via Travis CI 2020-08-16 22:31:08 +02:00
Wolfvak
03007c2b42 fix shared memory optimization problem 2020-08-15 20:30:27 -03:00
d0k3
8375434093 Properly handle TWL system data archives 2020-08-04 21:46:13 +02:00
Wolfvak
bf767f2c01
add a needed delay for new 3ds consoles (#617) 2020-08-04 16:41:10 -03:00
Wolfvak
4dc5661d58 use hardcoded configuration for ARM11 interrupts 2020-08-02 11:40:18 -03:00
d0k3
8863979a99 Merge branch 'thumb' 2020-08-02 15:43:28 +02:00
d0k3
0ee1368153 Fix building on Windows (cygwin) 2020-08-02 15:40:42 +02:00
d0k3
a051b07791 Don't allow the rom renamer in incompatible drives 2020-08-02 15:40:42 +02:00
d0k3
596e7e499c Scripting: install command for game images 2020-08-02 15:40:41 +02:00
d0k3
d4d8c9a0ff Remove force_nand from the game file installer options 2020-08-02 15:40:41 +02:00
d0k3
7fb194caea Allow batch fixing of borked NCCH crypto flags
Fixes #609
2020-08-02 15:40:41 +02:00
d0k3
521fb25075 Fix titledb entry manual detection 2020-08-02 15:40:41 +02:00
d0k3
829880994f Fix installer system CMD handling 2020-08-02 15:40:41 +02:00
aspargas2
e744be504b perform DISA/DIFF cmac fixing automatically upon unmounting 2020-08-02 15:40:41 +02:00
aspargas2
e7fdf993a7 fix some tab/space indent mixing
shame on you, @d0k3 /s
2020-08-02 15:40:41 +02:00
aspargas2
89c5107733 Fix title info entry product code for TWL titles 2020-08-02 15:40:41 +02:00
aspargas2
9766a0be5e fix handling of contents whose index and ID are unrelated 2020-08-02 15:40:41 +02:00
aspargas2
24d2a4ea5b fix install destination logic 2020-08-02 15:40:41 +02:00
aspargas2
214edfc399 don't sort tickets until a virtual ticket dir is read
this makes mounting of a ticket.db almost instantaneous regardless of number of tickets it contains
2020-08-02 15:40:41 +02:00
aspargas2
cb870d2b02 fix problems with vbdri new filename handling
this should now disallow having non-hex characters in the title id and allow changing of the NAME_TIK and NAME_TID macros
2020-08-02 15:40:41 +02:00
d0k3
d8aeb056cb Fix CMD & NCSD handling 2020-08-02 15:40:41 +02:00
d0k3
b8798f2aff Check for title.db before attempting install 2020-08-02 15:40:41 +02:00
d0k3
e559c2b4a1 Fix setting the CIA console ID 2020-08-02 15:40:41 +02:00
d0k3
32b6838d32 Fix TMD CDN CIA building 2020-08-02 15:40:26 +02:00
d0k3
8fcdde29c8 Misc code beautification 2020-08-02 15:40:26 +02:00
d0k3
77f1f94e13 Improved output for game install last step 2020-08-02 15:40:26 +02:00
d0k3
e568348086 Don't overwrite existing saves when installing
thanks @aspargas2
2020-08-02 15:40:26 +02:00
d0k3
6116545fef Fix batch install of game images 2020-08-02 15:40:26 +02:00
d0k3
e916476563 Take over @wolfvak's gameutil.c improvements 2020-08-02 15:40:26 +02:00
d0k3
d2c47b7977 Allow installation of game files
Should work for NCCH, NCSD, CIA, TMD from NUS/CDN and DSi eShop titles in NDS format
2020-08-02 15:40:26 +02:00
Wolfvak
8a7448995f fixed overlooked ARM9 exception handler issue where code would be dumped incorrectly, modified ARM11 exception vectors to not take an entire page of compiled code 2020-07-26 10:27:48 -03:00
Wolfvak
07c009de72 fix comments for bootrom functions 2020-07-24 23:38:31 -03:00
Wolfvak
f96daa407a potentially fix non-working FIRM builds, remove duplicated cycle wait functions
the sdmmc wait function is exactly the same as the one in the bootrom and worked as a drop in replacement
2020-07-24 14:22:38 -03:00
Wolfvak
f835469e19 rewrite the bootrom function header, add more operations and add ARM11 versions
- the bootrom is now mapped on the ARM11

- removed the waitClks in favor of a more canonical implementation (subs r0, r0, 4/5 + branch back)
2020-07-24 13:37:29 -03:00
d0k3
2791b42f6e Fix an exception for big file searches 2020-07-24 11:02:07 +02:00
Wolfvak
d7444e144a use a regular global pointer for sharedmem
fetching the thread id requires coprocessor access which means doing funky switches between thumb and arm -
it's faster to just allocate a single pointer and do an indirect load when necessary
2020-07-23 23:46:15 -03:00
Wolfvak
3973ce57df revert back to using Thumb code for the ARM9 binary
leads to better density and therefore much smaller FIRM sizes
2020-07-23 20:33:46 -03:00
Wolfvak
929cc7fdcf better hints to reduce compiled size by a few kb
mostly just added static const to constant arrays/buffers
2020-07-23 13:46:42 -03:00
Wolfvak
698ad9d891 fix Travis CI, take 2 2020-07-23 12:13:50 -03:00
d0k3
6b54290cf2 Fix Travis CI building (hopefully)
Thanks @vaguerant
2020-07-20 22:57:37 +02:00
d0k3
79768acef7 Fix a small typo in file attribute menu 2020-07-20 00:51:20 +02:00
Wolfvak
4e9721db9b new3DS FCRAM is always enabled nowadays, so the IS_UNLOCKED check is wrong 2020-07-19 12:08:47 -03:00
Wolfvak
5e307a3f32 limit size of initrd, fix building on msys2 2020-07-19 12:03:04 -03:00
Wolfvak
6487307cf0 improved mmu and gic code 2020-07-19 11:59:52 -03:00
Wolfvak
5905fb84fb removed the cross allocator, use the shared memory region instead for I2C and NVRAM transfers 2020-07-19 11:44:03 -03:00
Wolfvak
30f0b004c2 fixed screen init, hopefully the last commmit
- properly performs gpu/backlight reset

- nukes vram so the initrd had to be moved to arm9 memory, and have its size (at least temporarily) limited to 256k
2020-07-18 20:25:34 -03:00
d0k3
f20d2657fa Revert "Use .tie extension for titledb entries"
This reverts commit 8ee0fac6c44622c75fd2bf2fb15bf0c06662caf8.
2020-07-13 17:27:21 +02:00
d0k3
eb265e9575 NCSD CIA builder: Use proper index 2020-07-09 22:53:56 +02:00
d0k3
8ee0fac6c4 Use .tie extension for titledb entries 2020-07-09 22:51:59 +02:00
aspargas2
6e0b6d2d0a invalidate vbdri cached entry when a write fails 2020-06-30 19:22:18 +02:00
aspargas2
75cae95509 sort unsigned system tickets into the homebrew directory in ticket.db mounts 2020-06-30 19:22:18 +02:00
aspargas2
519855de5b fix write permission bypass bug
attempting to open a file in a bdri mount for reading only which did not exist but had a valid name would create the file without ever unlocking appropriate write permissions
2020-06-30 19:22:18 +02:00
aspargas2
6b6fe4741d minor visual fix
previously, it was possible to select and deselect drives on the root menu by using the shortcut keys to select all files, but this would not functionally do anything
2020-06-30 19:22:18 +02:00
aspargas2
fd4fd14ee7 allow deletion of files in virtual BDRI drives 2020-06-30 19:22:18 +02:00
aspargas2
8ffe774f77 remove remaining uses of brute-force ticket.db parsing 2020-06-30 19:22:18 +02:00
aspargas2
127008a274 fix oversight in AddBDRIEntry
this would cause an uninitialized u64 to be used for the entry size in certain circumstances
2020-06-30 19:22:18 +02:00
aspargas2
6e63fdf4bf avoid malloc(0) in vbdri 2020-06-30 19:22:18 +02:00
aspargas2
c70546d5ca implement virtual mounting of BDRI files 2020-06-30 19:22:18 +02:00
aspargas2
2b94b585eb improvements to bdri.c:
* fix a bug in ReadTicketFromDB that would fail to read tickets that were not a specific size
* fix the endianness of the title IDs outputted by ListBDRIEntryTitleIDs
* improve the speed of ReadBDRIEntry and GetBDRIEntrySize by taking advantage of the hash table
2020-06-30 19:22:18 +02:00
aspargas2
b51fc388c2 change a #include to make more sense 2020-06-30 19:22:18 +02:00
aspargas2
11c3a4a71b remove inaccurate comment
the title size field in a title info entry is infact not in bytes
2020-06-30 19:22:18 +02:00
aspargas2
fd93df60c5 deinit filesystems before booting a firm payload 2020-06-30 19:22:18 +02:00
aspargas2
77b83bc89e move structs that are only used locally from .h to .c in disadiff and bdri 2020-06-30 19:22:18 +02:00
d0k3
2fd6915075 Readme: fix an error
thanks @profi200 !
2020-06-02 17:04:32 +02:00
santiago
244d24ee2a fix compiling on dkA r54, libc is bloaty so please stick with r53 for now 2020-06-01 17:13:30 -03:00
d0k3
d6e09c9c15 Updated splash screen 2020-05-18 23:24:32 +02:00
d0k3
da1dff7cd7 Legit CIAs: Change personalized ticket warning 2020-05-18 23:24:32 +02:00
d0k3
43753535d7 Readme: Added "digital preservation" paragraph 2020-05-18 23:24:32 +02:00
d0k3
a7ce125d7f Allow building "pirate legit" CIAs (TMD & encryption intact) 2020-05-11 18:02:26 +02:00
d0k3
73dc54a754 Readme: add a note about 4GiB cart dumps missing the last byte
As asked for in #593
2020-05-11 17:19:27 +02:00
d0k3
2793daa55f Take over title version when building CIA from NCSD 2020-05-11 17:19:27 +02:00
d0k3
182f1ebe43 Fix garbage data in converted CIAs
Partial fix for #587
2020-05-11 17:19:27 +02:00
d0k3
da28c0ef40 Fix #585 2020-05-11 17:19:27 +02:00
aspargas2
c265e3ac2f fix config save dumping for citra in megascript 2020-05-11 17:19:27 +02:00
santiago
1e92163245 lazy fix for the screen init bug, hopefully 2020-05-09 16:24:40 -03:00
aspargas2
2aba1afb2e remove usm files in sd cleanup script
The unSAFE_MODE exploit that will be soon added to the 3ds guide adds a few more files that need to be removed.
2020-04-27 09:54:05 +02:00
aspargas2
52034cd41f
Always inject correct sighax signatures when installing b9s in the megascript (#592)
* megascript: always inject correct sigs when installing b9s

someone just bricked by accidentally using the dev firm because there was no check for it and this was not being done

* split up sighax literal
2020-03-30 01:08:06 -03:00
luigoalma
6541e52f05 Reinforcing alignment to buffer size 2020-03-28 07:05:42 -03:00
luigoalma
e763cbaf72 Changes to CIA building for DLC on legit cases
Ignore unowned content implied by ticket.
Standard building still should include everything due to fake ticket.
2020-03-28 07:05:42 -03:00
luigoalma
978c4f8b86 Fake ticket building changes 2020-03-28 07:05:42 -03:00
luigoalma
ccc0ddf300 Adding ability to check ticket content rights 2020-03-28 07:05:42 -03:00
luigoalma
f7b7459d9f Little stack usage optimization
Just in one function's buffer but still
2020-03-28 07:05:42 -03:00
luigoalma
d27cfc71e1 Indentation fixes
Indentation fixes everywhere
(mostly anyway under arm9/source/)
And some other tab to spaces
2020-03-28 07:05:42 -03:00
luigoalma
4e04849860 Support for variable sized tickets
Except for cia building or loading cia just yet.
Added more checks on ticket content index, mainly due to having effects
in the ticket format itself, and are unknown still.
Ability to determine ticket size.
Verify signature with ticket's proper size.
Changes to use the new Ticket struct with the flexible array member.
2020-03-28 07:05:42 -03:00
luigoalma
e0e72142bc Add BDRI function for getting size
In part, partial copy of ReadBDRIEntry changed just for getting size.
2020-03-28 07:05:42 -03:00
luigoalma
4e38973384 Fix a memory leak
When running CIA checker tool
2020-03-28 07:05:42 -03:00
luigoalma
2760bb4a38 Fixes to mymalloc functions 2020-03-28 07:05:42 -03:00
aspargas2
130ff694e2 GM9Megascript: Move payloads when moving Luma
copy luma/payloads, and remove the unneeded `-a` in the allow command because only lvl 1 perms are needed here
2020-01-02 21:08:45 +01:00
d0k3
98c1b25bb0 Allow fixing improperly decrypted NCSD/NCCH
... use "verify" for this. Also, there's a hint now when trying to CIA convert such files.
2020-01-02 21:08:45 +01:00
Wolfvak
940284c8da removed BEAT debug prints 2020-01-02 21:08:45 +01:00
Wolfvak
ce9f0a25ef add BEAT interactivity, fix typos and other small bugs 2020-01-02 21:08:45 +01:00
Wolfvak
e4b98e0932 drop in replacement for old BEAT code, not yet interactive 2020-01-02 21:08:45 +01:00
TurdPooCharger
12bc19cc43 Disarm anti savegame restore in scripts.
This stops certain games such as _Animal Crossing: New Leaf_, _Super Smash Bros._, and the _Pokemon_ series from erasing their saves due to changes in "Secure Value" after CTRTransfer or NAND restore.
2020-01-02 21:08:45 +01:00
Wolfvak
9f50d2f03c Fix #573 2020-01-02 21:08:44 +01:00
d0k3
42f7fcfb7b Improved scroll speeds for wordwrapped texts 2020-01-02 21:08:44 +01:00
Wolfvak
6fb60e007a Fix #568 2020-01-02 21:08:44 +01:00
d0k3
622d0b053c FatFS R0.14 customization: public.sav detection 2020-01-02 21:08:44 +01:00
d0k3
e446bdbfa5 Update FatFS R0.13c -> R0.14 2020-01-02 21:08:44 +01:00
aspargas2
9e1b5e0be2 add a9lh stage2 payload removal to hax uninstall 2020-01-02 21:08:44 +01:00
aspargas2
7729605f9a fix #563 2020-01-02 21:07:22 +01:00
d0k3
e58760231a Fix building with FIXED_BRIGHTNESS
@thanks uwabami
2020-01-02 21:07:22 +01:00
d0k3
479fed35ef Further improvements to GBA VC save injection
... taking over @TurdPooChargers proposal.
2020-01-02 21:07:21 +01:00
d0k3
23a7ea7fd3 Beautified the GBA VC SD save handling code 2020-01-02 21:07:03 +01:00
d0k3
da412226be Fix #562 2020-01-02 21:07:03 +01:00
d0k3
cfae228bcf Disarm anti savegame restore on CTRtransfer 2019-10-28 22:31:21 +01:00
TurdPooCharger
a145e8d4a9 Add handling for SD GBA VC .sav CMAC.
When identifying a selected `00000001.sav`, cmac type testing is first attempted for 3DS saves with the **DISA** format. If a 3DS save data is not detected, the search continues at expected offsets for gba vc bottom slots in increasingly larger save sizes. For the GBA VC saves, this only calculates and corrects whichever of the two slots is newer or has the higher counter. There are five additional **CMAC_AGBSAVE_** types to differentiate the different gba save sizes. If a bottom slot was found but determined to be older based on comparing the counter values, the search defaults to **CMAC_AGBSAVE_SD**.

For the save counters, there are two scenarios where the value `00` is considered bigger than `FF` depending which slot has what value. If clarification is required, I will post a diagram at [issue #494](https://github.com/d0k3/GodMode9/issues/494) explaining what is meant by `00` bigger than `FF`.

Please make corrections and improvements to the coding as you see fit in your review. I am not well versed or efficient in the C/C++ programming language.
2019-10-28 21:47:43 +01:00
Wolfvak
499e301b7b - fix #555
- remove useless free(NULL) check
2019-10-28 14:16:55 -03:00
d0k3
624ac571e4 Improve GBA VC save injection
... see #548
2019-10-28 14:16:55 -03:00
d0k3
1889f4fd57 Simplify fsdrive code 2019-10-28 14:16:55 -03:00
d0k3
f184ad5701 Fix #554 2019-10-28 14:16:55 -03:00
d0k3
cfe535f20b Fix #551 2019-10-28 14:16:55 -03:00
Wolfvak
cf7fa9e401 Fix #549 2019-10-28 14:16:55 -03:00
Bálint Kovács
2e463c6b84 Change timeout on CardSPIWaitWriteEnd (#557)
Allows long waits for erase on things like Art Academy, but fails faster
elsewhere. In particular initialization fails almost instantly.
2019-10-26 09:12:18 -03:00
d0k3
2b05453685 Increase splash duration
Partial fix for #550
2019-10-20 22:57:36 +02:00
d0k3
1ceba1ed6f Update issue templates 2019-10-19 15:03:58 +02:00
d0k3
ae583300e6 Don't show the JEDECID file on carts that have none 2019-10-17 19:51:05 +02:00
d0k3
9e72c098b9 Make gamecart handling a little less annoying 2019-10-15 23:08:06 +02:00
d0k3
c847618048 Some minor cleanup 2019-10-14 23:48:15 +02:00
d0k3
422e54dca4 FIRMInstaller: Remove crypto check
... this interfered with installation to corrupted partitions and is no more required anyways.
2019-10-14 22:18:00 +02:00
Wolfvak
0f42426115 Fix unaligned crypto buffers 2019-10-14 13:11:23 -03:00
Wolfvak
915cb2d13e Hopefully fix #466 - now it resets the GPU/LCD into a known state instead of leaving the previous one on 2019-10-13 18:32:41 -03:00
Wolfvak
4890e4116f Remove repeated credit 2019-10-13 13:47:01 -03:00
Glazed_Belmont
5d61bebb25 added credits from the essential.exefs script (#547)
we both thought and wrote the script, so I thought the addition of the names would be great
2019-10-13 13:45:31 -03:00
Wolfvak
744ab6934b Integrate unmark into the release target 2019-10-13 13:43:35 -03:00
Death Mask Salesman
b32b63da27 Add Unmark as an external tool (#546)
`unmark` is a tool to produce an user manual from the `README.md`.

The `patch.json.gz` file contains a list of patterns to match and
their replacements.
If `unmark` complains about being unable to match a pattern, please open
an issue with the warning and your `README.md` at
[upstream](https://github.com/DMSalesman/Unmark).
2019-10-13 13:33:31 -03:00
DMSalesman
6d8226ac5e Update user manual 2019-10-12 17:32:36 +02:00
d0k3
a4270eda56 GM9MegaScript: Added essential.exefs dumping
... so I got at least one commit in that script.
2019-10-12 17:31:47 +02:00
d0k3
f24db1442e Fix #543 2019-10-12 17:14:16 +02:00
d0k3
0ec73520e6 Rewrote the dir/file/drive info dialogue 2019-10-12 17:10:33 +02:00
d0k3
dc746f69c5 Readme updates for changed stuff 2019-10-11 16:28:07 +02:00
Balint Kovacs
c1b04d85d4 Fix jedecid_and_sreg.bin offset reads 2019-10-11 16:24:08 +02:00
Balint Kovacs
2f24f37e7b Temporarily disable IR carts
And massively simplify chip detection
2019-10-11 16:24:08 +02:00
Balint Kovacs
c51d8a7191 Fix Art Academy save writing
Apparently, at least in my copy, the flash chip has a chance to fail a
PP command, and just never complete it. So we just try again.
2019-10-11 16:24:08 +02:00
Balint Kovacs
0308dfdebc Get rid of card_eeprom.c for real
Rebase brought it back
2019-10-11 16:24:08 +02:00
Balint Kovacs
f624850465 Handle errors when reading JEDEC ID vfile 2019-10-11 16:24:08 +02:00
Balint Kovacs
aea79aa634 Cut back on card definitions
Saves 400 - 440 bytes of .data
2019-10-11 16:24:08 +02:00
Balint Kovacs
bef427dfdb Code formatting for card_spi.c 2019-10-11 16:24:08 +02:00
Balint Kovacs
84d5f800a9 Get rid of card_eeprom.c, move spi.c to card_spi.c
It was bugging me that there was two spi.c's
2019-10-11 16:24:08 +02:00
Balint Kovacs
d2f596e7a3 Merge ARM11 spi and ARM9 spicard drivers
Also centralize device IDs into SPI.h
2019-10-11 16:24:08 +02:00
Balint Kovacs
48d8c48d12 Completely refactor SPI.h, write CTR flash
Also (hopefully?) write Art Academy, and also implement sector-based
write on Sanyo 256K chips.
2019-10-11 16:24:08 +02:00
Balint Kovacs
004341e1ef Add a little utility to test gamecard flash chips 2019-10-11 16:24:08 +02:00
Balint Kovacs
fa741b265b Write support for NTR saves
Why does this work? We are writing flash memories without erasing them,
and writing pages without regard to alignment. Yet it works?
2019-10-11 16:24:08 +02:00
Balint Kovacs
38d9a23427 Minor cleanup of gamecart.c 2019-10-11 16:24:07 +02:00
Balint Kovacs
7b0a101f13 Add read support for CTR cartridge saves
I have done nothing, however, to decrypt them. There is also no write
support.
2019-10-11 16:24:07 +02:00
Balint Kovacs
f60a4c1f63 Add a vfile to show the JEDEC id for the inserted cart
This is meant to replace the Prompt I was using previously.
Fun fact: WarioWare DIY seems to have *something* on the SPI bus, as it
returns an ID of 0x000001 consistently. Or am I just glitching the
parallel flash? Or did I get a fake?
2019-10-11 16:24:07 +02:00
Balint Kovacs
fd48c95deb Add a timeout to SPIWaitWriteEnd
Solves the WarioWare issue
2019-10-11 16:24:07 +02:00
Balint Kovacs
556c75c337 Fix many bugs by simplifying SPICARD init
* Fixed card reading (I didn't notice I broke it)
* Fixed cart swapping
* Still unsupported: CTR carts
* Still hangs if cart has no SPI flash (see WarioWare DIY)

The initialization code was simplified to only enable the SPICARD
interface, which assumes the *TRCARD interface has been initialized
beforehand.
To keep things simple, I just wrapped SPIWriteRead with SPICARD_Init and
SPICARD_deinit (which does the exact opposite)
2019-10-11 16:24:07 +02:00
Balint Kovacs
ac4ec6ee90 spicard.h: use void* pointers
First initialized cart reads correctly now, and cardswap just hangs.
2019-10-11 16:24:07 +02:00
Balint Kovacs
2ceafc545b First viable(-ish) prototype
For some reason (messed up memory access?) the first two time I read the
status register, I get garbage.

Also:
* Reinserting card breaks SPI (everything reads 0xff
* No support for CTR carts for now
2019-10-11 16:24:07 +02:00
d0k3
a3cc272e63 Try to fix the infloop
Debug output (revert this later)
2019-10-11 16:24:07 +02:00
d0k3
01bc082ca0 Initial support of cartridge savegame reads 2019-10-11 16:24:07 +02:00
Wolfvak
beb2a881cd fix compilation warning due to ternary operator results having differing signedness 2019-10-09 22:31:09 -03:00
Chromaryu
d4cd60eccf Travis: Enable Sudo-safe container (#544)
Use latest ubuntu distribution, this time Bionic.
2019-10-09 20:36:11 -03:00
d0k3
2372340e6d Updated touchscreen playground 2019-10-06 22:28:57 +02:00
d0k3
392b59976b Got rid of the Testing menu
... (hint) also hiding a secret here
2019-10-06 14:02:05 +02:00
d0k3
00c0dac479 Fix notification LED color 2019-10-05 20:00:14 +02:00
d0k3
5799d99c4c Fix installing FIRMs 2019-10-04 18:26:08 +02:00
d0k3
760052f20d Fix #541 2019-10-03 17:04:35 -03:00
d0k3
e7948d9a2f Fix entering the boot menu in bootloader 2019-10-03 17:04:35 -03:00
Wolfvak
891c0c2a36 adjust stack and code dump lengths to be more useful in real life 2019-10-03 17:04:35 -03:00
d0k3
1633961707 Allow game icons as preview for scripting 2019-10-03 17:04:35 -03:00
d0k3
0e701ea719 Fix flavor colors 2019-10-03 17:04:35 -03:00
Wolfvak
a9624b6d81 fix a potential mcu bug 2019-10-03 17:04:35 -03:00
Wolfvak
ea26510402 remove unnecessary parameters being passed 2019-10-03 17:04:35 -03:00
d0k3
622fb38223 Fix compiler warnings (thanks @aspargas2) 2019-10-03 17:04:35 -03:00
d0k3
85c43795c3 Partially fix #537 (two fixes make one) 2019-10-03 17:04:35 -03:00
Wolfvak
47312797e2 Partially fix #537
if size was zero, the inputstr array could contain stack garbage
2019-10-03 17:04:35 -03:00
Wolfvak
53708e64dc
Fix Travis, take 3 2019-10-03 08:13:35 -03:00
Wolfvak
380d3ced7a Fix Travis CI, take 2 2019-10-01 17:18:16 -03:00
Wolfvak
db9b2cf8ec Reinstate Travis CI, take #1 2019-09-29 22:12:51 -03:00
aspargas2
97fed0a284 vdisadiff: reduce memory usage when fixing hashes, and fix an alignment bug 2019-09-29 19:53:30 +02:00
aspargas2
85960298e4 add wwylele and myself to the credits
because Wolfvak said I could :3
2019-09-29 19:53:30 +02:00
aspargas2
50770616d7 refactor bdri to operate on a file representing the diff ivfc lvl4
intended use here is now to mount the diff file as an image, then use bdri calls on partitionA.bin
2019-09-29 19:53:30 +02:00
aspargas2
f8b9332728 implement vdisadiff 2019-09-29 19:53:30 +02:00
aspargas2
1026a60597 add virtual disadiff mounting code 2019-09-29 19:53:29 +02:00
aspargas2
7322e31f43 refactor disadiff to cater more nicely to a vdisadiff 2019-09-29 19:53:29 +02:00
aspargas2
0283692e83 add BDRI handling 2019-09-29 19:53:29 +02:00
aspargas2
0b3b5529f2 add DISA/DIFF writing
this has only been tested with DIFF, specifically title database type files, but there's no reason it shouldn't work on all DISA/DIFF files
2019-09-29 19:53:29 +02:00
Wolfvak
fd5320b86f - properly align ARM11 stacks and buffers
- add very simple exception dumping for the ARM11
2019-09-29 19:53:28 +02:00
Wolfvak
3e25393284 fix #539
saner new3DS vs old3DS detection
2019-09-29 19:53:28 +02:00
aspargas2
398c7fd14c fix null pointer deref when cancelling ticket.db mounting
take 2
2019-09-29 19:53:28 +02:00
Wolfvak
2ef408f4af fix broken cross-buffer assumption, check nvram reads 2019-09-29 19:53:28 +02:00
Wolfvak
1a0fe17b6c better FIRM checks, fix unchecked NULL that triggered a data abort 2019-09-29 19:53:28 +02:00
Wolfvak
c8a7c63963 fix unicode FAT labels (#508) 2019-09-29 19:53:28 +02:00
d0k3
e6b63f328b Store manual calibration data in a support file 2019-09-29 19:53:28 +02:00
Wolfvak
cb4ea7217a fix entrypoint detection algo (nandboot, #514) 2019-09-29 19:53:27 +02:00
Wolfvak
524a86e9a4 fix issue #512 2019-09-29 19:53:27 +02:00
Wolfvak
d6c6f56526 fix compilation warnings due to unaligned packed structures in newer gcc 2019-09-29 19:53:27 +02:00
Wolfvak
88751ab96a refactor build system code to allow common code to be built for each target 2019-09-29 19:53:27 +02:00
Wolfvak
07b2a2beb6 fix backwards compatibility with software that exclusively uses the old SPI interface
fix PXI acknowledgement bug that prevented older GM9 from booting
2019-09-29 19:53:27 +02:00
Wolfvak
3061da4dcc Refactor file/dir/drive information dialog and attribute setting
Now allows directory attributes to be set
2019-09-29 19:53:26 +02:00
Ian Burgwin
506a3d3089 Makefile: call firmtool as a PY3 module (#535)
Calling firmtool directly may not work as expected on Windows, where
Python is not added to PATH by default. However, the py launcher is
always added to a directory in PATH by default.

The only downside is that firmtool with Python 2 will not automatically
be called. Since Python 3.5 is required for add2tar, however, this
shouldn't be an issue.
2019-09-14 11:33:12 -03:00
Bálint Kovács
3c8fe0f69d Get rid of extra copy of readme (#504)
See 9ab9c01
2019-07-07 01:12:02 -03:00
Wolfvak
e87f69dc20 Fix setting file attributes 2019-07-05 23:59:06 -03:00
Bálint Kovács
8f588fa8bc Fix crashes when opening extensionless files. (#503)
* Set extension to an empty string when there's none
2019-07-05 23:35:41 -03:00
d0k3
3cbbd53850 Fix the software keyboard
Fixes #501
2019-07-01 23:03:35 +02:00
d0k3
e7e800d44f Fix booting FIRMs from scripts 2019-06-30 23:51:15 +02:00
d0k3
9a7ff738be Show "NOLABEL" for unlabeled SDs 2019-06-30 23:51:15 +02:00
d0k3
4e61bcaa50 Mark the cart drive as uninitialized when uninitialized
Fixes #492
2019-06-30 23:50:55 +02:00
d0k3
ccb8531ce6 swkbd: Fix deleting the last char in a string 2019-06-30 23:50:54 +02:00
d0k3
d928591a80 sdmcc.c: Longer delay on SD init (thanks @profi200) 2019-06-30 23:50:54 +02:00
d0k3
1403dc8ef9 Improved touchscreen playground 2019-06-30 23:50:45 +02:00
d0k3
dc9dc794b0 Added brightness setting dialogue to HOME more.. menu, some minor adaptions 2019-06-30 23:50:44 +02:00
d0k3
ab110bf73d Improved legit CIA build warning 2019-06-10 16:54:19 +02:00
d0k3
87d4152d4e Add handling for SD / TWLN & DLC CMD CMACs
Fixes #340
2019-06-10 16:30:40 +02:00
Wolfvak
bd74ad00d8 add initial brightness config dialog, currently inaccessible 2019-06-07 17:13:42 -03:00
Wolfvak
04bf6438de lowered circle pad sensitivity on the horizontal axis 2019-06-03 02:28:27 +02:00
d0k3
40b4e3f541 Use software keyboard instead of string input prompt 2019-06-03 02:28:27 +02:00
d0k3
ee86ffeb03 Remove old touch playground code 2019-06-03 02:28:27 +02:00
d0k3
73e3a18ea8 Remove legacy A9LH support 2019-06-03 02:28:27 +02:00
d0k3
ff491f2993 Scripting: allow NO_CANCEL flag for fill command 2019-06-03 02:28:27 +02:00
d0k3
ae5584aca0 Fix displaying alphabet preview in input tool 2019-06-03 02:28:27 +02:00
Wolfvak
b45bb966df fixed an off by one error in the UI code that caused all rectangles to be drawn one pixel lower than indicated 2019-06-03 02:28:27 +02:00
Wolfvak
648275c097 - rewrote the entrypoint detection code for clarity and size
- fixed a dumb bug during mpu setup
2019-06-03 02:28:27 +02:00
Wolfvak
f179caaef3 removed useless stack clearing and whitespace 2019-06-03 02:28:27 +02:00
Wolfvak
ca7944ce04 - enable the VFP on the ARM11
- stopped using the ITCM as the interrupt vector table
- removed dead Thumb code handler in interrupt handling
- added basic memory protection flags
2019-06-03 02:28:26 +02:00
Wolfvak
8b098fa91a improvements over the last couple of RGB565 related commits 2019-06-03 02:28:26 +02:00
Wolfvak
256f2465d8 converted all bitmaps to RGB565 2019-06-03 02:28:26 +02:00
Wolfvak
a42dbedf82 fix screenshot functionality 2019-06-03 02:28:26 +02:00
Wolfvak
6823e15584 enable write buffering on VRAM, optimize some UI drawing algorithms 2019-06-03 02:28:25 +02:00
Wolfvak
bb5182cae3 skip unnecessary fixed point conversion + multiplication in touchscreen reading code 2019-06-03 02:28:25 +02:00
Wolfvak
6dc89d7107 compile time fixed brightness bugfix, reinstated command to set brightness from ARM9 2019-06-03 02:28:25 +02:00
Wolfvak
50e97d2dab Moved most things to RGB565 2019-06-03 02:28:25 +02:00
d0k3
73d8d14bd5 Fix #478 2019-06-03 02:28:25 +02:00
d0k3
dbd8b8aca8 Included software keyboard in testing 2019-06-03 02:28:25 +02:00
d0k3
ca8c2070f5 Change how TouchboxGet() works 2019-06-03 02:28:25 +02:00
d0k3
f4fc17f145 Tweak button delay in hid.c 2019-06-03 02:28:24 +02:00
Wolfvak
7d3a5270f1 fix lodepng CRC calculation 2019-06-03 02:28:24 +02:00
d0k3
9cc31b6f56 Fix several alignment assumptions 2019-06-03 02:28:24 +02:00
d0k3
c3152838db Move touchbox functions to hid.c / hid.h 2019-06-03 02:28:24 +02:00
Wolfvak
2f64a8046a - compile with size optimizations, reduces inst cache pressure
- removed most of lodepng's optional features
- lodepng now uses the already existing CRC32 code instead of using its own copy
- fixed GIC interrupt priority
2019-06-03 02:28:24 +02:00
d0k3
cadc7e6982 Revert to old splash logo 2019-06-03 02:27:44 +02:00
d0k3
ff9fde1561 With shell closed, use the LED to signal finished operations 2019-06-03 02:27:44 +02:00
d0k3
85a189b3b6 Move testing stuff to its own menu entry 2019-06-03 02:27:44 +02:00
d0k3
df21331218 New & improved touchscreen playground 2019-06-03 02:27:44 +02:00
Wolfvak
77f857ab64 - added way to prevent a race condition when reading the touchscreen values
- simplified CODEC init and read code
- fixed I2C register

thanks to @profi200 for the last two points
2019-06-03 02:27:44 +02:00
d0k3
dad662610d Moved touch testing functions to HOME -> more... 2019-06-03 02:27:44 +02:00
d0k3
54caa3588e Added touchscreen calibration from NVRAM (thanks @wolfvak) 2019-06-03 02:27:44 +02:00
d0k3
36c03e578c Enable screenshots in touch test functions 2019-06-03 02:27:44 +02:00
d0k3
500333b011 Some source code reorganisation 2019-06-03 02:27:43 +02:00
d0k3
bc66cd0ccf Improved touchscreen calibration GUI & playground 2019-06-03 02:27:43 +02:00
Wolfvak
08b53f71e1 Fix clobbered registers on MRC/MCR/MRS/MSR C wrappers
Previously the compiler could've optimized stores/reads to be placed outside of critical sections, etc
2019-06-03 02:27:43 +02:00
Wolfvak
a6734af45d licensing bs 2019-06-03 02:27:43 +02:00
Wolfvak
46a5735f5c - fixed bug where a N3DS without extra FCRAM enabled would get stuck on boot 2019-06-03 02:27:43 +02:00
Wolfvak
ad9a9bd5a0 - turn off the LCDs when the lid closes, and turn them back on when it's open
- reset LEDs on boot
- add code to set the notification LED
- add a PXI command to verify the NVRAM is actually online
- notify the ARM9 about the shell state through the HID thing
2019-06-03 02:27:43 +02:00
Wolfvak
79aa9191f7 - clamp down the touchscreen coordinates to boundaries
- fix annoying compilation warning regarding unsigned vs signed comparison
2019-06-03 02:27:42 +02:00
Wolfvak
70757e3385 - added extremely simple calibration dialog, to be replaced by something prettier/saner/safer at a later point in time
- moved all SPI code to the ARM11
- reimplemented NVRAM reading for the new SPI interface
2019-06-03 02:27:42 +02:00
Wolfvak
b52bf3b9a5 refactored SPI and CODEC drivers, getting ready to move all SPI ops to the ARM11 2019-06-03 02:27:42 +02:00
Wolfvak
1b04ca4fa1 - added touchscreen calibration code
- added very simple 12-bit precision fixed point arithmetic code as a fast float replacement
2019-06-03 02:27:42 +02:00
Wolfvak
bf45ee3900 - added new SPI and CODEC drivers ported from linux, thanks to xerpi
- circle pad simulates dpad keys (up, right, down, left)
- raw touchscreen data is provided but currently unused
- added a simple shared memory region thing
- fixed the 10ms delay to be _after_ the backlights are turned on, thanks to profi again

as always, other stuff I probably forgot about
2019-06-03 02:27:42 +02:00
Wolfvak
bcff09a389 added a small 10ms wait before turning on the backlight, thanks to profi for reminding me of that 2019-06-03 02:27:42 +02:00
Wolfvak
f5a877d00b - implemented MCU stuff and its interrupts, thanks @profi200 for the info
- moved brightness control to the ARM11
- moved HID updating to the ARM11
- moved screen init from ARM9 to the ARM11, always performed unconditionally
- removed unnecessary SCREENINIT and SET_BRIGHTNESS pxi commands

and other stuff I probably forgot about
2019-06-03 02:27:41 +02:00
Wolfvak
5e56cd2f77 - refactored arm11/sys.c
- moved common.h from the ARM9 tree to the common code tree
- does proper deinit now on the ARM11 side

the bug that caused it to fail to launch some FIRMs has been fixed - it can even boot stock FIRMs
2019-06-03 02:27:41 +02:00
Wolfvak
016eac6982 - properly set up MMU tables with caching and other fun stuff
- maps a regular ARM-style exception vector table instead of using the bootrom vector redirection

features a ton of bugs because I'm missing something, it actually manages to boot fb3DS v1.2 and BAX fine, but fails to boot itself
2019-06-03 02:27:41 +02:00
Wolfvak
2f86686388 renamed most low level functions and other stuff to fit with the current theme
- added initial SCU twiddling
- added very untested and unusable SMP code
- fixed race condition that happened on boot
- added initial MMU code (just super basic identity mapping, no caching set up or anything)
- enabled some of the fancier ARMv6 features
- reorganized ARM11 files into their own folders
- possibly more stuff I'm forgetting about
2019-06-03 02:27:41 +02:00
Wolfvak
e70b8ab116 - unified CPU/cache header that works on C and asm code
- added legacy boot PXI command that allows power savings on ARM11
2019-06-03 02:27:41 +02:00
Wolfvak
987b820c4a beginning of better ARM11:
- moved I2C code to the ARM11 (with an ugly hack that MUST be fixed)
- reworked the PXI protocol to have lower latencies and remove any potential async support
2019-06-03 02:27:41 +02:00
DMSalesman
9ab9c01aae Update user manual 2019-04-30 13:38:27 +02:00
d0k3
602b6fc7df Updated readme file, recommend fastboot3DS as bootloader 2019-04-29 00:30:08 +02:00
Wolfvak
796457e54c Restored autodependency generation 2019-04-19 15:19:37 -03:00
d0k3
c86ebe4baa CIA checker tool: properly detect custom TMD 2019-04-17 00:45:48 +02:00
d0k3
151e6389ac Use iomemcpy for registers (thanks @profi200) 2019-04-17 00:45:48 +02:00
d0k3
afd2c6593c Updated GM9Megascript.gm9
Thanks @annson24, @Validusername16 and @eip618! Merges #468
2019-04-16 00:50:24 +02:00
luigoalma
6a95643edb Very minor optimization
It only effect happens at common misaligned memory check and fixup
Does the exact same end result, just in less 2 instructions and independent of r4 and r5, using r12 instead
2019-04-16 00:41:31 +02:00
d0k3
ce71e56a52 Added third anniversary edition splash 2019-03-21 01:57:07 +01:00
d0k3
10425bfa03 Fix LTO related compiler warnings 2019-03-21 01:57:07 +01:00
d0k3
d4e7f092fa Reenabled LTO (fixed in dkA r52) 2019-03-21 01:23:13 +01:00
d0k3
d762c390af CPPCheck audit, several fixes 2019-03-21 00:42:39 +01:00
d0k3
539099db81 Fix compiling script runners 2019-03-20 23:53:50 +01:00
d0k3
21fdb9543a Added ability to convert DSiWare .nds to CIA
Fixes #465
2019-03-20 02:07:34 +01:00
d0k3
f51a48c39e sha.c: add volatile keyword where required 2019-03-19 00:20:10 +01:00
d0k3
89e9aceaaf Use ARM instead of Thumb for ARM9 core 2019-03-15 01:05:23 +01:00
luigoalma
1e2b45941b revert seqmemcpy and memcpy reimplementation 2019-03-15 00:48:24 +01:00
Eix
c644820e41 re-order the keyboard string to make renaming stuff less annoying 2019-03-15 00:34:42 +01:00
windows-server-2003
732165153b Implemented new file selector 2019-03-15 00:34:41 +01:00
d0k3
d50e6b88ae Scripting: add dumptxt command 2019-03-14 01:50:27 +01:00
d0k3
82d6e94789 Fix compiling in devkitARM r51
Use custom (sequential) memcpy for reading / writing hardware registers.
Fixes #460
2019-03-13 01:36:33 +01:00
d0k3
10ec95b8fe Fix #455 2019-02-12 00:03:55 +01:00
d0k3
a04c2beb3c Scripting: Add textview command 2019-01-16 01:26:40 +01:00
d0k3
0906b4e6d8 Update FatFS to R0.13c 2019-01-09 01:05:48 +01:00
DMSalesman
e8c853a384 Update user manual 2019-01-03 00:19:24 +01:00
d0k3
223d327fca README: Mention POWER as altenative to HOME
fixes #449
2019-01-02 01:00:31 +01:00
d0k3
d4ea225677 Offer fixing of BOSS files on failed verification
Fixes #442
2018-12-08 18:12:25 +01:00
d0k3
75a23a15c3 Show cart ID and type on cart drive
Fixes #435
2018-11-05 00:19:41 +01:00
d0k3
f13a5c6e4f Safety measure for scriptrunners: 0:/iderped.firm
see: https://github.com/ScarletStudy/DGS1-3DS-Release/issues/47
2018-10-31 00:19:13 +01:00
d0k3
71d0cecf20 Fix copying to virtual NAND 2018-10-29 01:33:20 +01:00
d0k3
9f25b6cf25 Improved TMD checks 2018-10-29 00:04:23 +01:00
d0k3
e7de8b9ca3 CIA builder: Better handling for personalized legit tickets 2018-10-24 00:21:39 +02:00
d0k3
449a89277e ticket.db: fix out of bounds reads 2018-10-23 01:47:16 +02:00
d0k3
2b8d4fcc04 Don't remove TMD crypto flags on non-existing contents 2018-10-18 00:11:07 +02:00
d0k3
762edd5432 Fix mounting incomplete DLC CIAs 2018-10-16 01:00:03 +02:00
knight-ryu12
f58bb6e61b Make N_PANE definable 2018-10-08 01:44:35 +02:00
d0k3
e477ec0a18 Fix compile errors introduced by bfc3363
Fixes #432
2018-10-02 18:42:04 +02:00
annson24
0286d9cde9 Fixed Setup Luma to CtrNAND
Fixes #427, merges #430
2018-10-01 23:54:51 +02:00
d0k3
bfc3363012 Improved / fixed DirStruct entry name handling
Fixes #431
2018-10-01 23:51:05 +02:00
d0k3
8f24ccec0c Full / proper verification for romFS in NCCH 2018-09-25 01:42:52 +02:00
Hyarion Sanyënóna
5c138e1219 Add scripting commands extrcode, cmprcode, cp -p
* extrcode already existed, but now has a progress bar and an entry in HelloScript.
* cmprcode recompresses a code binary into its original format. It takes 2-3 minutes.
* cp -p appends file 2 to the end of file 1 rather than overwriting it.
2018-09-19 00:47:28 +02:00
d0k3
2d807915e6 SortDirStruct workaround for T_DOTDOT and T_ROOT 2018-09-18 01:30:44 +02:00
windows-server-2003
9c4ff77476 Improved file loading time 2018-09-18 00:33:26 +02:00
d0k3
29b05aee54 Less strict checks for AGBSAVE
This fixes weird issue #412
2018-09-11 00:00:24 +02:00
d0k3
619242ef96 Improved verification for TMD 2018-09-05 23:53:45 +02:00
d0k3
a05cc1ff56 Properly verify CFA NCCHs
Also fixes NCSD verification
2018-09-03 22:55:37 +02:00
d0k3
cbe473450f Improve virtual romfs memory handling
Fixes #425
2018-09-03 21:44:16 +02:00
d0k3
b8b2c026ac Protect firmlaunch parameters in bootloader
Fixes #424
2018-08-30 16:41:40 +02:00
d0k3
79a00b09f9 Use correct crypto for padding in ExeFS
Fixes #413
2018-08-29 00:07:38 +02:00
d0k3
14c97a7f6b sdmmc.c: Corrected OCR register value on SD init to the one from Process9
Thanks @profi200 !
2018-08-27 00:26:46 +02:00
d0k3
31fd7f88e9 Fix a small issue with relocking write permissions 2018-08-26 23:06:54 +02:00
d0k3
e7a1a72333 Protect S:/essential.exefs file
Fixes #418
2018-08-26 23:06:32 +02:00
annson24
760238e3f4 GM9 Megascript Fixes
- Fixed Emunand not restoring.
- Fixed a minor bug when exiting Title Options, it exits directly to the Main Menu instead of Misc. Menu.
- This fixes #420
2018-08-26 22:30:40 +02:00
d0k3
e44d266d94 Increase # of panes to 3
fixes #414
2018-08-13 00:13:29 +02:00
d0k3
3446a43127 Added CIA Checker Tool 2018-08-13 00:08:56 +02:00
d0k3
9467bd6050 Fix verification and decrypt for incomplete DLC CIAs 2018-08-10 14:59:23 +02:00
d0k3
e75c25e41d Fix #411 2018-08-06 23:22:16 +02:00
d0k3
5e51805ea0 Allow handling of DLC CIAs with up to 1000 contents 2018-08-02 01:23:56 +02:00
d0k3
9a227b92bf Ability to setup a default font 2018-08-02 00:43:33 +02:00
d0k3
03d1255aaa Allow batch trimming of NDS/NCCH/NCSD/FIRM/NAND images 2018-08-01 01:34:12 +02:00
TheGinGear
df67d1de58 Update NANDManager.gm9
Just a quick fix, replaced the old keysel command
2018-07-30 11:49:50 +02:00
d0k3
f40ec898cf Also include derreks sighax signature
in the source, currently not used
2018-07-30 01:03:15 +02:00
DMSalesman
99af6a73be Added refined internal user guide
This commit adds an edited README.md to be built into GM9 as user guide.

The scrubbed parts include refs to the GM9 banner, unused MarkDown and
the whole "How to build this / developer info" block.

Links have been replaced with their corresponding anchor text, when
replacing them could be done without altering the sentences' original
meaning.

Certain parts have been further altered, such as the "License"
paragraph, which now includes the full link to GM9's "license.txt".
2018-07-26 00:46:02 +02:00
d0k3
b897d15474 Readme updates 2018-07-25 00:14:14 +02:00
d0k3
09bef518b5 Fix GW EmuNAND / RedNAND user selection
Fixes #399
2018-07-24 01:28:24 +02:00
d0k3
3956e8ab91 Prevent wrong recognition of GW type EmuNANDs 2018-07-23 22:20:20 +02:00
d0k3
c78e5b97a6 keysel -> labelsel -k 2018-07-23 01:03:50 +02:00
DMSalesman
ae8c27fcad Celebrating commit no. 1024: Fixed readme typos 2018-07-23 01:03:07 +02:00
d0k3
6a04bfca67 Safety checks for dummy file / dir creation 2018-07-18 00:16:41 +02:00
d0k3
bc5f187a0f FIRM installs: clarify sighax injection
Fixes #397
2018-07-16 17:02:26 +02:00
d0k3
81ad8a2c1e Add trimmer tool for FIRM, NAND images, NCSD, NCCH, NDS
Fixes #392
2018-07-16 01:07:59 +02:00
Steveice10
f9ece57eb0 Fix dumping DLC to CIA. 2018-07-10 01:05:34 +02:00
d0k3
794800fb83 Check the results after a file entry rename 2018-07-04 22:52:10 +02:00
d0k3
5880777e18 diskio.c: use the correct error codes 2018-07-04 22:51:43 +02:00
d0k3
f74d9ddfd7 Include ARM9 footer when mounting .nds files 2018-06-27 01:33:17 +02:00
d0k3
ff86444e2c Scripting: nextemu command and EMUBASE global var 2018-06-25 23:19:44 +02:00
d0k3
e4352d4cb0 Updated gamecart reset routines
thanks @profi200
2018-06-25 23:14:17 +02:00
Hyarion Sanyënóna
a6305206e0 Buffer all BPS, IPS, CRC32 reads in chunks of 1 MB or less 2018-06-18 00:03:12 +02:00
d0k3
5df5ead553 Add support for setting up Multi RedNANDs 2018-06-17 23:53:29 +02:00
windows-server-2003
c10f6d1f9e Fix potential buffer overflows 2018-06-14 12:37:42 +02:00
Hyarion Sanyënóna
ffa5eaaae4 Progress bars will not draw to screen faster than 30 Hz 2018-06-14 00:44:43 +02:00
annson24
5c87f61880 Include GM9Megascript in GodMode9 resources
Collective scripts for GodMode9.
2018-06-13 13:55:43 +02:00
d0k3
2beb92305c Make renamer error message less misleading
Fixes #386
2018-06-13 13:27:11 +02:00
d0k3
63120f8a79 Workaround for dumping NTR-AKRJ-JPN
... this cart has a broken header, thus trimming is not possible.
2018-06-07 00:26:03 +02:00
d0k3
28c2f7b06e Actually wipe card2 gamecart savedata when dumping 2018-06-05 00:55:46 +02:00
d0k3
bdf635e39d Fix a potential buffer overflow
thanks @windows-server-2003 !
2018-06-04 00:52:45 +02:00
d0k3
0cbcce5579 sdmmc.c: Adjust eMMC clock to be in spec before switching to HS mode
.. and some cleanup
2018-06-04 00:52:44 +02:00
d0k3
568db1d471 Updated sdmmc.c driver with support for faster reading/writing
thanks @profi200
2018-05-31 23:21:48 +02:00
d0k3
5b72bfdf16 Shift-JIS workaround for NDS image mounting
Fixes #368
2018-05-24 16:59:37 +02:00
d0k3
8898909b04 Temporarily disable Travis CI 2018-05-24 01:11:42 +02:00
d0k3
a4a7b8f1e0 Fix GCC v8.1 (new dkA) warnings
... this also fixes #371
2018-05-24 01:08:00 +02:00
SirNapkin1334
795716957e Celebrating commit no. 1000: Improved readme fix 2018-05-23 23:27:33 +02:00
d0k3
a981b4375e Fix readme file
Thanks @PC-Reviver
2018-05-23 00:30:06 +02:00
windows-server-2003
46f67e1d18 Fix sprintf format vulnerability 2018-05-17 00:29:03 +02:00
d0k3
5b413a9eb3 Increase MAX_DIR_ENTRIES
Fixes #360
2018-05-11 17:47:41 +02:00
d0k3
87890ebc83 Compatibility for mounting fb3ds.firm
This allows handling of the superhaxed fb3ds firm.
2018-05-11 17:45:39 +02:00
windows-server-2003
aee58273f0 Indent NANDManager (#365) 2018-05-11 17:44:30 +02:00
d0k3
a35ebacab1 Readme: added 'Buttons' section 2018-04-30 02:28:58 +02:00
MadScript77
0bf6fca408 Replaced the old non-branching NAND scripts.
I replaced the old non-branching NAND backup/restore scripts with a branching, hotkeyed one.
2018-04-30 01:53:07 +02:00
d0k3
3bfe2fca02 Scriptrunner: Only stop at splash with R+UP 2018-04-26 12:16:10 +02:00
d0k3
4d7f047caf Fix #359
Note to self: need to pay attention to this with every FatFS update.
2018-04-26 12:13:37 +02:00
d0k3
470cd95121 Scripting: keychk command 2018-04-25 23:32:22 +02:00
d0k3
0caf2a6cbb Scripting: add keysel command 2018-04-25 15:25:07 +02:00
Hyarion Sanyënóna
8628e18d35 Switch iteration order over RomFS's from "folders before files" to "files before folders".
* This should only affect the for loop in scripts, causing RomFS's to be read in the order described on 3DBrew.
2018-04-23 01:39:44 +02:00
d0k3
e6a966ccaf Update FatFS to R0.13b 2018-04-23 01:31:52 +02:00
SirNapkin1334
13e4d356a5 Add Wiki logo 2018-04-23 01:12:09 +02:00
d0k3
d076194d26 Fix #351 2018-04-23 01:11:00 +02:00
d0k3
c5c02a8d58 Disable PNG support when monitoring the heap 2018-04-19 00:43:35 +02:00
d0k3
20bc988676 Scripting: add sdump -w flag 2018-04-18 16:25:37 +02:00
d0k3
83c90b8afb Scripting: add sdump command 2018-04-18 02:14:59 +02:00
d0k3
3a7c7432ca Always read CTR carts in 1MB chunks
This fixes #346
2018-04-18 01:24:27 +02:00
d0k3
e09c9b6e1d Include GodMode9 version in exception dumps 2018-04-18 00:07:57 +02:00
d0k3
b0997fa687 Improved string display handling
should fix #344 for good
2018-04-17 23:44:53 +02:00
d0k3
2a6d5c79c0 Fix #344 2018-04-17 01:42:00 +02:00
d0k3
2e07189a1b Allow .code extraction for .3ds files 2018-04-17 00:50:17 +02:00
Hyarion
1a9bf41c9d Add support for BPS/BPM/IPS-formatted binary delta patches.
BPS standardization edits.

* Clean up headers.
* Move crc32.c to /crypto/.
* Rename beat.c to bps.c and move it to /system/ with the rest of the non-3DS file formats.

Allocate memory for Source and Target files when possible.

Last-minute BPS improvements.
* BPS fails more gracefully on error, freeing memory and showing a more detailed message.
* BPM no longer deletes the folder it patches to - that should be up to the user.
* BPM is scanned before patching to figure out the total output file size for a more accurate progress bar.

Add IPS support.
2018-04-17 00:49:29 +02:00
d0k3
c12eb67b55 HelloScript: additional fset description 2018-04-16 23:19:11 +02:00
d0k3
4c97a09393 Add SHOW_FREE=1 and MONITOR_HEAP=1 build parameters 2018-04-16 01:02:30 +02:00
d0k3
ed6e7a2b91 H&S Injection: set savedata size to zero
Thanks @TurdPooCharger!
2018-04-13 17:12:17 +02:00
d0k3
f3782909c9 Add ZuishMode9 FLAVOR 2018-04-11 01:28:58 +02:00
d0k3
4f8dfc1eaf Scripting: add fget & fset commands 2018-04-11 01:28:34 +02:00
windows-server-2003
b656f0d90b Fix 'SD is write locked' after SD ejection 2018-04-05 12:35:43 +02:00
windows-server-2003
53db497f88 Fix some typos 2018-04-05 12:35:33 +02:00
d0k3
b7cd03b758 Remove redundant data from data dir 2018-04-05 12:32:23 +02:00
d0k3
1a0b3fcc5b Fix PNG viewer for 400x240px files 2018-04-04 23:41:12 +02:00
d0k3
5114ecffd4 Add splashes for new FLAVORs 2018-04-04 23:40:51 +02:00
d0k3
f34fcf6fa3 Added GodMode64 and BrickedMode9 FLAVORs 2018-04-04 23:28:30 +02:00
d0k3
7bdc153ca2 Use SD FAT volume label for listing and formatter
Fixes #333
2018-04-03 22:56:53 +02:00
Wolfvak
8c121ae1d3 Faster PNG compression, enabled separate data and function sections. 2018-04-03 01:17:58 +02:00
Wolfvak
c6e3c0ee30 Save screenshots as PNGs. 2018-04-03 01:17:58 +02:00
Wolfvak
19209918a7 Deprecated PCX code in favor of PNG. 2018-04-03 01:17:58 +02:00
Wolfvak
03014a72ee Initial PNG support (courtesy of lodepng). 2018-04-03 01:17:58 +02:00
d0k3
823f3b6d60 Added C64, Sheikah, Zuish fonts to resources 2018-04-02 23:14:48 +02:00
d0k3
ed55cffdca Revert to standard splashes 2018-03-28 00:33:23 +02:00
Wolfvak
c6903a1cf8 Add FIRM hashes on release. 2018-03-27 18:39:21 -03:00
d0k3
cea5fe49f9 Fix ARM9 crashes with injected H&S apps 2018-03-27 00:28:24 +02:00
d0k3
9ab50ba68d Fix mounting TADs
... thanks @wolfvak for help fixing this.
2018-03-26 02:40:47 +02:00
d0k3
e2d9942c23 Anniversary edition splash screens 2018-03-21 23:11:14 +01:00
d0k3
9239cdc289 Updated readme file 2018-03-21 23:11:13 +01:00
d0k3
0bac823271 Makefile: also show version and build time 2018-03-21 23:11:13 +01:00
d0k3
541d7650bb Fix Makefile output 2018-03-21 00:46:17 +01:00
d0k3
e03cc0b9c4 Beautified Makefile output 2018-03-20 00:56:37 +01:00
d0k3
3b5755fc28 seedDB building: detect empty seeddb 2018-03-19 01:11:48 +01:00
d0k3
46090fde0a Use datetime stamp for screenshot names 2018-03-17 18:09:43 +01:00
d0k3
05af82a4ad Fix UTF-16 handling for titles (3DS/NDS) 2018-03-17 17:00:10 +01:00
d0k3
3581ee97d8 Fix #325 2018-03-17 16:38:09 +01:00
d0k3
07b06b8552 Fix file corruption when copying dirs to A:/
thanks @ihaveamac for pointing this one out.
2018-03-16 18:46:53 +01:00
d0k3
ac514669a1 Properly handle UTF-8 filenames 2018-03-16 03:00:26 +01:00
d0k3
02f5abb877 Fix too menu entries in dir crashing GM9
... happened when there where more than 1024 entries.
2018-03-15 00:57:41 +01:00
d0k3
6a0391bb86 Update FatFs to R0.13a 2018-03-14 23:22:22 +01:00
Wolfvak
07e419f514 Enable the FCRAM extension on N3DS
... this means a larger RAM drive on N3DS
2018-03-14 23:22:21 +01:00
d0k3
7a85615a42 Improved SHA code
Thanks @profi200
2018-03-14 00:00:57 +01:00
d0k3
db5208a7b8 Allow injecting .srm type GBA saves
Fixes #323
2018-03-09 00:14:42 +01:00
windows-server-2003
3c7ad93d1c Forbid writing to SD if write locked 2018-03-09 00:14:41 +01:00
d0k3
915437dac0 Ignore .sublime-* files 2018-03-07 01:22:32 +01:00
d0k3
4087a2a2d7 Stricter checking for ExeFS files
fixes #321
2018-03-07 01:22:15 +01:00
d0k3
67e19ad574 Allow screenshots (almost) everywhere 2018-03-07 01:15:12 +01:00
d0k3
0ddb5c49d5 Improved SD card unmount 2018-03-06 23:35:12 +01:00
d0k3
84bfac6a1b Allow overriding the default font via gm9/support/font.pbm 2018-02-27 00:00:57 +01:00
d0k3
b63de24c26 Always format the RAM drive on reboots 2018-02-26 23:58:37 +01:00
d0k3
3671e2eb8e Fix #317 2018-02-26 23:29:00 +01:00
d0k3
988f2634b0 Fix #316 2018-02-26 23:16:43 +01:00
d0k3
4c17f6f96e Only show M:/otp_dec.mem if available 2018-02-26 23:09:50 +01:00
d0k3
37cdb26f91 System info: workaround for uninitialised movable.sed 2018-02-26 22:50:40 +01:00
d0k3
2f739ab130 Added ability to extract data from DIFF files 2018-02-22 01:47:29 +01:00
d0k3
bba90f14ad Compatibility with A9NC > 0.1.3
... this breaks compatibility with all versions <= 0.1.3
2018-02-21 02:00:53 +01:00
d0k3
8b21d0209b Hexviewer: some minor cosmetics 2018-02-21 01:59:37 +01:00
d0k3
a7d17ccd22 Increase CIA content count limit 2018-02-21 01:58:49 +01:00
d0k3
2806cf09ee Rewritten virtual ticket.db drive 2018-02-21 01:58:28 +01:00
d0k3
3d7ac49f87 Improved encdecTitlekeys.bin / seeddb.bin builder 2018-02-21 01:57:35 +01:00
d0k3
cabe185016 Added simple DISA / DIFF decoder 2018-02-20 22:54:16 +01:00
d0k3
03a9ca6a44 Separate ticket.c/.h and ticketdb.c/.h 2018-02-19 02:54:21 +01:00
d0k3
c70599977a File handler: fix output path detection 2018-02-19 02:54:21 +01:00
Wolfvak
0eaa971b50 Fix bootfirm version 2018-02-19 01:02:03 +01:00
d0k3
c1945fa82b Allow batch .code extraction 2018-02-13 03:17:10 +01:00
d0k3
1e39cbacd4 Batch operations: allow continue after failed operation 2018-02-13 03:11:31 +01:00
SirNapkin1334
388a89a970 Remove XORPADs from README
Since the [X:] drive was removed, there's no reason to mention it in the ReadMe.
2018-02-12 02:11:30 +01:00
d0k3
689f6f7cf4 Rewitten .code extraction to require less of the heap 2018-02-08 00:49:34 +01:00
d0k3
73a8332695 Fix #308 2018-02-07 23:07:23 +01:00
d0k3
79a3bfc9e1 Don't verify ExeFS for Process9 2018-02-07 02:16:31 +01:00
d0k3
d714d580e8 Fix #306 2018-02-07 01:53:51 +01:00
d0k3
4fbd909c8c Fix #304 2018-02-07 01:21:18 +01:00
d0k3
7235401b2b Bootloader: Resume GodMode9 if no bootable FIRM found 2018-02-07 00:58:38 +01:00
d0k3
0086a6bcb5 Improved memmap.h, now used everywhere 2018-02-07 00:43:21 +01:00
d0k3
93485ac287 Fixed all occurences of VGAME_BUFFER 2018-02-07 00:43:21 +01:00
d0k3
cdf72bbdc2 Fix all occurences of SCRIPT_BUFFER 2018-02-07 00:43:20 +01:00
d0k3
ae6c1c61c1 Fix all occurences of VCART_BUFFER 2018-02-07 00:43:20 +01:00
d0k3
b204921554 CPPcheck audit, fixed some minor stuff 2018-02-07 00:43:20 +01:00
d0k3
7927c742c6 Fix all occurences of NAND_BUFFER & SDCRYPT_BUFFER 2018-02-07 00:43:20 +01:00
d0k3
d731a5960f Fix all occurences of DIR_BUFFER 2018-02-07 00:43:19 +01:00
d0k3
14323b4d8d Fix: FIRM from FCRAM handling 2018-02-07 00:43:19 +01:00
d0k3
a2bbcef1a0 Fix: detecting CDN/NUS type 2 2018-02-07 00:43:19 +01:00
d0k3
144ade92f8 Deprecated ncchinfo.bin xorpads and the xorpad drive 2018-02-07 00:43:19 +01:00
d0k3
e70074b9c5 Fixed a crash when building enc/decTitlekeys.bin 2018-02-07 00:43:19 +01:00
d0k3
1b236acc86 Setup heap testing 2018-02-07 00:43:18 +01:00
d0k3
a0d2d27b06 Replace TEMP_BUFFER & MAIN_BUFFER with heap 2018-02-07 00:43:18 +01:00
d0k3
e9dc378b7a Fix crashes when viewing metainfo for certain CIAs 2018-01-23 02:00:21 +01:00
d0k3
6beec28470 README.md / HelloScript.gm9: minor stuff 2018-01-23 02:00:21 +01:00
d0k3
0fa9f52b08 Added PCX bitmap viewer
Fixes #299
2018-01-23 02:00:02 +01:00
d0k3
bb258725f2 Use 0:/gm9/out as standard folder for screenshots
Thanks @windows-server-2003 #299
2018-01-23 01:18:28 +01:00
d0k3
10da2e3789 More handholding for inexperienced users
Fixes #302
2018-01-23 00:47:02 +01:00
d0k3
67222429b4 Fix #303 2018-01-22 23:17:45 +01:00
d0k3
3d405166c5 Fixed a typo 2018-01-18 15:55:37 +01:00
d0k3
838a08df2a Scripting: GM9VER environment variable 2018-01-18 15:13:24 +01:00
d0k3
5034e99832 Scripting: Allow recursive 'for' 2018-01-18 02:23:46 +01:00
d0k3
3684db2fe7 Allow paralell building of ARM9 and ARM11 ELF 2018-01-17 23:53:48 +01:00
d0k3
40598423da Improved progress indicator for drive CMAC fixer 2018-01-17 23:53:48 +01:00
d0k3
3310400e1f Fix #295 2018-01-17 01:07:01 +01:00
d0k3
cb00194c49 Hexviewer: don't read more data than required 2018-01-17 01:06:48 +01:00
d0k3
e8af552547 TAB-> SPACES 2018-01-17 01:06:18 +01:00
d0k3
b60e5150e6 Font updates 2018-01-17 01:05:36 +01:00
d0k3
98bc5f00ec Better handling for tiny fonts 2018-01-16 00:43:09 +01:00
d0k3
dbb2c2f6ad Hexviewer: Don't allow edit mode for empty / unreadable files 2018-01-15 13:28:01 +01:00
d0k3
53d9964a26 Fix #294 2018-01-15 13:26:52 +01:00
d0k3
5df8c4b739 New, easier to edit font format 2018-01-15 01:49:04 +01:00
d0k3
48f7f4c652 Allow switching fonts at runtime 2018-01-13 17:05:51 +01:00
d0k3
39a94f4442 Fix #292 2018-01-13 16:13:48 +01:00
d0k3
a034214512 Revised font system 2018-01-13 16:11:14 +01:00
d0k3
e9c1faa319 Scripting: handling for 'for' 2018-01-12 03:19:04 +01:00
d0k3
239faede0f Scripting: 'isdir' & 'exist' commands 2018-01-12 02:52:39 +01:00
d0k3
387ff483fb Do not ask for essential backup on NTRBOOT 2018-01-12 02:51:18 +01:00
d0k3
24c31f482d Validate tickets via RSA signature
-> only proper / signed tickets in T:/ drive
-> 100% safe way of telling a ticket is legit
2018-01-10 02:08:29 +01:00
d0k3
5d8758bf83 Scripting: properly handle unclosed conditionals 2018-01-10 00:49:28 +01:00
d0k3
ddf6e11459 Scripting: fix 'dirsel' command 2018-01-09 15:46:37 +01:00
d0k3
7befb8f1b5 Scripting: added 'dirsel' command
fixes #287
2018-01-09 01:39:37 +01:00
d0k3
9bdd6a516f Scripting: Detect 'ntrboot' via $[HAX] 2018-01-03 02:21:56 +01:00
d0k3
64b5c3d2ad Moved sample scripts to their own directory 2018-01-02 02:30:42 +01:00
d0k3
93f966e1da Scripting: 'fill' and 'fdummy' commands 2018-01-02 02:26:49 +01:00
d0k3
c7d60879ae Scripting: allow browsing dirs in filesel 2018-01-02 01:02:09 +01:00
d0k3
0dd72ceb27 Fix building .cia from .3ds files
fixes #290
2018-01-01 22:40:09 +01:00
d0k3
dbe600c458 Scripting: 'not' command 2017-12-31 04:00:02 +01:00
d0k3
918482ef91 Scripting: added strrep command 2017-12-31 04:00:01 +01:00
d0k3
58046d0a20 Included HelloSpaghetti script in the readme 2017-12-29 17:32:19 +01:00
d0k3
b20f235e1d Added HelloSpaghetti.gm9 sample script 2017-12-29 17:25:32 +01:00
d0k3
4ade338ba8 Bootmenu: swap boot entries 2017-12-29 03:38:57 +01:00
d0k3
636e8ea348 Allow updating the .sha file if it doesn't match
fixes #285
2017-12-29 02:53:09 +01:00
d0k3
24f93a24c4 System Info: Also display the SD KeyY 2017-12-29 02:34:13 +01:00
d0k3
978f713a11 Added access to NVRAM to M: drive 2017-12-29 02:33:07 +01:00
d0k3
b5a0f6cfcf Try to catch low space on game crypto and CIA build operations 2017-12-28 03:46:57 +01:00
d0k3
28ba5a85b3 README: Added hint about updating the essential backup 2017-12-28 02:34:06 +01:00
d0k3
7ce028aa72 SD formatter: allow using the full 11 chars 2017-12-27 17:12:01 +01:00
d0k3
973fef9eaf Alphabet preview for string input 2017-12-27 16:33:19 +01:00
d0k3
e43b28e8bf Scripting: Fix handling variable names 2017-12-26 18:24:25 +01:00
Ian Burgwin
e94adae363 Add a custom Python script "add2tar.py" to create the vram0 tar file 2017-12-25 01:54:28 +01:00
windows-server-2003
4ea35ef504 Scripting: Added strsplit command 2017-12-20 16:06:50 +01:00
d0k3
625d1e5bea Scripting: Added labelsel command 2017-12-20 02:08:40 +01:00
d0k3
3c4b4236b3 Scripting: Some minor cosmetics 2017-12-20 01:06:56 +01:00
d0k3
52b3f128bf Scripting: Allow PCX and custom text for preview 2017-12-20 00:13:31 +01:00
d0k3
c92a6fa164 Fix SCRIPT_RUNNER compiler warnings 2017-12-19 22:51:43 +01:00
d0k3
5ef4dda899 Update README credits
... also sneak in a fix for the last two typos
2017-12-19 22:44:54 +01:00
d0k3
75448571ea Scripting: add 'elif' command 2017-12-19 22:34:05 +01:00
d0k3
32b9675c49 Added HIDE_HIDDEN build parameter 2017-12-19 22:34:05 +01:00
d0k3
61c93e1222 Update .gitignore 2017-12-19 22:34:05 +01:00
windows-server-2003
d70d67163c add if,else,end,goto command 2017-12-19 22:34:05 +01:00
d0k3
1e36b3ca98 Fix NULL dereference
Thanks @AuroraWright!
2017-12-19 02:59:40 +01:00
d0k3
0b7076ced3 Safe Restore: ask to create a backup if not found 2017-12-19 01:10:08 +01:00
d0k3
c17a2a9155 Rewrote NAND safe restore for aeskeydb sector 2017-12-11 17:09:07 +01:00
d0k3
585172f810 Added the ability to install aeskeydb.bin to NAND 2017-12-11 14:55:44 +01:00
d0k3
de7fe6cfb9 Fix a typo in Makefile.common 2017-12-11 02:47:43 +01:00
d0k3
1a63575caa Rewritten support file handling
Support files are now also accepted from CTRNAND.
2017-12-11 02:47:29 +01:00
d0k3
d8521dfdb9 Added TIMER_UNLOCK build parameter 2017-12-07 02:58:49 +01:00
d0k3
1cb2ca523c Proper permission handling for the VRAM drive 2017-12-07 02:54:12 +01:00
d0k3
3dd8a4764e Allow compiling multi-script autorunners 2017-12-07 02:01:15 +01:00
d0k3
38d3b4b4dc Makefile: Use 7za instead of 7z 2017-12-05 18:38:57 +01:00
Wolfvak
0220230403 Replace QLZ with PCX for splash 2017-12-05 18:37:50 +01:00
d0k3
c63a6e26c8 README: Added some missing info
Thanks @SirNapkin1334
2017-12-05 00:10:16 +01:00
d0k3
87743357c3 FIRM installer: Allow Nintendo style entrypoints 2017-12-02 12:28:50 +01:00
d0k3
65358b5964 README viewer: return to ToC on B 2017-12-02 12:28:20 +01:00
d0k3
f653dade6e Improve vram0 tar handling 2017-11-28 01:04:13 +01:00
profi200
9268a2f349 Fixed some bugs. 2017-11-27 00:48:05 +01:00
d0k3
63767e5eae Updated build system
Includes better handling for FLAVOR now, AUTO_UNLOCK for unlock
sequences and setting SD_TIMEOUT from make
2017-11-24 18:21:02 +01:00
d0k3
9217116a68 Update I2C code to newest version 2017-11-24 02:48:56 +01:00
d0k3
7466e0a4ea CTRtransfer: remove old SecureInfo_C before transfering
Fixes #267
2017-11-24 01:49:07 +01:00
d0k3
7d0a133d00 Fixed I2C_init() code (thanks @profi200) 2017-11-23 14:33:09 +01:00
DMSalesman
f157dcd542 README.md: Fixed typo and improved readability 2017-11-22 22:47:11 +01:00
d0k3
b4ee86d4ef Simple confirmation instead of unlock sequence for FIRM boots 2017-11-22 22:39:40 +01:00
d0k3
da7599d05c Fix: Recognizing file locks due to alias mounts 2017-11-22 03:17:57 +01:00
d0k3
bf2ce1a37c Use random keysequences and increase length for dangerous ones 2017-11-22 03:17:57 +01:00
d0k3
534174e630 Moved color definitions to their own .h file 2017-11-22 03:17:57 +01:00
d0k3
44c31ab50a Fix: Marking found entries in hex editor 2017-11-22 03:17:57 +01:00
d0k3
5132fb1271 Handle SRL as directory in vGame drive 2017-11-22 03:17:57 +01:00
d0k3
75791f1908 Fix: Unaligned file lengths in virtual TADs
Thanks @zoogie for pointing that one out.
2017-11-22 03:16:50 +01:00
d0k3
c18ac35d45 General fixes and cleanup
Thanks @Kazuma77 for pointing that stuff out!
2017-11-20 17:50:48 +01:00
d0k3
b5f2c64e77 NCCH crypto: Workaround for unrecognized seeds in internal SEEDDB 2017-11-20 17:01:43 +01:00
d0k3
ffc053a682 Fixed/improved release build goal 2017-11-17 20:48:51 +01:00
d0k3
45b7a75af0 Simplified TAR code 2017-11-17 19:37:46 +01:00
d0k3
20d2772056 DSiWare Export -> TAD 2017-11-17 19:37:46 +01:00
d0k3
ec861a7bf7 Added title info / mount support for DSiWare Exports 2017-11-17 19:37:46 +01:00
d0k3
fc97df6466 On-the-fly decryption for DSiWare Exports 2017-11-17 19:37:46 +01:00
angelsl
83b2fba142 Put the SD init timeout behind a compile flag 2017-11-17 19:37:46 +01:00
d0k3
ada25ea534 README: Updated build instructions 2017-11-17 19:37:45 +01:00
d0k3
cce1032d34 Fix revised Makefile 2017-11-17 19:37:45 +01:00
Wolfvak
beeea37d07 Revised Makefile 2017-11-17 19:37:45 +01:00
d0k3
463f2881da RTC: use the full 8 byte 2017-11-17 19:37:43 +01:00
d0k3
3ccd81da2c Extended system info with info from movable.sed & sdmmc
fixes #238
2017-11-17 19:37:43 +01:00
d0k3
643b58533e Cleanup: combine several .h files into one 2017-11-17 19:37:43 +01:00
d0k3
0f3fc2a5d1 Use vram0.tar instead of standard bin2o method 2017-11-09 00:22:16 +01:00
d0k3
2d36460a02 Virtual VRAM drive, based on TAR 2017-11-09 00:22:16 +01:00
angelsl
284fda27bc Add way to change file attributes 2017-11-08 00:52:47 +01:00
d0k3
840ccfe643 Use 0xDA partition type instead of 0x1C for EmuNANDs
fixes #253
2017-11-07 01:13:13 +01:00
angelsl
ee6482aa44 Timeout SD init after about a second 2017-11-06 01:58:29 +01:00
d0k3
12739c2a91 Adjust brightness while displaying progress bar
fixes #259
2017-11-06 01:50:35 +01:00
d0k3
d413e71c01 Show title info for 3DSX files 2017-10-29 15:32:25 +01:00
d0k3
a9eaf45a8e Wait until all buttons released before showing the bootmenu 2017-10-28 14:39:32 +02:00
figgyc
45d620bf72 Added REGION variable for scripting (fix #243) 2017-10-27 19:42:47 +02:00
d0k3
05ca9109de Use new entrypoint detection method, remove old one 2017-10-27 19:25:26 +02:00
Wolfvak
7937540162 Entrypoint detection stuff (untested) 2017-10-26 20:27:02 -03:00
d0k3
dfe3e4bf15 scripting: Block the Z: drive from the filesel command
... fixes #248
2017-10-25 00:36:58 +02:00
d0k3
5f43dcc02d Also ignore "._" in file selector 2017-10-24 23:58:41 +02:00
d0k3
770137ceb0 Fix the "._" check 2017-10-24 16:18:47 +02:00
d0k3
ef9ba1a5a5 Block crappy "._" files from getting recognized as filetype 2017-10-23 23:44:43 +02:00
JoshuaDoes
64407f1604 Organize and edit battery color scheme 2017-10-23 23:44:43 +02:00
d0k3
d9ae07bd2b Allow disabling the slider and fixing the brightness via the Makefile
Use make FIXED_BRIGHTNESS=x, whereas x is between 0...15
2017-10-20 17:36:30 +02:00
d0k3
39b76ef5fc Make AL3X10MODE the standard
You can still pause & view the splashscreen via R+UP
2017-10-19 01:34:24 +02:00
d0k3
ac25337690 Enable Mount CXI and Extract .code for TMDs 2017-10-16 17:19:34 +02:00
d0k3
5d4d122543 Limited GBA rom image support
... support for:
* proper extension when extracting from .code
* showing title info
* renaming cartridge images
2017-10-16 02:02:24 +02:00
Death Mask Salesman
5462f2d5e8 Fix typos in readme file 2017-10-13 00:45:12 +02:00
d0k3
c6dd031438 Open containing folder in secondary pane 2017-10-13 00:39:32 +02:00
d0k3
90027ac8b2 ui.c: Fix a typo 2017-10-13 00:30:02 +02:00
d0k3
6ff6733cbc Hardcode the readme file
... we need to find a better way of doing this later
2017-10-11 23:58:36 +02:00
d0k3
f6dbed41cf Temporarily disable GBA VC Save dumps from SD 2017-10-11 23:52:21 +02:00
d0k3
2917a9674c Vastly imporved reliability of GBA VC save injections 2017-10-11 17:00:52 +02:00
d0k3
eb6dc62fd8 Added the Makefile code for the previous commit 2017-10-11 03:24:04 +02:00
d0k3
fe9e42ddb4 Allow disabling the brightness slider on compilation
make DISABLE_SLIDER=1
2017-10-11 03:23:05 +02:00
d0k3
69423b22ed Improved image mount handling 2017-10-11 03:17:50 +02:00
d0k3
defcb678d5 Improved alternative bootmode 2017-10-11 01:57:28 +02:00
d0k3
c24a654cb9 Added CMAC and GBA VC inject support for SD AGBSAVEs 2017-10-10 16:00:19 +02:00
d0k3
9dc8105e9c Improved / fixed SetupSecretKey() 2017-10-09 16:51:39 +02:00
d0k3
653de94395 Disable Link Time Optimization
... this may solve build issues
2017-10-09 15:20:45 +02:00
d0k3
26acfc4cff Improved text viewer color scheme 2017-10-05 02:23:09 +02:00
Shadowhand
d625c19b79 Added hidden / undocumented alternative bootmode 2017-10-05 01:55:31 +02:00
d0k3
30774a09d9 Remove support for legacy support paths 2017-10-04 01:27:09 +02:00
d0k3
a18875ea35 Fixed several cases of stray tabs 2017-10-03 14:40:22 +02:00
d0k3
641b2c3a1a GBA VC save dumper: Ensure the output directory exists 2017-10-03 14:40:22 +02:00
d0k3
89090aa8c9 Scripting: Fix partial SHA via shaget command 2017-10-03 14:40:22 +02:00
d0k3
f2f28c856c Prevent crashes on viewing certain text files (sourcecode, mainly) 2017-10-03 14:40:22 +02:00
d0k3
42820b185c Added readme viewer to HOME menu 2017-10-03 14:40:21 +02:00
d0k3
ee26458341 Fix caption types in Readme 2017-10-02 00:22:21 +02:00
d0k3
b6409ec045 FIRM chainloader: offer on-the-fly decryption of encrypted FIRMs 2017-09-29 03:14:06 +02:00
d0k3
5f1814b599 Virtual FIRM: Add addresses to section names 2017-09-28 05:09:35 +02:00
d0k3
fa3daea740 Improved checks for installable FIRMs 2017-09-28 05:09:15 +02:00
d0k3
0221839299 Fix ARM9 entrypoint on decrypting encrypted FIRMs
... this makes decrypted N3DS NATIVE_FIRM, AGB_FIRM, TWL_FIRM bootable.
2017-09-28 05:08:16 +02:00
d0k3
21c1ae30fe Allow piggybacking filesystem images to the GodMode9 firm
... just put an image file called `vram0.img` into data - max size:
3MB(!).
2017-09-27 02:13:03 +02:00
d0k3
3b56a12857 Add bootmenu keycombo to the bootloader splash 2017-09-27 01:53:05 +02:00
d0k3
a90379f2c1 Allow chainloading larger FIRMs via FCRAM 2017-09-27 01:53:05 +02:00
Death Mask Salesman
2e0125cd37 Fixed variable typo
Replaced `ERRORMSGMSG` with `ERRORMSG` and adjusted the padding to match.
2017-09-27 01:09:18 +02:00
lucario1001
e019b5e848 Update README.md 2017-09-27 01:09:18 +02:00
d0k3
8e705edf1b M: drive: Remove the disfunctional _ext memory access on sighax 2017-09-27 01:09:18 +02:00
Wolfvak
8a4597635d Potentially fix screen init on some systems
Sanitized I2C
Reorganized the memory layout
 - Moved GM9 to ARM9 RAM
 - Increased RAMdisk size to 88MiB
2017-09-26 19:56:19 -03:00
d0k3
5e652b1313 Fix: crash on viewing certain scripts 2017-09-25 13:21:54 +02:00
d0k3
20a318a29d Fix: Scripts not displaying in text viewer 2017-09-25 00:50:44 +02:00
d0k3
d847944462 Fix: Check for bootmenu keys in bootloader 2017-09-25 00:50:16 +02:00
d0k3
5d9ed651cb Scripting: allow 'shaget to store the SHA in a var 2017-09-24 13:44:49 +02:00
d0k3
fad938b977 Fix vanishing top bar 2017-09-24 12:10:09 +02:00
d0k3
fe1791c7c5 Added NAND restore scripts by Kazuma77 2017-09-24 12:08:23 +02:00
d0k3
430bcd6997 Allow context menu inject for virtual files 2017-09-24 12:04:52 +02:00
d0k3
dcafbaa191 Improved ntrboot checks
... this also restores default behaviour when booting from ntrboot and
simplifies the bootloader behaviour.
2017-09-23 13:11:38 +02:00
Death Mask Salesman
a92c993573 Fixed typos 2017-09-22 17:45:51 +02:00
d0k3
0a1a08a7e0 Allow filelist reloads via R+DOWN 2017-09-22 17:18:06 +02:00
d0k3
1bb41bbaa6 Prevents mounts of FAT drives from SysNAND / EmuNAND virtual 2017-09-22 17:17:48 +02:00
d0k3
b3243a2792 AGBSAVE: allow injecting smaller saves 2017-09-21 23:10:32 +02:00
d0k3
c80ebb1100 Bootloader: improved bootloop preventation on FCRAM boots
... also beautified the battery symbol a little
2017-09-21 01:53:52 +02:00
d0k3
2a98ab8bfd Scripting: 'chk' command, HAX / ONTYPE / RDTYPE env vars
... also increases the allowed length of args
2017-09-21 01:53:52 +02:00
d0k3
c9f9745495 Added GBA VC save dumper / injector
... this also removes the gbavc.sav file from the virtual NAND drives
and does some general cleanup. Fixes #205.
2017-09-21 01:53:23 +02:00
d0k3
73d4ba0ab8 Documented the undocumented bootloader 2017-09-20 01:31:28 +02:00
d0k3
d6919eba22 Automatically show the bootmenu on ntrboot 2017-09-20 00:44:18 +02:00
d0k3
85e584c2d5 Made bootloader the default mode when installed to FIRM0 2017-09-19 15:58:43 +02:00
d0k3
680c809d76 Scripting: add qr command 2017-09-19 15:57:29 +02:00
d0k3
1f2d6a78f2 Prevent AR dumps from triggering exceptions 2017-09-19 15:25:01 +02:00
d0k3
20ac0573a5 Updated readme credits 2017-09-19 15:25:01 +02:00
Wolfvak
d50c45ff23 Enable MPU and caches on the exception handler
An (uncachable) background region makes sure no bad accesses get caught
2017-09-19 15:25:00 +02:00
d0k3
d249b647d6 Added ability to output exception QR codes 2017-09-19 15:25:00 +02:00
d0k3
628234a861 FIRM from FCRAM: check for secondary magic 2017-09-19 01:00:44 +02:00
d0k3
4df98de543 Added battery symbol to the top bar 2017-09-18 19:57:43 +02:00
Death Mask Salesman
1be3878659 Update readme file 2017-09-18 14:02:43 +02:00
d0k3
93a6a183c5 A9NC / bootloader: check for FIRM in FCRAM on start 2017-09-17 17:50:31 +02:00
d0k3
59928d7573 Scripting: allow customizing and disabling the script preview
fixes #201
2017-09-16 17:08:26 +02:00
d0k3
c164077434 Added delete code for certain virtual files (not used) 2017-09-16 17:07:51 +02:00
d0k3
5941ce41bc Show battery state on top bar
thanks @al3x10m for pointing out the possibility
2017-09-16 16:46:30 +02:00
d0k3
a947835830 Added bootonce feature to hidden bootloader 2017-09-16 13:48:31 +02:00
d0k3
d646018c81 Fix swapped sd_cid.mem / nand_cid.mem 2017-09-16 13:31:11 +02:00
d0k3
93e84b8b12 Brought back "Copy to 0:/gm9/out" for dirs 2017-09-15 14:11:43 +02:00
d0k3
83f1eac13a Fix readme typos 2017-09-15 02:10:54 +02:00
d0k3
33e164abc4 Also include .sha files for ntrboot installable FIRMs 2017-09-14 22:53:55 +02:00
d0k3
8b71fd768e Updated readme file 2017-09-14 22:13:16 +02:00
d0k3
4244122dda Improved hidden bootloader 2017-09-14 13:38:19 +02:00
d0k3
5cd1c7259f Added hidden & undocumented bootloader functionality 2017-09-13 20:03:46 +02:00
d0k3
e1b135ddc5 Improved AGBSAVE / CMAC handling code 2017-09-13 16:36:31 +02:00
d0k3
88a390f7a8 Revamped & combined drive / directory info feature 2017-09-13 16:36:16 +02:00
d0k3
f545113c08 Added file info feature 2017-09-13 16:36:16 +02:00
d0k3
28e542245b Allow recursive CMAC fxing for applicable drives 2017-09-13 16:36:08 +02:00
d0k3
ab557e6ae5 Scripting: filesel command for selecting a file
Fixes #197, also includes run_cmd() code cleanup
2017-09-13 02:46:19 +02:00
d0k3
b7d914d73f Allow copying from NAND to virtual NAND
... reduced safety, but will always work on standard NANDs and any sane
repartitioned NANDs
2017-09-13 02:46:02 +02:00
d0k3
f46a88c9ff Beautified exception handler 2017-09-13 01:10:14 +02:00
d0k3
e8b34a90be Fixed encrypted CIA mounting
Again, thanks @ihaveamac for pointing out the bug
2017-09-12 13:10:14 +02:00
d0k3
5dc2634183 FIRM mounting: use proper names for sections 2017-09-12 01:52:46 +02:00
d0k3
e63953585d CIA mounting: allow full access to encrypted CIAs
Thanks @ihaveamac for pointing out the possibility
2017-09-12 01:22:07 +02:00
d0k3
af164e2cf8 Fix: allow NCCH encrypted copy from inside CIA / NCSD / FIRM 2017-09-11 01:13:53 +02:00
d0k3
e4d4b05cc9 Workaround for empty EmuNAND partitions 2017-09-10 14:15:38 +02:00
d0k3
cc31926a69 Added ability to rebuild / fix NAND NCSD headers 2017-09-10 14:13:45 +02:00
d0k3
343f1182b9 Fix writing in drives A: / B:
Thanks @AuroraWright for finding this bug
2017-09-09 19:12:28 +02:00
d0k3
78cc747861 Fix: Also take over CIA meta data on en-/decryption
... thanks, Rai-chan!
2017-09-09 13:07:29 +02:00
d0k3
77ed3d4733 Scripting: improved write permission checks 2017-09-08 20:58:20 +02:00
d0k3
322c996afe Show a warning if potentially incomplete key setup detected 2017-09-08 20:25:48 +02:00
d0k3
c32908e4cf Allow building standalone script runners
... just include autorun.gm9 in the data folder
2017-09-08 15:39:57 +02:00
d0k3
c094c6c192 Scripting: add extrcode command 2017-09-08 15:39:57 +02:00
d0k3
01bc03244c Scripting: Properly deinit filesystems on reboot / poweroff 2017-09-08 15:24:29 +02:00
d0k3
1838c608e1 Fix #194 2017-09-08 13:30:16 +02:00
d0k3
a6a15eb70d Added ability to extract uncompressed .code 2017-09-08 04:00:39 +02:00
d0k3
f12dcfda4c Reorganized memory buffers for more usable space 2017-09-08 03:09:49 +02:00
d0k3
6d276c6bf5 Scripting: Add -f flag to find for returning first match 2017-09-06 13:01:52 +02:00
d0k3
5f0ab648aa Scripting: Live preview for scripts
This commit also adds limited syntax highlighting for scripts
2017-09-06 00:46:01 +02:00
d0k3
730cff8554 Offer setting the RTC if year < 2017 is detected 2017-09-05 14:26:18 +02:00
d0k3
bf5750381c Replace gamecard timeout code (for consistency) 2017-09-04 16:51:16 +02:00
d0k3
8d1f39d235 Source code reorgnaizations 2017-09-04 16:18:07 +02:00
d0k3
ebf904a2c2 Scripting: shaget and switchsd commands
Fixes #190
2017-09-04 02:15:45 +02:00
d0k3
b7e0012f74 Readme: updated credits section 2017-09-04 01:08:10 +02:00
d0k3
a5c1fd5749 Include build timestamp in splash screen 2017-09-01 18:01:33 +02:00
d0k3
0666370f75 Add version to release archive, include ntrboot FIRMs 2017-09-01 03:29:24 +02:00
d0k3
ac810359fa Scripting: Make 'find' always return the alphanumerical last match
... fixes #189
2017-09-01 02:30:12 +02:00
d0k3
ea6f455811 Fixed position bar graphical errors 2017-08-29 03:29:29 +02:00
d0k3
f09aa9bf09 Large batch operations: update cursor and scroll list 2017-08-29 02:52:22 +02:00
d0k3
e50a0af7ef Fix certain NDS roms not mounting properly
... fixes #186
2017-08-26 16:11:36 +02:00
d0k3
19ecbd6bb0 Scripting: Combine warning and confirmation prompt. 2017-08-26 13:14:38 +02:00
d0k3
6c76bd9cfb Fix #183 2017-08-25 15:16:09 +02:00
d0k3
e245c576cc Virtual memory: otp_dec.bin support without boot9.bin 2017-08-25 14:44:54 +02:00
d0k3
0fd5261516 Virtual memory: add ability to read NAND/SD CID 2017-08-25 14:19:16 +02:00
Myria
ff7b9749ad Refactored vmem.c, added support for reading MCU 2017-08-25 14:02:31 +02:00
d0k3
3407b3d5da Virtual drives: Introduce VFLAG_READONLY 2017-08-25 14:02:31 +02:00
Myria
99a638a084 Added ability to display system info 2017-08-25 14:02:31 +02:00
Myria
8d4996bc60 Consolidated region definitions 2017-08-25 02:15:56 +02:00
d0k3
63522346bf Handle CTRtransfers with no valid destination 2017-08-25 00:21:09 +02:00
d0k3
34e5b23c80 Scripting: improve handling for input, find & findnot 2017-08-25 00:20:50 +02:00
d0k3
de230fd8e5 Scripting: Dynamically update envvars at runtime 2017-08-24 15:46:36 +02:00
d0k3
0c07b17df1 FIRM Installer: show proper success / failure message 2017-08-23 13:33:31 +02:00
Wolfvak
1a65b4e7f0 Fix backlight turning on issue 2017-08-23 13:31:17 +02:00
Wolfvak
5104deff9e Refactored screeninit 2017-08-23 13:31:16 +02:00
d0k3
b333380bc0 Less restrictive FIRM section adress whitelisting
... alllows loading Luma 8 again
2017-08-23 02:22:18 +02:00
d0k3
71debc772f Scripting: allow partial sha checks 2017-08-23 02:09:41 +02:00
d0k3
0ccce0cb32 Scripting: Allow inject command to expand or create files
fixes #177
2017-08-23 02:09:40 +02:00
d0k3
c0aec42f1d Add workaround to allow installing B9S FIRM 2017-08-22 13:23:48 +02:00
d0k3
9c02388d15 Scripting: add boot command 2017-08-21 21:33:22 +02:00
d0k3
551a48149f Scripting: add fixcmac command
fixes #175
check HelloScript.gm9 for how it's done
2017-08-21 19:56:30 +02:00
Matt
26690f4a90 Update EmuNAND Backup script 2017-08-21 12:18:08 -04:00
Matt
7416f6c890 Update SysNAND Backup script 2017-08-21 12:18:01 -04:00
d0k3
0af54bd67a NDS mount code cleanup 2017-08-20 15:33:05 +02:00
Aurora Wright
387f5d6db1 Fix overwriting part of the FIRM with garbage on install 2017-08-20 15:33:05 +02:00
d0k3
8b8a8695d9 Better checks for installable FIRMs 2017-08-20 15:31:30 +02:00
Wolfvak
7d8f6bb368 Hardcoded framebuffers
VRAM addresses are in common/vram.h

Now waits for the ARM11 to ack before running
2017-08-18 18:53:54 +02:00
d0k3
564f403f4c Rely on b9s key setup if the 0xBEEF magic is found 2017-08-18 18:52:42 +02:00
d0k3
2cc94be6b4 Added ability to install FIRM files 2017-08-18 17:08:03 +02:00
d0k3
fdcc9059e2 Revised / fixed NDS rom file mounting
... fixes #170
2017-08-18 14:53:06 +02:00
Wolfvak
cfa26c2a2d Misc exception handlers fixes
Biggest one is they actually work now
2017-08-16 19:43:08 -03:00
d0k3
06318455c1 Textviewer fix: left arrows in unused lines 2017-08-16 20:04:41 +02:00
d0k3
2393f82e79 Improve screen clear speed 2017-08-16 17:56:21 +02:00
d0k3
4faf67e194 Pull version numbers from git 2017-08-16 15:50:46 +02:00
d0k3
0fb149afa4 Add drive info for dirs (press R+A) 2017-08-16 01:44:50 +02:00
d0k3
34756037b2 Enable "search for titles" for applicable drives 2017-08-16 01:44:49 +02:00
Wolfvak
e920bd34a4 Fixed the MPcore interrupt handler, added local ARM9 exception handler 2017-08-16 01:44:49 +02:00
Wolfvak
930b646008 Improved MPcore interrupt handler 2017-08-16 01:44:48 +02:00
d0k3
e36b2c347f Vastly speed up boot times
This also improves f_getfree handling (prevents it where possible)
2017-08-16 01:44:48 +02:00
d0k3
9882b68a31 Improved NDS rom file mounting 2017-08-16 01:44:48 +02:00
d0k3
b44e43d0e5 Updated FATFS to R0.13 2017-08-16 01:44:47 +02:00
d0k3
5ec488937e Allow forced initialization of aeskeydb.bin files 2017-08-15 02:16:53 +02:00
Aurora Wright
69c89409c7 Pass argc=1 if the specified FIRM does not require screen init (as B9S/Luma do) 2017-08-14 13:38:43 +02:00
d0k3
d1b8a89510 Added a "Payloads..." menu to HOME menu
... this also moves the "Scripts..." menu one level up and fixes a minor
bug.
2017-08-14 13:10:16 +02:00
d0k3
32fc283791 Added support for mounting NDS images 2017-08-14 02:47:00 +02:00
d0k3
fdb93b51f3 Fix FIRM validation before boot 2017-08-12 20:45:08 +02:00
Riccardo Boninsegna
2387cb9e21 Information about ntrboot 2017-08-12 20:45:07 +02:00
Riccardo Boninsegna
e95ece09f4 Enable alternate key .firm build (for ntrboothax, etc) 2017-08-12 20:45:07 +02:00
d0k3
a4e174938e Fix FIRM whitelist and address check 2017-08-11 23:05:44 +02:00
d0k3
a9badfee9c Allow hardcoding keys
... the required file will not be provided
2017-08-11 00:44:59 +02:00
d0k3
96054a8406 Fix NTR AGING cart dump
... for reals, this time
2017-08-10 01:51:54 +02:00
d0k3
8b6ca667ed Increased version number to 1.3.1 2017-08-08 17:52:48 +02:00
al3x10m
9f135f225a Improved brightness table 2017-08-08 17:47:49 +03:00
Wolfvak
b56ca0e8b8 Added brightness adjustment through the volume slider, made the ARM11 finally do something rather than sit and wait for the entrypoint 2017-08-08 09:40:09 -03:00
d0k3
ed257e9216 Use ISO 8601 for displaying date & time
fixes #143
2017-08-08 12:30:33 +02:00
d0k3
bf58112c1d Also generate the FIRM .sha files when compiling. 2017-08-08 12:12:39 +02:00
d0k3
cf84ce4fa4 Revert "Fix dumping NTR AGING cart"
This reverts commit d6490453ba9bebbc82b97c5ac9e20bf21eab01e3.
2017-08-08 11:53:47 +02:00
d0k3
df5e80bb98 Fix mounting FAT / NAND images
fixes #142
2017-08-07 23:33:08 +02:00
d0k3
4dddd8aeeb Remove arm9loaderhax entrypoint 2017-08-07 12:57:33 +02:00
d0k3
745c7f4cbf Updated readme file 2017-08-07 01:04:41 +02:00
d0k3
8e3d864d83 Scripting: Support TIMESTAMP and DATESTAMP env variable 2017-08-04 18:21:56 +02:00
d0k3
3f87c42334 Properly handle HWCAL0.dat / HWCAL1.dat
These files are system unique. This commit fixes the write permission
system and includes both files in the essential backup.
2017-08-04 16:56:06 +02:00
d0k3
24a9b711e8 Add support for handling the RTC & correct FAT times 2017-08-04 03:51:03 +02:00
d0k3
06f70d0a59 Fix sizes of SHA hashes 2017-08-04 03:51:03 +02:00
d0k3
e576baa601 User the POWER button as an alternative to HOME 2017-08-04 03:51:03 +02:00
d0k3
90a7705d21 Don't spam the MCU with reads (in hid.c) 2017-08-04 03:51:02 +02:00
d0k3
cb694689aa Allow creating dummy files 2017-08-04 03:51:02 +02:00
d0k3
78dbc95b60 Fix mounting images from drives 8: / 9: 2017-08-04 03:51:02 +02:00
d0k3
63b7604529 Fully initialize the crypto system
This allows chainloading Luma outside of boot9strap
Requires a good aeskeydb.bin, like MD5 A5B28945A7C051D7A0CD18AF0E580D1B
2017-08-04 03:51:02 +02:00
d0k3
030e939dc5 Handle FIRM boot path 2017-08-04 03:51:01 +02:00
d0k3
1e61af9442 Removed all legacy entrypoints (only SigHax and A9LH remain) 2017-08-04 03:51:01 +02:00
Wolfvak
ba808f9876 Removed old Brahma-compatible chainloader 2017-08-04 03:48:47 +02:00
d0k3
5d6ee82728 Properly credit stuckpixel 2017-08-04 03:48:47 +02:00
d0k3
45fef040ff Prevent race condition in main 2017-08-04 03:48:47 +02:00
Wolfvak
e121e72f1c Implemented FIRM booting 2017-08-04 03:48:47 +02:00
Wolfvak
15882e7111 Allow running GodMode9 in any environment 2017-08-04 03:48:46 +02:00
d0k3
d6490453ba Fix dumping NTR AGING cart 2017-07-29 14:22:46 +02:00
d0k3
3da6cf5c0e Fix case sensitive permission checks 2017-07-27 20:30:12 +02:00
d0k3
5f70cdc8fa Cleanup screeninit build directory 2017-07-27 20:29:53 +02:00
d0k3
e4a0d62d16 Scripting: add decrypt, encrypt, buildcia commands 2017-07-27 14:29:03 +02:00
d0k3
20c9b640d6 Miscelaneous small fixes 2017-07-27 14:26:59 +02:00
d0k3
f38697b156 Fix: TWL key init on certain A9LH chainloaders 2017-07-27 13:35:18 +02:00
d0k3
8e8df94aba Fix compiler warning 2017-07-26 22:35:53 +02:00
d0k3
b3373a2182 Fix text viewer line numbers 2017-07-26 22:35:53 +02:00
d0k3
c7322b478d Add screeninit to FIRM payload 2017-07-26 22:35:52 +02:00
d0k3
96f6f2f34b Scripting: add 'input' command 2017-07-26 14:14:12 +02:00
d0k3
3025329799 Scripting: add CURRDIR environmental variable 2017-07-26 14:08:29 +02:00
d0k3
3cfdc3dc77 Fixed a typo 2017-07-26 14:07:34 +02:00
d0k3
bba9c13506 More intuitive non-unlockable handling, fixes #128 2017-07-25 12:44:27 +02:00
Dave Murphy
748b77ad9c Allow parallel build 2017-07-24 14:16:54 +02:00
d0k3
9aeac540e5 Where/were typo - Fix #125 2017-07-24 14:08:22 +02:00
Dave Murphy
1f69db1bdb fix build with r47. Closes #119 2017-07-24 13:59:33 +02:00
d0k3
c60237a8c3 Poweroff LCD before reboot / poweroff
... fixes several MCU issues
2017-07-11 20:55:53 +02:00
d0k3
730b88638d Include sample script in release archive 2017-07-11 20:55:18 +02:00
d0k3
cd9d480579 Updated readme file 2017-07-11 20:55:06 +02:00
d0k3
7b3438d458 'mount' / 'umount' -> 'imgmount' / 'imgumount' (in scripts) 2017-07-11 20:54:30 +02:00
d0k3
1a080c3029 Replaces spaces -> '_' in cart names 2017-07-10 22:46:51 +02:00
d0k3
cfe68b4ff9 FIRM loading needs boot9strap nightly 2017-07-10 22:46:51 +02:00
d0k3
804e5d5921 Improved timer reinits 2017-07-10 22:46:51 +02:00
d0k3
e434c5aac8 Updated I2C routines
Thank @profi200
2017-07-10 22:46:51 +02:00
d0k3
dc85dccd06 Fix timer stops on DS cart initialization 2017-07-06 00:59:21 +02:00
d0k3
102ad45905 Remove delays on I2C reads
... strangely seems to fix NDS cart inits
2017-07-04 21:06:12 +02:00
d0k3
b9eea8e92b Allow booting FIRM images
... works only with latest boot9strap nightly
2017-07-04 02:22:35 +02:00
d0k3
7522f73685 INPUT_PATHS -> SUPPORT_PATHS 2017-07-04 01:49:18 +02:00
d0k3
04985b9a4c Finished the textviewer 2017-07-04 01:49:17 +02:00
d0k3
488ea87e29 Safety confirmation before actual cancellation of copy/move/inject 2017-06-30 03:06:57 +02:00
d0k3
2f8c32d1ac Fix bad ETA on progress bar 2017-06-30 02:43:52 +02:00
d0k3
3080262786 Fix empty SysNAND Virtual Drive for corrupted NCSD 2017-06-30 02:42:25 +02:00
d0k3
dd2efaedc5 Added Textviewer (unfinished) 2017-06-28 23:35:51 +02:00
d0k3
9589731fa6 Show nagscreen if no embedded backup is found. 2017-06-23 17:28:09 +02:00
d0k3
f129100f88 Add SYSID0 & EMUID0 to script environment vars 2017-06-23 02:13:22 +02:00
d0k3
61712ce1fb Add a warning disclaimer when first running scripts 2017-06-23 01:41:23 +02:00
d0k3
754efbf112 Offer write permission relock after change
.. this also adds an error message on failed dir reads and removes an
unneeded check
2017-06-23 00:59:51 +02:00
d0k3
fc5637e86a Fix scripting flags handling for cp, mv, inject 2017-06-23 00:28:45 +02:00
d0k3
c240f3463d Fix data aborts on TWL MBR writes 2017-06-21 12:55:36 +02:00
d0k3
1ebfd74aa4 Include official scripts in release archive 2017-06-21 02:19:18 +02:00
d0k3
844b32c49d Use 0:/gm9/out and 0:/gm9/support instead of earlier paths 2017-06-21 02:18:30 +02:00
d0k3
d59c05876a Scipts menu in HOME -> more
.. scripts go to 0:/gm9/scripts
2017-06-21 01:04:36 +02:00
d0k3
27426eae44 Fix I2C delays 2017-06-20 00:26:57 +02:00
d0k3
2861b9516b Improved power functions 2017-06-20 00:23:49 +02:00
d0k3
17502ff5a1 Revised timer functions 2017-06-20 00:07:32 +02:00
Hikari-chin
093438413b Wait 3ms for i2c reads/writes to workaround N3DS MCU bugs 2017-06-19 02:36:57 +02:00
d0k3
dedf0f8327 Simplified RedNAND / EmuNAND options on SD format menu 2017-06-19 02:36:57 +02:00
d0k3
78d9f1747a Godmode9 scripting support 2017-06-19 02:36:57 +02:00
d0k3
9661ffc940 Rewritten file copy / move routines 2017-06-14 14:45:09 +02:00
d0k3
65af709aa9 Improved ticket validation 2017-06-09 00:21:31 +02:00
d0k3
392039a5ba Updated Quick start guide 2017-06-08 15:36:53 +02:00
d0k3
d785159827 Remove support for the secret_sector.bin support file 2017-06-07 12:42:24 +02:00
d0k3
10426d532e Changed fs -> filesys 2017-06-06 21:16:29 +02:00
d0k3
94b8588423 Improve vff.c / vff.h functionality 2017-06-06 21:14:19 +02:00
d0k3
d97e754593 Remove legacy entrypoints from release goal 2017-06-05 13:52:31 +02:00
TuxSH
a27bd1f82d Fix TWL key 0x03 init for devkits 2017-06-05 13:48:12 +02:00
d0k3
a75f77ad13 Allow FIRM A9L decryption on devkits
... still needs testing
2017-06-05 13:32:07 +02:00
d0k3
ae96c058f8 Fix #82 2017-06-03 12:22:12 +02:00
d0k3
d704452c28 Updated BrahmaLoader submodule 2017-06-02 17:27:57 +02:00
d0k3
7bbaf17b42 Replace (u8*) with (void*) where applicable
... also changes sector0x96 workaround to OTP encrypt method
2017-06-01 16:12:16 +02:00
d0k3
c9abc77348 Fix Travis CI 2017-06-01 12:09:14 +02:00
d0k3
9da76b94c6 Reduce ram drive size on sighax to 64MB
Don't use extended FCRAM, cause that's disabled
2017-06-01 01:19:30 +02:00
d0k3
7df545da18 Properly discard un-displayable UTF-16 chars
addresses #68
2017-05-31 23:42:33 +02:00
d0k3
7505c0b212 Allow setting up GW type EmuNANDs after SD format
addresses #69
2017-05-31 23:26:45 +02:00
d0k3
5694df0dad Sighax compatibility improvements
... this also removes the last remaining NAND offset hardcoding
2017-05-31 23:25:34 +02:00
d0k3
c93746e957 SD format: Auto-revert to default cluster size on fail
Addresses #78
2017-05-31 23:14:20 +02:00
d0k3
3e14fd3f44 Remove A9LH self payload handling in vMem drive 2017-05-31 23:06:24 +02:00
TuxSH
540daed73a Remove firmtool submodule 2017-05-31 21:53:42 +02:00
d0k3
348741f963 Fix remaining NAND offset hardcoding 2017-05-31 16:16:31 +02:00
d0k3
4d91a86d12 Remove the size limitation on BOSS files 2017-05-31 16:16:31 +02:00
TuxSH
d8d2901ec1 Add support for upcoming Luma3DS & B9S versions...
...without breaking support for outdated/deprecated entrypoints, and fix start.s (GW & DTCM issue)
2017-05-31 16:16:30 +02:00
d0k3
87631e06d1 Remove NAND offset hardcoding from diskio.c 2017-05-31 16:16:30 +02:00
d0k3
f920fc47fc Use OTP in essential backup instead of OTP hash 2017-05-31 16:16:30 +02:00
d0k3
4984df1c08 Remove offset hardcoding from AGBSAVE handling 2017-05-31 16:16:29 +02:00
d0k3
48281307a0 Use actual offsets from NCSD in virtual drives 2017-05-31 16:16:29 +02:00
d0k3
90049a5fd3 CXI/NDS Dumper: Create output dir if it doesn't exist
Fixes #76
2017-05-31 16:16:28 +02:00
d0k3
85756eba00 Put NAND backup at the top of the HOME -> More... menu 2017-05-31 16:16:28 +02:00
d0k3
02a8222662 aeskeydb.bin handling improved again 2017-05-31 16:16:28 +02:00
d0k3
bd5f634134 FIRM is the new default build goal 2017-05-31 16:16:28 +02:00
d0k3
2e011a0db0 Fix OTP decryption (M:/otp_dec.mem) 2017-05-31 16:16:28 +02:00
d0k3
c4c464cf5c Updated aeskeydb.bin format
... now supports retail & devkit keys in one file and initialization
vectors
2017-05-31 16:16:27 +02:00
d0k3
5a5b60c31e Fix: mentions of A9LH in user prompts
Fixes #65
2017-05-31 16:16:27 +02:00
LegoFigure11
de5d102845 Fix typo 2017-05-20 22:52:39 +10:00
d0k3
028ef3a5f4 Removed the obsolete bootrom.mem / bootrom_unp.mem access 2017-05-20 13:46:04 +02:00
d0k3
80352dfcad Updated readme file 2017-05-19 16:59:58 +02:00
d0k3
7d4a5dd407 Removed "helpful hints", no more relevant under sighax 2017-05-19 16:59:58 +02:00
d0k3
d314834986 Added ability to build FIRMs 2017-05-19 16:59:57 +02:00
d0k3
4a241c7fd9 Fix OTP crypto for devkits 2017-05-19 16:59:57 +02:00
d0k3
ac4246c75f Sighax compatibility changes
* Load OTP hash directly from OTP if available
* Enable access to otp, boot9 and boot11
* Add OTP decryption (via key/iv in boot9)
2017-05-19 16:59:57 +02:00
d0k3
c23c9c2476 Made topdown mode the default 2017-05-19 02:40:57 +02:00
d0k3
84c49ca4b8 Added ability to rename game (NCCH/NCSD/CIA/NDS) files 2017-05-19 02:29:23 +02:00
d0k3
b32a49131e Fix bad ARM9RAM extended offset in vmem.c 2017-05-17 13:55:55 +02:00
d0k3
a6fa7042d5 Allow dumping CXIs from TMDs 2017-05-17 01:19:03 +02:00
d0k3
0e3433385f Fix hexviewer in topdown mode 2017-05-17 01:19:03 +02:00
d0k3
fd87a2763a Improve GetGoodName() function 2017-05-17 01:18:49 +02:00
d0k3
d7e2f45256 Use good names in CIA builder and NCCH cryptor 2017-05-16 16:08:38 +02:00
d0k3
51a262db73 Show progress when parsing titles 2017-05-16 16:08:03 +02:00
d0k3
19bae17b7d Allow direct search for titles
... press R+A on titles folders
2017-05-15 23:26:24 +02:00
d0k3
8b22dc6a28 Fix displaying title info for NTR/TWL TMD 2017-05-15 23:26:24 +02:00
d0k3
7dc672a647 Introduce GetGoodName() function 2017-05-15 23:26:24 +02:00
d0k3
6a5b13ea09 Sourcecode cleanup / reorganization 2017-05-15 23:26:23 +02:00
d0k3
e510ac76c4 Improved naming routines for building CIAs and de/encryption 2017-05-09 22:34:35 +02:00
d0k3
41a25cee16 Show helpful hints when decryption / injecting H&S fails 2017-05-08 20:54:26 +02:00
d0k3
96d70aaa01 Process full media units in ExeFS 2017-05-03 01:15:47 +02:00
d0k3
fe19600828 Improve top-down screen mode 2017-04-26 01:53:13 +02:00
d0k3
893f98b343 Allow switching screens via a #define
... #define SWITCH_SCREENS (in common.h?) to enabled this
2017-04-24 21:48:21 +02:00
d0k3
761a3a7a91 Disable size checks for essential backup 2017-04-24 12:29:00 +02:00
Devon Maloney
33fabef720 Fix spelling in readme 2017-04-24 12:28:59 +02:00
d0k3
71138c7578 Improved detection for TWLN public.sav images 2017-04-24 12:28:59 +02:00
d0k3
a8bf80ee2a Fix SD mount issues 2017-04-24 12:28:59 +02:00
d0k3
51a254a9b9 Updated sdmmc.c
.. thanks @Gelex, @TuxSH, @AuroraWright, @Normmatt!
2017-04-24 01:59:25 +02:00
d0k3
dd36d00a66 Updated FATFS R0.12b to R0.12c 2017-04-21 12:10:40 +02:00
d0k3
c55b1b712d Build the output path if it doesn't exist
... for decTitlekeys.bin / encTitlekeys.bin / seeddb.bin / aeskeydb.bin
2017-04-20 12:31:05 +02:00
d0k3
f5d20aa3b5 Also handle multi NANDs in GW EmuNAND format
Fixes #48
2017-04-19 14:26:09 +02:00
d0k3
f3b28ad5e0 Update readme file 2017-04-19 14:14:10 +02:00
d0k3
5e426f2694 Include NAND CID & OTP hash in essential backup 2017-04-19 14:14:02 +02:00
d0k3
1aef326b98 Mount support for aeskeydb.bin files 2017-04-18 17:27:44 +02:00
d0k3
b278be0b49 Add options for building / decrypting / encrypting aeskeydb.bin 2017-04-18 17:26:53 +02:00
d0k3
679d90dea7 Updated file type detection routines
... now also detects aeskeydb.bin & legacy slop0x??Key?.bin files
2017-04-18 01:09:31 +02:00
d0k3
60e2479b16 Handle write permissions when build titlekey / seed db 2017-04-18 01:09:31 +02:00
Wolfvak
8295a2eef2 increase ramdrive storage size, reorganized the memory layout 2017-04-18 01:09:30 +02:00
d0k3
f6f45f242e Show icon.bin for mounted CIAs 2017-04-12 01:05:22 +02:00
d0k3
729997078e Updated readme file 2017-04-12 00:41:10 +02:00
d0k3
89b6946789 Added ability to build seeddb.bin
... plus new entry in HOME more... menu
2017-04-12 00:27:02 +02:00
saibotu
1c14730f8f Added .tik extension to tickets 2017-04-08 21:17:54 +02:00
saibotu
6f82843a05 Fixed ticket.db parsing 2017-04-08 21:17:54 +02:00
d0k3
dd377dbf8e Enable building titlekey databases 2017-04-08 21:17:54 +02:00
d0k3
f856211773 Better detection routines for H&S injects 2017-04-07 15:32:15 +02:00
saibotu
995f57ab23 Fixed permission checks on copies to virtual drives 2017-04-07 15:32:00 +02:00
saibotu
a4e061aea6
Fixed CMAC fixing 2017-04-02 19:38:42 +02:00
d0k3
0956e62b9b Fix: illegal chars in all cart names 2017-03-31 03:15:48 +02:00
d0k3
c19bc1c464 Add title info display for NDS files 2017-03-31 03:14:07 +02:00
d0k3
b9501318c5 Add title info display for SMDH/NCCH/NCSD/CIA/TMD 2017-03-30 14:30:45 +02:00
lilymaniac
433d79d050 Use proper TIDLow for KOR N3DS H&S
* 20027300, not 00027300
 * This fixes H&S inject on KOR N3DS
2017-03-30 13:49:37 +02:00
d0k3
e6754c367f Only allow CTRNAND transfer in A9LH 2017-03-24 21:22:49 +01:00
d0k3
bf1f536b0e Updated readme file 2017-03-24 21:13:59 +01:00
d0k3
a0e65c01bc Improved CTRNAND transfer method 2017-03-23 19:40:27 +01:00
d0k3
4dba221bfd Cleanup Makefile 2017-03-23 19:40:27 +01:00
d0k3
7904b06bc7 Permissions system: also protect LocalFriendCodeSeed_A 2017-03-23 19:40:27 +01:00
d0k3
2dbdeff0fd Fix #31 2017-03-23 12:50:16 +01:00
d0k3
181749c69e Improve / fix readme file 2017-03-22 11:59:14 +01:00
d0k3
f4cd9f384d Added drives info to readme file 2017-03-22 01:03:03 +01:00
d0k3
c08e6e916f Copy to 0:/gm9out for dirs
On R+A
2017-03-20 02:57:13 +01:00
d0k3
3a22496705 Ignore directories when searching folders 2017-03-20 02:13:51 +01:00
d0k3
6a8b97c3e5 Handle incomplete DLCs when building CIA from TMD 2017-03-15 12:52:12 +01:00
d0k3
d6df1efad3 Fix invalid chars in cart titles 2017-03-14 01:51:57 +01:00
d0k3
fd91427317 Some minor cosmetics and improvements 2017-03-14 01:51:47 +01:00
d0k3
2d0abe2e49 Make extra clear that SysNAND lvl3 permissions are dangerous 2017-03-10 18:52:39 +01:00
d0k3
8957d74016 Improved splash screen
o including release / hourly links
o new SafeMode9 splash based on @Ordim3n's work
2017-03-10 13:47:16 +01:00
d0k3
d1ab7602b9 Improved TWL cart dumper code thanks to @Normmatt
... uses the internal timer for accurate timings now
2017-03-10 12:49:02 +01:00
d0k3
7ca396ccfb Improve start.s file (thanks to @TuxSH and @Wintermute) 2017-03-10 12:22:30 +01:00
d0k3
d8aca859bc Fix NAND header validation 2017-03-10 12:21:58 +01:00
d0k3
c12d944076 Show splash screen when initializing 2017-03-09 14:35:36 +01:00
d0k3
6597a5e30e Updated README.md file
... also including new GodMode9 logo
2017-03-03 13:24:35 +01:00
d0k3
e502ad1d99 Provide the tools for CTR transfers (A9LH only) 2017-03-02 22:44:30 +01:00
d0k3
55e3da2e3c Fix / improve the path copy function
This previously failed when copying dirs with a subdir depth > 7
2017-03-02 22:44:30 +01:00
d0k3
8535fcf163 Handle SD card inserts / ejects 2017-03-02 22:44:11 +01:00
d0k3
5c566ced14 Fix: Backing up NAND from home menu 2017-02-28 18:00:14 +01:00
d0k3
35c87abf10 Use a bigger SELF_MAX_SIZE for payload size 2017-02-28 18:00:14 +01:00
d0k3
aa8ede3543 Handle NAND header when safe restoring (only if required!) 2017-02-28 18:00:14 +01:00
d0k3
b575fac6ad Misc code reorganization & cleanup 2017-02-28 18:00:02 +01:00
d0k3
d7ffe06aeb Allow mounting images from bonus drive and ramdrive 2017-02-28 16:10:09 +01:00
d0k3
a96df06041 Fix #28 2017-02-28 15:57:14 +01:00
d0k3
0aec26cfcf Build output path if it doesn't exist (when required) 2017-02-28 15:47:49 +01:00
d0k3
f83b34d436 New HOME more... menu
Also: improved H&S inject and easy way to restore old H&S
2017-02-28 04:10:23 +01:00
d0k3
63527b3467 Added ability to analyze dirs and drives 2017-02-27 02:07:27 +01:00
d0k3
e8fea8cf19 Fix: Display issues for mounted CIA files 2017-02-27 02:06:52 +01:00
d0k3
a09711afe0 Fix: Deleting files and creating dirs in alias drives 2017-02-26 14:44:15 +01:00
d0k3
c031e6e03b Improve devkit support for NCCH / CIA 2017-02-26 14:04:03 +01:00
d0k3
7d08bebf99 Write arm9loaderhax_si.bin instead of arm9loaderhax.bin after format 2017-02-26 13:36:03 +01:00
d0k3
81e7b1fbb6 Improved unit type detection code 2017-02-26 13:35:37 +01:00
d0k3
cbcdea231a Merge branch 'master' of https://github.com/d0k3/GodMode9 2017-02-25 15:33:19 +01:00
Wolfvak
87929cae38 Update start.s (#27) 2017-02-25 15:32:00 +01:00
d0k3
877daf9179 Makefile cleanup 2017-02-24 21:15:55 +01:00
d0k3
d41d2fff82 Reduced the size limit of the bonus drive to 4MB 2017-02-24 18:12:36 +01:00
d0k3
71e433643e GodMode9 v1.0.0 (!!!) 2017-02-23 22:02:35 +01:00
d0k3
dbda964f5a Updated readme file 2017-02-23 22:02:25 +01:00
d0k3
25bcb138c0 Fix bootup times for small NANDs 2017-02-23 22:02:02 +01:00
d0k3
fe62480cd3 Some minor improvements
o Reload current dir after updating embedded backup
o Payload is now available in mem for GW entyrpoint, too
o Fix building .3DSX file
2017-02-23 19:18:33 +01:00
Wolfvak
d0c4e11bad Merged linker scripts and bootstrapping code 2017-02-23 14:49:39 +01:00
d0k3
ad4e6b33cf Add hint about HOME menu 2017-02-22 23:44:57 +01:00
d0k3
29d8ac186f Improved SD format dialogue 2017-02-22 23:27:34 +01:00
d0k3
0d5638c3a6 Some minor cosmetics 2017-02-22 18:44:39 +01:00
d0k3
d5e1b30425 Updated permissions system for non A9LH entrypoints 2017-02-22 18:43:57 +01:00
d0k3
5f252a3a34 Updated .ld files thanks to @Wolfvak 2017-02-22 18:00:49 +01:00
d0k3
06eaf679b9 Properly check for /Nintendo 3DS/ path write permission 2017-02-22 17:59:33 +01:00
d0k3
12e9ca82d1 Include essential.exefs file in virtual NAND (if available) 2017-02-22 17:41:18 +01:00
d0k3
e772d1b2f7 Don't overwrite the essential backup on safe restore 2017-02-22 17:41:01 +01:00
d0k3
f76c753340 Inject essential backup to NAND on safe restore 2017-02-21 22:22:37 +01:00
d0k3
56aff4dd4c Only offer bonus drive with enough space
... also fix remounting bonus drive after image mount.
2017-02-21 16:19:32 +01:00
d0k3
2e8ed9e48f Update BrahmaLoader submodule 2017-02-20 20:47:49 +01:00
d0k3
e2c799ca5d Allow setting up a bonus drive on unused space 2017-02-20 20:47:33 +01:00
d0k3
1348b7ca03 Fix warnings for most recent devKitArm 2017-02-17 15:54:37 +01:00
d0k3
1129c710d7 Virtual files: use u64 for offset / size 2017-02-17 04:01:25 +01:00
d0k3
034564ef93 Display extended area in virtual NAND drive 2017-02-17 03:47:08 +01:00
d0k3
005a850963 Remove meaningless virtual A9LH area flag 2017-02-17 03:31:14 +01:00
d0k3
89b987b1c0 Enabled embedded backups for NAND images 2017-02-17 03:28:53 +01:00
d0k3
1764a1b271 Allow split cart dumps for 4GB carts 2017-02-16 15:44:17 +01:00
d0k3
08b858a8cb Increase TMD_MAX_CONTENTS 2017-02-16 12:03:14 +01:00
d0k3
80dada9c16 Don't allow unlocking all write permissions at once 2017-02-16 02:44:49 +01:00
d0k3
23d50fb718 Fix ticket.db mounting categories 2017-02-16 02:26:25 +01:00
d0k3
a9d778823f Completely revised permission system 2017-02-16 02:26:13 +01:00
d0k3
f606fec7ea Updated readme file 2017-02-12 16:53:58 +01:00
d0k3
335476b295 Detect support file types 2017-02-12 16:31:35 +01:00
d0k3
7a7bc96a9b Full mount compatibility for all known FIRM versions 2017-02-12 16:00:59 +01:00
d0k3
ea00a3217a Preliminary ticket.db mount support 2017-02-12 14:12:34 +01:00
d0k3
f5694cc16d Handle titlekeys in devkit tickets 2017-02-10 20:28:18 +01:00
d0k3
c93295df42 Improve FIRM v2.1.0 mount code
... maybe all older FIRMS, unsure.
2017-02-10 17:06:16 +01:00
d0k3
3ac2297f39 Updated readme file 2017-02-10 16:31:18 +01:00
d0k3
0d36f497b2 Allow alternative filenames for NUS / CDN content 2017-02-10 16:12:00 +01:00
d0k3
58eaffc577 File handling: return to base menu when A is pressed 2017-02-10 15:23:46 +01:00
d0k3
704d6725c4 Group drives by NAND source 2017-02-10 15:04:31 +01:00
d0k3
d05a72b05a Fix ramdrive init and deinit 2017-02-10 15:02:13 +01:00
d0k3
b3d9394877 Show number of selected files in A button menu 2017-02-09 14:36:28 +01:00
d0k3
6cf3117bc3 Fix and improve CMAC calculation dialogue 2017-02-09 14:36:18 +01:00
d0k3
2d9dabdd0e Don't check meta size when validating CIA headers 2017-02-09 13:41:24 +01:00
d0k3
c20c8ce862 Added ability to calculate & fix CMACs 2017-02-08 23:40:10 +01:00
d0k3
76cfc03a66 Enable direct decrypt of NUS / CDN content 2017-02-07 23:18:25 +01:00
d0k3
faba2ebae5 Improve automatic CIA / NCCH output naming 2017-02-07 00:01:47 +01:00
d0k3
53a4687fed Enable building CIAs from CDN / NUS content 2017-02-07 00:01:46 +01:00
d0k3
306f7773ac Enable building NUS/CDN certs for TMD & Ticket 2017-02-06 23:59:25 +01:00
d0k3
4082b4fa00 Fix verification for TMD from NUS/CDN 2017-02-06 02:57:21 +01:00
d0k3
d9e9455be3 Properly detect TMDs from NUS/CDN 2017-02-06 02:53:12 +01:00
d0k3
058fd9f528 Fix IV calculation for uppercase SD paths 2017-02-05 16:15:38 +01:00
d0k3
e35c87335d Added bootrom access to virtual memory drive
... still protected by system, no hype pls.
2017-02-03 15:22:31 +01:00
d0k3
2bb0888973 Improved sector0x96 crypto check 2017-02-03 02:21:55 +01:00
d0k3
c6b6e649b8 Improved progress ETA calculation 2017-02-03 02:21:38 +01:00
d0k3
1ad48969ca Improved FIRM detection / verification routines 2017-02-03 02:21:16 +01:00
d0k3
d2e16c9de5 Added NCCH/NCSD/CIA/BOSS encrypt options 2017-01-31 16:17:16 +01:00
d0k3
1a9cad856d Improved NCCH crypto routines
... now allow on-the-fly reencryption. H&S inject is now also possible
for encrypted CXIs
2017-01-31 16:17:01 +01:00
d0k3
3f31807c75 Added BOSS file decryption & sverification 2017-01-30 20:28:49 +01:00
d0k3
0ea8ac2ff1 Add button sequence to payload launching 2017-01-30 01:49:54 +01:00
d0k3
0c696416c7 Add H&S injection for unencrypted CXIs 2017-01-30 01:49:01 +01:00
d0k3
7fb0f2df0f Added functionality for NCCH encryption 2017-01-30 01:44:52 +01:00
d0k3
cab496b2df fsutil.c: code cleanup 2017-01-27 18:32:52 +01:00
d0k3
3b6932d9ab Changed filetype var handling to bitwise
... cause files can have more than one filetype
2017-01-27 15:29:53 +01:00
d0k3
0abc6e88ff Show ETA for large operations 2017-01-27 13:49:47 +01:00
d0k3
120f5c88a5 Include GM9 payload in virtual mem drive 2017-01-27 13:49:46 +01:00
d0k3
cd7e0341d8 Include rom revision in dump names 2017-01-27 13:49:40 +01:00
Wolf
af32ca3ac5 Added ARM9 payload launching 2017-01-25 23:11:32 +01:00
d0k3
d9dbf14f8b Added NCCH padgen ability
... from ncchinfo.bin
2017-01-25 14:46:29 +01:00
d0k3
8d55cf4a62 Add "Copy to 0:/gm9out" to A button menu 2017-01-24 01:46:28 +01:00
d0k3
40afd65e0e Fix file operations for very large files 2017-01-21 21:31:38 +01:00
d0k3
cc35599b08 Expand the readme credits section 2017-01-20 15:48:01 +01:00
d0k3
a69a1d23ab Vastly improve TWL gamecart compatibility 2017-01-20 15:37:38 +01:00
d0k3
8ab2988258 Allow setting the label when formatting the SD card 2017-01-20 15:37:37 +01:00
d0k3
74ff158c93 Show sizes for virtual drives 2017-01-20 15:37:37 +01:00
d0k3
ae2adbceea Improve virtual cart eject / insert handling 2017-01-20 15:37:28 +01:00
d0k3
0379ba2cd5 Support Multi EmuNAND switching
... in home button menu
2017-01-20 15:37:27 +01:00
d0k3
d15b850a86 Common interface for FAT / virtual files 2017-01-20 15:37:27 +01:00
d0k3
2c271fb97e Fix EmuNAND setup after SD format 2017-01-20 15:37:27 +01:00
d0k3
eae783d6c3 Autodetect cart inserts / ejects 2017-01-20 15:37:26 +01:00
d0k3
b00fb89164 Fix: NCSD header struct too big 2017-01-20 15:37:26 +01:00
d0k3
fa9a2c2fb5 Added virtual gamecart drive 2017-01-20 15:37:04 +01:00
d0k3
1e4be5fe61 Lower restrictions on FAT -> virtual copy operations 2017-01-09 20:07:36 +01:00
d0k3
640c65f18d Fix a typo in AGBSAVE handling 2017-01-05 03:19:06 +01:00
d0k3
d0785b12d1 Handle GBA VC save in virtual NAND drives 2017-01-05 02:50:41 +01:00
d0k3
9432723791 Virtual FIRM: Leave section .bins encrypted 2017-01-02 20:55:36 +01:00
d0k3
900b9ec628 Virtual NAND: access to unused sectors 0x01...0x95 2017-01-02 20:52:54 +01:00
d0k3
9e40ce3e86 Allow NAND safe restore and validation 2017-01-02 17:37:08 +01:00
d0k3
f600402cee Improved the readme formatting 2016-12-26 18:26:12 +01:00
d0k3
ae605246e9 Changed the handling for deleting multiple files
... cursor has to be on a marked file for batch deletion now.
2016-12-26 18:21:05 +01:00
d0k3
0c72ff3ffa Source code reorganization 2016-12-26 18:15:01 +01:00
d0k3
73eff94484 Prevent slot0x??key?.bin file locks
.. actually close the file after key is found
2016-12-26 16:01:57 +01:00
d0k3
f05e77a99f Updated readme file 2016-12-23 18:36:27 +01:00
d0k3
6625df9808 New path for input files: 1:/rw/files9 2016-12-23 17:15:39 +01:00
d0k3
825f94b05b Fix: FIRM mount/decrypt handling 2016-12-23 17:15:18 +01:00
d0k3
3ba8c675db Enable FIRM file mounting 2016-12-22 19:00:03 +01:00
d0k3
2986ce3d5c Fix FatFS compiler warning 2016-12-22 11:44:32 +01:00
d0k3
36f52950e6 Fix a bug in vgame.c
it's a wonder this didn't blow up earlier
2016-12-22 01:35:59 +01:00
d0k3
52ef9c2af3 Enable verification and decryption of FIRM files 2016-12-22 01:35:35 +01:00
d0k3
0fffa3d2ce Cleanup virtual.c source code 2016-12-21 00:31:21 +01:00
d0k3
0e55882468 Fix TMD verification / CIA building for DLC content 2016-12-21 00:30:46 +01:00
d0k3
e38da8a4a8 Improve virtual.c / virtual.h code 2016-12-20 14:45:41 +01:00
d0k3
2a5a738765 Fix ticket.db parser 2016-12-20 14:45:41 +01:00
d0k3
b98bba9a6f Fix verifying CFA NCCH images 2016-12-20 14:45:40 +01:00
d0k3
37e24c1825 Enabled no SD mode 2016-12-20 14:45:32 +01:00
d0k3
c0c13d2f7d Code reorganization / cleanup 2016-12-19 13:50:03 +01:00
d0k3
32c5cd2196 Enable build CIA from NCCH/NCSD 2016-12-19 02:53:06 +01:00
d0k3
fcd61794a8 Various smaller improvements 2016-12-16 15:26:19 +01:00
d0k3
103641fd05 Vastly improved ticket.db parser 2016-12-16 03:35:29 +01:00
d0k3
2a904dc284 Enable build CIA from TMD files 2016-12-16 03:35:21 +01:00
d0k3
1f98f88d87 Better handling for locked files 2016-12-13 17:10:39 +01:00
d0k3
3b60fe2332 Persistent RAMdrive, not coupled to image handling 2016-12-13 16:00:14 +01:00
d0k3
236e037229 Check write permissions when decrypting game file 2016-12-13 14:48:44 +01:00
d0k3
9eb80b375a Enable decryption of CIA/NCCH/NCSD files 2016-12-13 00:20:00 +01:00
d0k3
f53d2808cf Minor code reorganizations 2016-12-11 16:28:51 +01:00
d0k3
a74897c0fb Speedup hexviewer search operations 2016-12-11 15:40:44 +01:00
d0k3
9466fe37d1 gameio.h/.c -> gameutil.h/.c 2016-12-10 15:40:36 +01:00
d0k3
020b1b74b2 Cleanup and reorganize fs.c / fs.h 2016-12-10 15:32:03 +01:00
d0k3
4dc92abef6 Enable mounting RomFS and ExeFS as virtual game images 2016-12-09 21:57:53 +01:00
d0k3
8947db2037 Fix detection of trimmed NCSD images 2016-12-09 16:09:33 +01:00
d0k3
baf1a645ca Also enable verification of TMD files
this verifies all referenced contents
2016-12-09 16:09:22 +01:00
d0k3
fec4f081a0 Fix file lock check routines 2016-12-09 16:09:12 +01:00
d0k3
4431c46a7b Handle write protected files as images 2016-12-08 23:37:20 +01:00
d0k3
a9c9d7a93f Improve image mount path selection 2016-12-08 23:37:19 +01:00
d0k3
67923556da Show a warning when a file is currently locked (on A button) 2016-12-08 23:37:08 +01:00
d0k3
648f314a0a Prevent alignment issues 2016-12-08 22:08:19 +01:00
d0k3
db8bbdb224 Allow (batch) verification of NCCH / NCSD / CIA 2016-12-08 22:06:47 +01:00
d0k3
2e8f6405e7 Miscellaneous cosmetics 2016-12-08 13:18:25 +01:00
d0k3
514e57c1f4 CheckNcchCrypto() -> SetupNcchCrypto() 2016-12-08 13:14:20 +01:00
d0k3
310159f0cb SetNcchKey(): Prevent unnecessary usage of SHA registers 2016-12-08 13:06:56 +01:00
d0k3
eff96b3e5b Reorganized A button file handler 2016-12-07 23:58:03 +01:00
d0k3
da506d3c4a Fix: Mounting public.sav files 2016-12-07 23:39:10 +01:00
d0k3
8e4b04a18e Improved memory buffer organization 2016-12-07 15:12:35 +01:00
d0k3
68b81ade76 Allow mounting public.sav files 2016-12-07 14:23:01 +01:00
d0k3
bb05242494 Fix: Decrypting TWL MBR in GW type EmuNANDs 2016-12-07 00:01:36 +01:00
d0k3
c2a4d5c0d1 Improved and extended aes.c / aes.h
Thanks @Gemarcano
2016-12-07 00:00:05 +01:00
d0k3
ae9a8aaf75 Fix .SHA calculation for A:/B: drives 2016-12-06 22:50:43 +01:00
d0k3
c28943ba13 Fix key setting after slot 0x03
... aka the most annyoing bug of all time
2016-12-06 22:50:12 +01:00
d0k3
8b0f4f2006 Fixed: CFA crypto handling 2016-12-06 15:48:24 +01:00
d0k3
d8442ac0cb On the fly crypto handling for mounted game files 2016-12-06 00:29:12 +01:00
d0k3
f23d2fd30a Proper keydb handling 2016-12-06 00:29:05 +01:00
d0k3
d10315ba64 Reorganized crypto related code to crypto subdir 2016-12-05 22:53:28 +01:00
d0k3
1b4481daa5 Speed up RomFS browsing via lv3 hashes 2016-12-02 16:42:39 +01:00
d0k3
dc3ea378ce Added virtual drive for NAND XORpads 2016-12-02 15:42:05 +01:00
d0k3
bb9b192052 Move bytewise read/write functions vnand.c -> nand.c 2016-12-02 14:08:30 +01:00
d0k3
ddd1dd070b Cleanup vgame.c / vgame.h 2016-12-02 13:26:24 +01:00
d0k3
6bf88bbdfb Enable FATFS file lock (prevents corruption) 2016-12-02 12:59:34 +01:00
d0k3
be91f8f96f Block copying to virtual game drive on UI level 2016-12-02 12:49:41 +01:00
d0k3
790f264a68 Enable recursive copy of virtual directories 2016-12-02 12:45:23 +01:00
d0k3
3dcfdd2b20 Enable recursive search for virtual game drives 2016-12-01 02:13:13 +01:00
d0k3
c2500b138a Fix: crashes on A:/B: hex viewer repeated searches 2016-12-01 01:14:47 +01:00
d0k3
efe4293a58 CiaInfo: also include max # of contents 2016-12-01 00:06:11 +01:00
d0k3
488dd156b5 image.h/.c: use u64 for bytewise functions 2016-12-01 00:06:10 +01:00
d0k3
4da34d3ce4 Fix: don't write .SHA files to drives other than the SD card 2016-12-01 00:06:01 +01:00
d0k3
6e7a55f422 Enable browsing the RomFS dir 2016-11-30 23:41:35 +01:00
d0k3
e2aac33c3d Reorganized virtual path copy code 2016-11-30 23:41:34 +01:00
d0k3
a3744ae7a3 Fix corruption on RAMdrive mount / unmount 2016-11-30 23:41:33 +01:00
d0k3
9af01de7dc Allow mounting images from any FAT based drive 2016-11-30 23:41:32 +01:00
d0k3
4df338b8a0 Code cleanup: vgame.c/vgame.h 2016-11-30 23:41:31 +01:00
d0k3
72c5f21339 Fixed NCCH mount handling for ExeFS 2016-11-30 23:41:30 +01:00
d0k3
521514c8be Prevent unneccessary remounts 2016-11-30 23:41:29 +01:00
d0k3
eac1591be3 Prevent a possible bug for alias drives 2016-11-30 23:41:28 +01:00
d0k3
34b58e979a Enable browsing the ExeFS dir 2016-11-30 23:41:27 +01:00
d0k3
f0492ad02d Check for mount state when detecting image drives 2016-11-30 23:41:26 +01:00
d0k3
1c636b1132 Allow copy files from ramdrive to virtual 2016-11-30 23:41:25 +01:00
d0k3
f5c0e6eb35 Place cursor on mounted image drive after mount 2016-11-30 23:41:24 +01:00
d0k3
2876ebf7ef Show file type for mounted game images 2016-11-30 23:41:16 +01:00
d0k3
cdb9000e6a Get rid of FindVirtualFileBySize() 2016-11-28 21:22:44 +01:00
d0k3
ddac828dcb Enabled virtual dir handling 2016-11-28 21:22:30 +01:00
d0k3
58d7573ef5 Enable mounting of NCCH files 2016-11-28 01:19:12 +01:00
d0k3
622947f63a Enable mounting of NCSD files 2016-11-26 15:37:53 +01:00
d0k3
2c5a46522d Handle Virtual Game Drive via image.h 2016-11-26 14:25:10 +01:00
d0k3
9d42c04271 Updated FatFS to R.12b 2016-11-25 21:31:57 +01:00
d0k3
79dec02e92 Enabled (preliminary) CIA mounting support 2016-11-25 18:30:01 +01:00
d0k3
2870621dca Introduce filetype.h / filetype.c 2016-11-25 13:34:01 +01:00
d0k3
8fff283a24 Handle image unmounts via DeinitSDCardFS() 2016-11-25 12:41:50 +01:00
d0k3
9a02499175 Handle RAMdrive buffers via common.h 2016-11-25 12:28:34 +01:00
d0k3
4bd787ace9 Introduce ctr_decrypt_boffset() function 2016-11-21 22:50:47 +01:00
d0k3
b70761e6aa Handle buffers via common.h file 2016-11-21 20:05:35 +01:00
d0k3
314ea7793d Fixed a typo 2016-11-21 20:05:28 +01:00
d0k3
049b6b0ea0 Improved virtual file handling 2016-11-15 23:34:21 +01:00
d0k3
943759bee9 Introduce CheckA9lh() function 2016-11-15 23:12:14 +01:00
d0k3
924dd8216e Improved virtual directory handling 2016-11-15 23:06:01 +01:00
d0k3
525b5b8810 Major reorganisation of virtual file code 2016-11-14 22:24:20 +01:00
d0k3
a99aa0790f Reorganize code to new virtual folder 2016-11-14 20:08:14 +01:00
d0k3
168582f395 Better clipboard handling on unmounts 2016-11-02 15:24:22 +01:00
d0k3
b4d3b6f3c3 Add SD format menu on HOME button menu 2016-11-01 16:14:18 +01:00
d0k3
e0e014ec16 Added alternative font
Thanks to @Ennea
2016-10-31 14:12:08 +01:00
d0k3
50450d2a9f Rename alias.h/.c -> sddata.h/.c 2016-10-30 16:20:09 +01:00
d0k3
94c0608477 Handle SD data crypto 2016-10-30 15:57:54 +01:00
d0k3
779b6fe25b Handle write permissions for SD data 2016-10-29 17:15:16 +02:00
d0k3
a9f3b1d6ea Handle /Nintendo 3DS folder deletion 2016-10-29 17:14:24 +02:00
d0k3
8f5cc140b3 Allow delete & create dir in alias drive 2016-10-29 17:14:02 +02:00
d0k3
3c75c13880 Handle drive size for alias drives 2016-10-29 16:57:46 +02:00
d0k3
9c0e6153f0 Introduce DriveType() function
Misc code cleanups & new display for root dirs
2016-10-29 16:02:07 +02:00
d0k3
1fced99d65 Preliminary NAND SD drive support
... no crypto yet. Also some minor bugfixes
2016-10-28 21:30:10 +02:00
d0k3
7f65846499 Added menu on home button 2016-10-22 18:07:20 +02:00
d0k3
5172bf9205 Allow POWER and HOME for poweroff / reboot
... also revised HID functions
2016-10-17 23:45:22 +02:00
d0k3
4abb666c1f Clear screen on exit 2016-09-07 00:21:38 +02:00
d0k3
659e66e1ca Offer SysNAND -> RedNAND clone on SD format 2016-09-07 00:19:12 +02:00
d0k3
26c677b785 Allow cluster size selection on SD format 2016-09-07 00:18:49 +02:00
d0k3
d00eabe9e4 Add aes_cmac() function
... actually unused here.
2016-09-06 23:43:36 +02:00
d0k3
2628082192 Enable compatibility with O3DS NANDs on N3DS 2016-08-10 21:27:58 +02:00
d0k3
7b8b11123a Removed unneeded inittarget() calls
thanks @profi200!
2016-08-10 19:26:06 +02:00
d0k3
10cbc3b3b8 Updated readme file 2016-08-10 19:25:36 +02:00
d0k3
8341d319ee Updated readme file 2016-07-28 03:49:52 +02:00
d0k3
8e61d67dd4 Updated aes.c / aes.h
... thanks to @gemarcano
2016-07-28 03:35:20 +02:00
d0k3
25e007765c Fix move - exist - skip handling 2016-07-28 03:34:39 +02:00
d0k3
03e11e7064 Move font files to subdir 2016-07-27 12:15:15 +02:00
d0k3
5299679cb4 Reverted CakeHax submodule 2016-07-27 03:18:43 +02:00
d0k3
fe14f071d0 Add ahndling for overwrite / skip all existing 2016-07-27 00:19:12 +02:00
d0k3
b46f5ab2ac Fix alignment warnings
Happy now, @Gemarcano? :)
2016-07-26 20:58:41 +02:00
d0k3
f3bdfc2ab6 Fix .travis.yml
... don't do 'release' for now, just a9lh
2016-07-26 19:12:17 +02:00
d0k3
83928cde9a Added R+B shortcut for quick return to root 2016-07-26 18:54:30 +02:00
d0k3
d7d6b18e3d Special handling for found files & folders
Added 'open containing folder' option
2016-07-26 18:54:29 +02:00
d0k3
6c4eba22b3 Show number of search results when searching 2016-07-26 18:54:27 +02:00
d0k3
a06e6619cd Improved display of path / filename in top screen 2016-07-26 18:54:26 +02:00
d0k3
2c782d47c8 Revised / improved file search system
Also includes search button combo in instructions
2016-07-26 18:54:12 +02:00
d0k3
cd17915028 Fix a few cosmetic issues 2016-07-23 17:18:06 +02:00
d0k3
55bc6e0c02 Also show last search results as drive 2016-07-23 17:18:04 +02:00
d0k3
e8cb821b6d Improve marking behaviour 2016-07-23 17:18:02 +02:00
d0k3
27a77cc474 Fix deleting last char on ShowInputPrompt() 2016-07-23 17:17:48 +02:00
d0k3
dfd0a4e306 Enabled basic file searching 2016-07-22 04:22:42 +02:00
d0k3
b51af7ceb4 Use the whole length of the progress bar for text 2016-07-20 15:18:04 +02:00
d0k3
75ce08681d Updated FatFS to v0.12a 2016-07-20 00:30:21 +02:00
d0k3
3d4108d49b Made 6x10 font the default 2016-07-19 23:15:09 +02:00
d0k3
eac5a58ed5 Add alternative fonts 2016-07-19 01:59:11 +02:00
d0k3
0ce32c8d7f Add TWL MBR as virtual file
Update version number (v0.6.0)
2016-07-18 02:44:08 +02:00
d0k3
3eeb5fbca3 Workaround for empty / incompatible EmuNANDs 2016-07-18 02:38:18 +02:00
d0k3
7988a26acc Automatically copy GM9 payload on newly formatted SDs
A9LH only feature
2016-07-18 02:37:51 +02:00
d0k3
6be34ee104 Miscelaneous cosmetics 2016-07-18 02:37:42 +02:00
d0k3
a7b511687b Added ability to format SD cards 2016-07-13 19:59:36 +02:00
d0k3
bf38dbc63b Fixed diskio.c for new sdmmc.c 2016-07-13 19:58:33 +02:00
d0k3
79609cbfe7 Added ability to search for strings and data
... in hexviewer
2016-07-12 18:33:52 +02:00
d0k3
0cf31eb547 New ShowDataPrompt() input prompt 2016-07-12 18:15:45 +02:00
d0k3
f998975d05 Added new locations for otp.bin 2016-07-12 18:12:25 +02:00
d0k3
c14b49f341 Updated sdmmc.c / sdmmc.h
Thanks to @Gemarcano
2016-07-12 18:11:05 +02:00
d0k3
93153f010e Extended write permission system for A9LH regions 2016-07-01 01:38:57 +02:00
d0k3
c4d2ffff90 Correctly handle ImgNAND virtual permissions 2016-07-01 00:35:10 +02:00
d0k3
b433147b81 Updated submodules 2016-06-30 14:44:10 +02:00
d0k3
c6b494253c Tweaked arrow button react times 2016-06-18 15:31:31 +02:00
d0k3
5d69a7186f Improved injection / paste handling 2016-06-18 15:26:11 +02:00
d0k3
e388dd4ca7 Exclude certain files from injection
No virtual as origin, no injecting file into itself
2016-06-18 15:23:21 +02:00
d0k3
d4df8bbb3d Allow START as alternate exit button in HexViewer 2016-06-18 15:07:57 +02:00
d0k3
d081645ea2 Fix cosmetic issues 2016-06-17 19:49:19 +02:00
d0k3
56ac8c1e68 Allow injecting files into files 2016-06-17 19:28:43 +02:00
d0k3
3a59f37fc9 Improved FileSetData() function 2016-06-17 17:12:11 +02:00
d0k3
fc35bed752 Allow handling of and verification via .SHA files 2016-06-16 14:33:03 +02:00
d0k3
0c42a32d0d Allow goto offset in hex editor 2016-06-13 23:51:41 +02:00
d0k3
964327650f Updated version number 2016-06-10 17:32:47 +02:00
d0k3
42fafc5d9b Cleaned up start.s files 2016-06-10 17:06:09 +02:00
d0k3
eaef2e8dcf Remove half-copied files 2016-06-10 17:04:14 +02:00
d0k3
d83ad781ee Show wait message when deleting 2016-06-10 17:03:54 +02:00
d0k3
c948a5a471 ui.c: Allow global setting of string buffer size 2016-06-10 17:03:51 +02:00
d0k3
0af6dfe463 Show percentage in progress view 2016-06-10 17:03:42 +02:00
d0k3
00101de4f4 Auto-adjust scroll after big delete operations 2016-06-10 14:23:37 +02:00
d0k3
a74f4c79ca Enable setting up 0x05 KeyY on FIRM81 2016-06-10 02:53:44 +02:00
d0k3
297bc2ec1b Fix write permissions when RAMdrive is mounted 2016-05-30 16:17:09 +02:00
d0k3
6e9a378a36 Added info about building SafeMode9 to readme 2016-05-30 16:03:14 +02:00
d0k3
1d1c7f7663 Release version v0.5.0 2016-05-30 15:49:21 +02:00
d0k3
a40e617274 Improved scroll delay handling 2016-05-30 03:03:40 +02:00
d0k3
b572dac3be Introduce SafeMode9 2016-05-30 02:24:47 +02:00
d0k3
c010efb236 Use timer for continuous scrolling 2016-05-30 01:56:03 +02:00
d0k3
0aae5408b8 Totally revised write permission system
... now allows granular control
2016-05-29 14:45:12 +02:00
d0k3
7082457918 Misc cosmetic improvements 2016-05-27 01:21:05 +02:00
d0k3
c1b69229ad Check for read only files in hex editor 2016-05-26 21:09:01 +02:00
d0k3
d367c926f9 Improved handling for existing files 2016-05-26 21:08:35 +02:00
d0k3
32e0b20f07 Also check origin permissions when moving files 2016-05-26 21:07:18 +02:00
d0k3
bc007b94fa Edit virtual OTP file for later reference
... commented out for now
2016-05-26 21:04:46 +02:00
d0k3
b1e375cd70 Added license info to readme 2016-05-26 21:04:06 +02:00
d0k3
407a64df25 Allow for reversion of hex edits 2016-05-21 22:04:03 +02:00
d0k3
fa49efbdbd Fix encrypting the sector0x96 2016-05-21 17:02:35 +02:00
d0k3
172a7c637d Fix finding wrong name virtual files 2016-05-21 15:18:36 +02:00
d0k3
98344a2076 Fix hex-editing virtual files 2016-05-21 14:50:01 +02:00
d0k3
6a6e28afda Handle copying to the same path 2016-05-20 14:12:03 +02:00
d0k3
84a9f892a9 Enable hidden shutdown combo 2016-05-19 22:26:28 +02:00
d0k3
88a62d8f2e Added ability to do simple hexedits 2016-05-19 21:24:49 +02:00
d0k3
f4622d5bff Get rid of unnecessary second framebuffer 2016-05-18 23:46:22 +02:00
d0k3
ceca36fdc7 Use bottom screen for hex viewer
... thanks to @al3x10m for the idea
2016-05-18 00:05:24 +02:00
d0k3
2e06480fa1 Use RedNAND as default when EmuNAND not setup 2016-05-15 18:32:53 +02:00
d0k3
67b54ec633 Enable crypto for sector 0x96 2016-05-15 18:16:45 +02:00
d0k3
f448f48ad7 Merge pull request #7 from d0k3/ramdrive
Enable RAM drive feature
2016-05-02 12:37:16 +02:00
d0k3
51e7361be0 Increased version number 2016-05-02 12:36:39 +02:00
d0k3
59f7d6173e Proper write protection handling for RAM drives 2016-05-02 12:36:38 +02:00
d0k3
e3e8b40061 Use more space for N3DS RAMdrive 2016-05-02 12:36:36 +02:00
d0k3
89cca90447 Keep RAMdrive mounted when unmounting SD 2016-05-02 12:36:35 +02:00
d0k3
8a65f79712 Added ability to mount a ramdrive 2016-05-02 12:36:22 +02:00
d0k3
6bd1cace1f Misc diskio.c / start.s improvements 2016-05-01 15:38:57 +02:00
d0k3
3aada172b9 Introduce sha_quick() function 2016-04-29 02:29:31 +02:00
d0k3
bc102c3645 Allow moving files & folders 2016-04-29 02:21:36 +02:00
d0k3
ed77cde373 Various source code improvements 2016-04-29 00:12:09 +02:00
d0k3
4a89682cae Ended bootstrap support
... the bootstrap build goal is now called 'a9lh'
2016-04-27 23:04:11 +02:00
d0k3
52dc94ddfd Update readme, no more slot0x05keyY.bin required 2016-04-27 22:45:30 +02:00
d0k3
fbe8f55a81 File copying: better handling for user errors 2016-04-27 22:03:25 +02:00
d0k3
897aada958 Improve string input behaviour 2016-04-27 16:14:04 +02:00
d0k3
24266a22b8 Deprecated GW Launcher.dat entrypoint
... use CakeHax instead
2016-04-25 22:18:22 +02:00
d0k3
e9b010d1ef Slot0x05 keyY is no more required 2016-04-25 22:10:22 +02:00
d0k3
e5c7e4320f Removed GPL v3 license text file
... this is licensed under the GPL v2, see license.txt
2016-04-25 02:59:19 +02:00
d0k3
e01e60fbdd Fix arm9ext.mem virtual size 2016-04-25 02:57:01 +02:00
d0k3
663aa681f6 Added ability to calculate & compare file SHA-256 2016-04-25 02:46:32 +02:00
d0k3
369061cf5b Use START + R for poweroff 2016-04-23 20:09:43 +02:00
d0k3
9e4c073933 Add a warning when overwriting A9LH 2016-04-22 17:47:13 +02:00
d0k3
d9fa450e66 Fix bug in i2c.c (thanks, anon!) 2016-04-22 15:51:48 +02:00
d0k3
34fbebebef Merge pull request #6 from d0k3/test2
Fix virtual memory drive accesses
2016-04-22 15:50:49 +02:00
d0k3
712f06789a Give access to N3DS extended memory regions 2016-04-22 15:48:57 +02:00
d0k3
10a9cba119 Update start.s files 2016-04-21 15:28:53 +02:00
d0k3
ecb63739eb Merge pull request #5 from fox8091/master
Fix DTCM address
2016-04-19 22:38:21 +02:00
fox8091
d4b489c94e Fix DTCM address 2016-04-19 13:29:59 -05:00
d0k3
a52647aca0 Fix GW Launcher.dat bootup
This is a workaround,, not a good solution
2016-04-14 11:28:08 +02:00
481 changed files with 124074 additions and 15425 deletions

40
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@ -0,0 +1,40 @@
---
name: Bug report
about: Report a bug you found in GodMode9
title: "[BUG] ..."
labels: bug
assignees: ''
---
---
name: Bug report
about: Report a bug you found
title: "[BUG] ..."
labels: bug
assignees: ''
---
**So you want to report a bug?**
Hold on, there are ways you could make things easier for us:
* Give a clear description of the bug (what happened?).
* Give us clear steps to reproduce (when/how did it happen?).
* Give us info about your system (where did it happen?).
* A photograph or even a short video of the bug happening is always helpful!
**Info about your system**
Include this info to make our work easier:
* Console type (O3DS/N3DS)
* Anything special about your console? (defects, custom modifications,...)
* Bootloader (boot9strap/fastboot3ds)
* Did you chainload GodMode9 via Luma?
* Helpful hint: *if you followed the Guide, boot9strap is your bootloader and Luma is your chainloader.*
**Help yourself**
*Especially for any kind of boot issue ("GodMode9 doesn't boot")*, but also in many other cases these steps make a lot of sense and we will ask you to do them anyways:
* Check your SD card (using h2testw, f.e.) or try a different one (you wouldn't believe how common failing/fake SD cards are, and what kinds of bugs are caused by them).
* Switch to fastboot3DS using [https://github.com/d0k3/OpenFirmInstaller](OpenFirmInstaller).
**Have you actually read this?**
[] I have read the information above

View File

@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for this GodMode9
title: "[FEATURE REQUEST] ..."
labels: feature request
assignees: ''
---
**Got a great idea on how to improve GodMode9?**
That's always appreciated. Please make sure you add all the required info here.
**Describe the feature you'd like**
Add a clear and concise description of what you want to happen.
**Describe alternatives you've considered**
Add a clear and concise description of any alternative solutions or features you've considered.

42
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,42 @@
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
container: devkitpro/devkitarm
steps:
- uses: actions/checkout@v1
- name: Fix apt sources
run: |
apt-get update
apt-get -y install dirmngr
echo 'deb http://us.archive.ubuntu.com/ubuntu/ bionic main' >> /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
apt-get update
- name: Install and update packages
run: |
apt-get -y install python3 python3-pip p7zip-full libarchive13
python3 --version
python3 -m pip install --upgrade pip setuptools
python3 -m pip install cryptography git+https://github.com/TuxSH/firmtool.git
- name: Build Project
run: make release -j$(nproc)
- name: Prepare build artifact
working-directory: release
run: |
ZIPNAME=$(ls GodMode9-*.zip)
rm $ZIPNAME
echo "OUTNAME=${ZIPNAME%.zip}" >> $GITHUB_ENV
- uses: actions/upload-artifact@v4
with:
name: ${{ env.OUTNAME }}
path: release/*
if-no-files-found: error

20
.gitignore vendored
View File

@ -1,8 +1,11 @@
# Object files
*.d
*.o
*.ko
*.obj
*.elf
*.map
*.dis
# Precompiled Headers
*.gch
@ -31,8 +34,25 @@
# Debug files
*.dSYM/
# OS leftovers
desktop.ini
.DS_Store
# Sublime files
*.sublime-*
# Visual Studio Code files
.vscode
# Build directories
/build
/output
/release
# Build leftovers
/data/README_internal.md
# User additions
/zzz_backup
/arm9/source/language.inl
*.trf

11
.gitmodules vendored
View File

@ -1,11 +0,0 @@
[submodule "CakeHax"]
path = CakeHax
url = https://github.com/mid-kid/CakeHax
[submodule "BrahmaLoader"]
path = BrahmaLoader
url = https://github.com/d0k3/BrahmaLoader
ignore = dirty
[submodule "CakesROP"]
path = CakesROP
url = https://github.com/mid-kid/CakesROP
ignore = dirty

View File

@ -1,13 +0,0 @@
language: c
before_install:
- wget http://sourceforge.net/projects/devkitpro/files/Automated%20Installer/devkitARMupdate.pl
- export DEVKITPRO=/home/travis/devkitPro
- export DEVKITARM=${DEVKITPRO}/devkitARM
install:
- sudo perl devkitARMupdate.pl
- sudo apt-get -qq install lftp p7zip-full
script:
- make release

@ -1 +0,0 @@
Subproject commit 439432ecf9121a03198749cad8fd23194f1d5bc6

@ -1 +0,0 @@
Subproject commit 6b8fca0b37a370a605f76b34b133da91a0b40f5e

@ -1 +0,0 @@
Subproject commit b14debbd349c1990aab65716086c8d3809ce90bf

674
LICENSE
View File

@ -1,674 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
{project} Copyright (C) {year} {fullname}
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

261
Makefile
View File

@ -1,193 +1,128 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
include $(DEVKITARM)/base_tools
include Makefile.common
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
# SPECS is the directory containing the important build and link files
#---------------------------------------------------------------------------------
export TARGET := GodMode9
BUILD := build
SOURCES := source source/fatfs source/nand source/abstraction
DATA := data
INCLUDES := include source source/fatfs source/nand
# Base definitions
export VERSION := $(shell git describe --tags --abbrev=8)
export DBUILTS := $(shell date +'%Y%m%d%H%M%S')
export DBUILTL := $(shell date +'%Y-%m-%d %H:%M:%S')
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -mthumb -mthumb-interwork -flto
export OUTDIR := output
export RELDIR := release
export COMMON_DIR := ../common
CFLAGS := -g -Wall -O2 -flto\
-march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
-ffast-math -std=c99\
$(ARCH)
CFLAGS += $(INCLUDE) -DEXEC_$(EXEC_METHOD) -DARM9
CFLAGS += -DBUILD_NAME="\"$(TARGET) (`date +'%Y/%m/%d'`)\""
ifneq ($(strip $(THEME)),)
CFLAGS += -DUSE_THEME=\"\/$(THEME)\"
# Definitions for initial RAM disk
VRAM_TAR := $(OUTDIR)/vram0.tar
VRAM_DATA := data/*
VRAM_FLAGS := --make-new --path-limit 99
ifeq ($(NTRBOOT),1)
VRAM_SCRIPTS := resources/gm9/scripts/*
endif
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
# Definitions for translation files
JSON_FOLDER := resources/languages
TRF_FOLDER := resources/gm9/languages
ASFLAGS := -g $(ARCH) -DEXEC_$(EXEC_METHOD)
LDFLAGS = -nostartfiles -g $(ARCH) -Wl,-Map,$(TARGET).map
SOURCE_JSON := $(JSON_FOLDER)/source.json
LANGUAGE_INL := arm9/source/language.inl
ifeq ($(EXEC_METHOD),GATEWAY)
LDFLAGS += --specs=../gateway.specs
else ifeq ($(EXEC_METHOD),BOOTSTRAP)
LDFLAGS += --specs=../bootstrap.specs
endif
JSON_FILES := $(filter-out $(SOURCE_JSON),$(wildcard $(JSON_FOLDER)/*.json))
TRF_FILES := $(subst $(JSON_FOLDER),$(TRF_FOLDER),$(JSON_FILES:.json=.trf))
LIBS :=
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS :=
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT_D := $(CURDIR)/output
export OUTPUT := $(OUTPUT_D)/$(TARGET)
export RELEASE := $(CURDIR)/release
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
ifeq ($(OS),Windows_NT)
ifeq ($(TERM),cygwin)
PY3 := py -3 # Windows / CMD/PowerShell
else
PY3 := py # Windows / MSYS2
endif
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
PY3 := python3 # Unix-like
endif
#---------------------------------------------------------------------------------
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
# Definitions for ARM binaries
export INCLUDE := -I"$(shell pwd)/common"
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export ASFLAGS := -g -x assembler-with-cpp $(INCLUDE)
export CFLAGS := -DDBUILTS="\"$(DBUILTS)\"" -DDBUILTL="\"$(DBUILTL)\"" -DVERSION="\"$(VERSION)\"" -DFLAVOR="\"$(FLAVOR)\"" \
-g -Os -Wall -Wextra -Wcast-align -Wformat=2 -Wno-main \
-fomit-frame-pointer -ffast-math -std=gnu11 -MMD -MP \
-Wno-unused-function -Wno-format-truncation -Wno-format-nonliteral $(INCLUDE) -ffunction-sections -fdata-sections
export LDFLAGS := -Tlink.ld -nostartfiles -Wl,--gc-sections,-z,max-page-size=4096
ELF := arm9/arm9_code.elf arm9/arm9_data.elf arm11/arm11.elf
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
.PHONY: all firm $(VRAM_TAR) elf release clean
all: firm
.PHONY: common clean all gateway bootstrap cakehax cakerop brahma release
#---------------------------------------------------------------------------------
all: brahma
common:
@[ -d $(OUTPUT_D) ] || mkdir -p $(OUTPUT_D)
@[ -d $(BUILD) ] || mkdir -p $(BUILD)
submodules:
@-git submodule update --init --recursive
gateway: common
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile EXEC_METHOD=GATEWAY
@cp resources/LauncherTemplate.dat $(OUTPUT_D)/Launcher.dat
@dd if=$(OUTPUT).bin of=$(OUTPUT_D)/Launcher.dat bs=1497296 seek=1 conv=notrunc
bootstrap: common
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile EXEC_METHOD=BOOTSTRAP
cakehax: submodules common
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile EXEC_METHOD=GATEWAY
@make dir_out=$(OUTPUT_D) name=$(TARGET).dat -C CakeHax bigpayload
@dd if=$(OUTPUT).bin of=$(OUTPUT).dat bs=512 seek=160
cakerop: cakehax
@make DATNAME=$(TARGET).dat DISPNAME=$(TARGET) GRAPHICS=../resources/CakesROP -C CakesROP
@mv CakesROP/CakesROP.nds $(OUTPUT_D)/$(TARGET).nds
brahma: submodules bootstrap
@[ -d BrahmaLoader/data ] || mkdir -p BrahmaLoader/data
@cp $(OUTPUT).bin BrahmaLoader/data/payload.bin
@cp resources/BrahmaAppInfo BrahmaLoader/resources/AppInfo
@cp resources/BrahmaIcon.png BrahmaLoader/resources/icon.png
@make --no-print-directory -C BrahmaLoader APP_TITLE=$(TARGET)
@mv BrahmaLoader/output/*.3dsx $(OUTPUT_D)
@mv BrahmaLoader/output/*.smdh $(OUTPUT_D)
release:
@rm -fr $(BUILD) $(OUTPUT_D) $(RELEASE)
@make --no-print-directory gateway
@-make --no-print-directory cakerop
@rm -fr $(BUILD) $(OUTPUT).bin $(OUTPUT).elf $(CURDIR)/$(LOADER)/data
@-make --no-print-directory brahma
@[ -d $(RELEASE) ] || mkdir -p $(RELEASE)
@[ -d $(RELEASE)/$(TARGET) ] || mkdir -p $(RELEASE)/$(TARGET)
@cp $(OUTPUT_D)/Launcher.dat $(RELEASE)
@-cp $(OUTPUT).bin $(RELEASE)
@-cp $(OUTPUT).dat $(RELEASE)
@-cp $(OUTPUT).nds $(RELEASE)
@-cp $(OUTPUT).3dsx $(RELEASE)/$(TARGET)
@-cp $(OUTPUT).smdh $(RELEASE)/$(TARGET)
@cp $(CURDIR)/README.md $(RELEASE)
@-7z a $(RELEASE)/$(TARGET)-`date +'%Y%m%d-%H%M%S'`.zip $(RELEASE)/*
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@-make clean --no-print-directory -C CakeHax
@-make clean --no-print-directory -C CakesROP
@-make clean --no-print-directory -C BrahmaLoader
@rm -fr $(BUILD) $(OUTPUT_D) $(RELEASE)
@set -e; for elf in $(ELF); do \
$(MAKE) --no-print-directory -C $$(dirname $$elf) clean; \
done
@rm -rf $(OUTDIR) $(RELDIR) $(FIRM) $(FIRMD) $(VRAM_TAR) $(LANGUAGE_INL) $(TRF_FILES)
unmarked_readme: .FORCE
@$(PY3) utils/unmark.py -f README.md data/README_internal.md
#---------------------------------------------------------------------------------
else
release: clean unmarked_readme
@$(MAKE) --no-print-directory firm
@$(MAKE) --no-print-directory firm NTRBOOT=1
DEPENDS := $(OFILES:.o=.d)
@mkdir -p $(RELDIR)
@mkdir -p $(RELDIR)/ntrboot
@mkdir -p $(RELDIR)/elf
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).bin : $(OUTPUT).elf
$(OUTPUT).elf : $(OFILES)
@cp $(FIRM) $(RELDIR)
@cp $(OUTDIR)/$(FLAVOR)_ntr.firm $(RELDIR)/ntrboot/
@cp $(OUTDIR)/$(FLAVOR)_ntr.firm.sha $(RELDIR)/ntrboot/
@cp $(OUTDIR)/$(FLAVOR)_ntr_dev.firm $(RELDIR)/ntrboot/
@cp $(OUTDIR)/$(FLAVOR)_ntr_dev.firm.sha $(RELDIR)/ntrboot/
@cp $(OUTDIR)/$(FLAVOR).firm $(RELDIR)/
@cp $(OUTDIR)/$(FLAVOR).firm.sha $(RELDIR)/
@cp $(OUTDIR)/$(FLAVOR)_dev.firm $(RELDIR)/
@cp $(OUTDIR)/$(FLAVOR)_dev.firm.sha $(RELDIR)/
@cp $(ELF) $(RELDIR)/elf
@cp $(CURDIR)/README.md $(RELDIR)
@cp $(CURDIR)/resources/lua-doc.md $(RELDIR)/lua-doc.md
@cp -R $(CURDIR)/resources/gm9 $(RELDIR)/gm9
@cp -R $(CURDIR)/resources/sample $(RELDIR)/sample
@-7za a $(RELDIR)/$(FLAVOR)-$(VERSION)-$(DBUILTS).zip ./$(RELDIR)/*
#---------------------------------------------------------------------------------
%.bin: %.elf
@$(OBJCOPY) --set-section-flags .bss=alloc,load,contents -O binary $< $@
@echo built ... $(notdir $@)
$(VRAM_TAR): $(SPLASH) $(OVERRIDE_FONT) $(VRAM_DATA) $(VRAM_SCRIPTS)
@mkdir -p "$(@D)"
@echo "Creating $@"
@$(PY3) utils/add2tar.py $(VRAM_FLAGS) $(VRAM_TAR) $(shell ls -d -1 $^)
$(LANGUAGE_INL): $(SOURCE_JSON)
@echo "Creating $@"
@$(PY3) utils/transcp.py $< $@
-include $(DEPENDS)
$(TRF_FOLDER)/%.trf: $(JSON_FOLDER)/%.json
@$(PY3) utils/transriff.py $< $@
%.elf: .FORCE
@echo "Building $@"
@$(MAKE) --no-print-directory -C $(@D) $(@F)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
# Indicate a few explicit dependencies:
# The ARM9 data section depends on the VRAM drive
arm9/arm9_data.elf: $(VRAM_TAR) $(LANGUAGE_INL)
# And the code section depends on the data section being built already
arm9/arm9_code.elf: arm9/arm9_data.elf
firm: $(ELF) $(TRF_FILES)
@mkdir -p $(call dirname,"$(FIRM)") $(call dirname,"$(FIRMD)")
@echo "[FLAVOR] $(FLAVOR)"
@echo "[VERSION] $(VERSION)"
@echo "[BUILD] $(DBUILTL)"
@echo "[FIRM] $(FIRM)"
@$(PY3) -m firmtool build $(FIRM) $(FTFLAGS) -g -D $(ELF) -C NDMA NDMA XDMA
@echo "[FIRM] $(FIRMD)"
@$(PY3) -m firmtool build $(FIRMD) $(FTDFLAGS) -g -D $(ELF) -C NDMA NDMA XDMA
vram0: $(VRAM_TAR) .FORCE # legacy target name
.FORCE:

38
Makefile.build Executable file
View File

@ -0,0 +1,38 @@
LIBS ?=
OBJECTS := $(patsubst $(SOURCE)/%.s, $(BUILD)/%.o, \
$(patsubst $(SOURCE)/%.c, $(BUILD)/%.o, \
$(call rwildcard, $(SOURCE), *.s *.c)))
OBJECTS_COMMON := $(patsubst $(COMMON_DIR)/%.c, $(BUILD)/%.cmn.o, \
$(call rwildcard, $(COMMON_DIR), *.c))
.PHONY: all
all: $(TARGET).elf
.PHONY: clean
clean:
@rm -rf $(BUILD) $(TARGET).elf $(TARGET).dis $(TARGET).map
$(TARGET).elf: $(OBJECTS) $(OBJECTS_COMMON)
@mkdir -p "$(@D)"
@$(CC) $(LDFLAGS) $^ -o $@ $(LIBS)
@$(OBJDUMP) -S -h $@ > $@.dis
$(BUILD)/%.cmn.o: $(COMMON_DIR)/%.c
@mkdir -p "$(@D)"
@echo "[$(PROCESSOR)] $<"
@$(CC) -c $(CFLAGS) -o $@ $<
$(BUILD)/%.o: $(SOURCE)/%.c
@mkdir -p "$(@D)"
@echo "[$(PROCESSOR)] $<"
@$(CC) -c $(CFLAGS) -o $@ $<
$(BUILD)/%.o: $(SOURCE)/%.s
@mkdir -p "$(@D)"
@echo "[$(PROCESSOR)] $<"
@$(CC) -c $(ASFLAGS) -o $@ $<
include $(call rwildcard, $(BUILD), *.d)

93
Makefile.common Normal file
View File

@ -0,0 +1,93 @@
export OBJDUMP := arm-none-eabi-objdump
dirname = $(shell dirname $(1))
rwildcard = $(foreach d, $(wildcard $1*), \
$(filter $(subst *, %, $2), $d) \
$(call rwildcard, $d/, $2))
FLAVOR ?= GodMode9
SPLASH = resources/$(FLAVOR)_splash.png
ifeq ($(FLAVOR),SafeMode9)
CFLAGS += -DSAFEMODE
else ifeq ($(FLAVOR),GodMode64)
OVERRIDE_FONT := resources/fonts/font_c64_8x8.pbm
CFLAGS += -DDEFAULT_FONT=\"font_c64_8x8.pbm\"
CFLAGS += -DCOLOR_STD_FONT="RGB(0x7B, 0x71, 0xD5)"
CFLAGS += -DCOLOR_STD_BG="RGB(0x41, 0x30, 0xA4)"
else ifeq ($(FLAVOR),BrickedMode9)
OVERRIDE_FONT := resources/fonts/font_nbraille_4x6.pbm
CFLAGS += -DDEFAULT_FONT=\"font_nbraille_4x6.pbm\"
CFLAGS += -DCOLOR_STD_FONT="RGB(0xFF, 0xFF, 0x00)"
CFLAGS += -DCOLOR_STD_BG="RGB(0x00, 0x00, 0xFF)"
else ifeq ($(FLAVOR),ZuishMode9)
OVERRIDE_FONT := resources/fonts/font_zuish_8x8.pbm
CFLAGS += -DDEFAULT_FONT=\"font_zuish_8x8.pbm\"
endif
ifeq ($(LARGEDLC),1)
CFLAGS += -DTITLE_MAX_CONTENTS=1536
else
CFLAGS += -DTITLE_MAX_CONTENTS=1024
endif
ifeq ($(SALTMODE),1)
CFLAGS += -DSALTMODE
endif
ifeq ($(SWITCH_SCREENS),1)
CFLAGS += -DSWITCH_SCREENS
endif
ifeq ($(SCRIPT_RUNNER),1)
CFLAGS += -DSCRIPT_RUNNER
endif
ifeq ($(AUTO_UNLOCK),1)
CFLAGS += -DAUTO_UNLOCK
endif
ifeq ($(TIMER_UNLOCK),1)
CFLAGS += -DTIMER_UNLOCK
endif
ifeq ($(HIDE_HIDDEN),1)
CFLAGS += -DHIDE_HIDDEN
endif
ifeq ($(SHOW_FREE),1)
CFLAGS += -DSHOW_FREE
endif
ifdef FIXED_BRIGHTNESS
CFLAGS += -DFIXED_BRIGHTNESS=$(FIXED_BRIGHTNESS)
endif
ifdef SD_TIMEOUT
CFLAGS += -DSD_TIMEOUT=$(SD_TIMEOUT)
endif
ifeq ($(NO_LUA),1)
CFLAGS += -DNO_LUA
endif
ifdef N_PANES
CFLAGS += -DN_PANES=$(N_PANES)
endif
ifeq ($(MONITOR_HEAP),1)
CFLAGS += -DMONITOR_HEAP
endif
ifdef NTRBOOT
FTFLAGS = -S spi-retail
FTDFLAGS = -S spi-dev
FIRM = $(OUTDIR)/$(FLAVOR)_ntr.firm
FIRMD = $(OUTDIR)/$(FLAVOR)_ntr_dev.firm
else
FTFLAGS = -S nand-retail
FTDFLAGS = -S nand-dev
FIRM = $(OUTDIR)/$(FLAVOR).firm
FIRMD = $(OUTDIR)/$(FLAVOR)_dev.firm
endif

224
README.md
View File

@ -1,28 +1,214 @@
# :godmode: Godmode9 :godmode:
_A full access file browser for the 3DS console_
# ![GodMode9](https://github.com/d0k3/GodMode9/blob/master/resources/logo.png)
_A full access file browser for the 3DS console_ :godmode:
GodMode9 is a full access file browser for the Nintendo 3DS console, giving you access to your SD card, to the FAT partitions inside your SysNAND and EmuNAND and to basically anything else. Among other functionality (see below), you can copy, delete, rename files and create folders.
GodMode9 is a full access file browser for the Nintendo 3DS console, giving you access to your SD card and to the FAT partitons inside your SysNAND and EmuNAND. As of now, you can copy, delete, rename files and create folders. A write permission system prevents you from doing dangerous stuff without noticing.
## Warning
__This is powerful stuff__, so you should not use it if you don't know exactly what you're doing. This tool won't protect you from yourself. On SysNAND, any writing change to your CTRNAND can result in a full brick. Writing changes to your TWLN partition can lead to a partial brick, leading to your console not being able to run DSiWare / DS cartridges anymore. Always keep backups, just to be safe.
__This is powerful stuff__, it provides you with the means to do basically any thinkable modification to any system data available on the 3DS console. However, precautions are taken so you don't accidentally damage the data of your console. The write permissions system protects you by providing warnings and forces you to enter an unlock sequence for enabling write permissions. It is not possible to overwrite or modify any important stuff without such unlock sequences and it is not possible to accidentally unlock something.
## How to run this / entry points
__As always, be smart, keep backups, just to be safe__.
GodMode9 can be built to run from a number of entry points, descriptions are below. Note that you need to be on or below 3DS firmware version v9.2 or have ARM9loaderhax installed for any of these to work. Note that for ARM9loaderhax you also need to have a file called `slot0x05keyY.bin` in the root of your SD card for full compatibility.
* __Gateway Browser Exploit__: Copy `Launcher.dat` to your SD card root and run this via http://go.gateway-3ds.com/ from your 3DS browser. Build this with `make gateway`.
* __A9LH, Brahma & Bootstrap__: Copy `GodMode9.bin` to somewhere on your SD card and run it via either [Brahma](https://github.com/delebile/Brahma2) or [Bootstrap](https://github.com/shinyquagsire23/bootstrap). Brahma derivatives / loaders such as [BrahmaLoader](https://gbatemp.net/threads/release-easily-load-payloads-in-hb-launcher-via-brahma-2-mod.402857/), [BootCTR](https://gbatemp.net/threads/re-release-bootctr-a-simple-boot-manager-for-3ds.401630/) and [CTR Boot Manager](https://gbatemp.net/threads/ctrbootmanager-3ds-boot-manager-loader-homemenuhax.398383/) will also work with this. Build this with `make bootstrap`.
* __Homebrew Launcher__: Copy `GodMode9.3dsx` & `GodMode9.smdh` into `/3DS/GodMode9` on your SD card. Run this via [Smealums Homebrew Launcher](http://smealum.github.io/3ds/), [Mashers Grid Launcher](https://gbatemp.net/threads/release-homebrew-launcher-with-grid-layout.397527/) or any other compatible software. Build this with `make brahma`.
* __CakeHax Browser__: Copy `GodMode9.dat` to the root of your SD card. You can then run it via http://dukesrg.github.io/?GodMode9.dat from your 3DS browser. Build this via `make cakehax`.
* __CakeHax MSET__: Copy `GodMode9.dat` to the root of your SD card and `GodMode9.nds` to anywhere on the SD card. You can then run it either via MSET and GodMode9.nds. Build this via `make cakerop`.
If you are a developer and you are building this, you may also just run `make release` to build all files at once. If you are a user, all files are already included in the release archive.
## Quick start guide
The recommended bootloader for use with GodMode9 is [fastboot3DS](https://github.com/derrekr/fastboot3DS). There are [known issues for some users](https://github.com/d0k3/GodMode9/issues/466) when using the standard setup based on [boot9strap](https://github.com/SciresM/boot9strap) and [Luma3DS](https://github.com/AuroraWright/Luma3DS). If you insist on using that setup follow the instructions found in a [certain guide](https://3ds.hacks.guide). Here's how to set up GodMode9 (and fastboot3DS) up quickly:
* Download [OpenFirmInstaller](https://github.com/d0k3/OpenFirmInstaller/releases/tag/v0.0.9) and follow the quick setup instructions found there.
* Copy the `gm9` folder from the release archive to your SD card. Then, get good versions of `seeddb.bin` and `encTitleKeys.bin` from somewhere (don't ask me!) and put these two files into `sd:/gm9/support` (optional but recommended for full functionality).
* It is also recommended you setup the RTC clock if you're running GodMode9 for the first time. Find the option via HOME button -> `More...`. Also keep in mind that you should fix your system OS clock afterwards. While you're in the `More...` menu, you may also set screen brightness to a fixed value of your choosing and manually calibrate the touch screen (*not recommended* - try the automatic configuration first).
* Helpful hint #1: Go [here](https://3ds.hacks.guide/godmode9-usage) for step by steps on doing some common tasks in GodMode9. Especially users coming from Decrypt9WIP or Hourglass9 may find this to be helpful.
* Helpful hint #2: __Never unlock the red write permission level unless you know exactly what you're doing__. You will notice that prompt when it comes up, it features a completely red screen. It is recommended you stay on the yellow permission level or below at all times to be completely safe. Also read more on the write permissions system below.
You may now run GodMode9 via holding the X Button (or any other button you chose) at startup. See below for a list of stuff you can do with it.
## Buttons in GodMode9
GodMode9 is designed to be intuitive, buttons leading to the results you'd expect. However, some stuff may not be obvious at first glance. So, here's a quick, incomplete rundown of what each button / button combo does.
* __\<A> button__: The \<A> button is the 'confirm' / 'choose' button. It confirms prompts and selects entries in menus. In the main file view, it pulls up a submenu for files and opens directories (use \<R+A> on directories for a submenu, also including the invaluable title search). In the hexviewer, \<A> switches into edit mode.
* __\<B> button__: The \<B> button is the 'cancel' / 'return' button. Use it to leave menus without action, hold it on file operations to cancel said file operations.
* __\<X> button__: In the main file view, the \<X> button deletes (marked) files. With \<R+X> files are renamed.
* __\<Y> button__: In the main file view, the \<Y> button copies and pastes files. With \<R+Y> you can create folders and dummy files.
* __\<L> button__: The \<L> button is the 'mark' button. Use it with \<LEFT> / \<RIGHT> to mark / unmark all files in a folder, hold it and use \<UP> / \<DOWN> to select multiple files.
* __\<R> button__: The \<R> button is the 'switch' button. It switches buttons to their secondary function. Notable exceptions are \<R+L> for a screenshot (works almost anywhere), \<R+LEFT> / \<R+RIGHT> to switch panes and \<R+DOWN> to reload the file listing.
* __\<START> button__: Use the \<START> button to reboot from GodMode9. Use \<R+START> to poweroff your 3DS.
* __\<SELECT> button__: The \<SELECT> button clears or restores the clipboard (depending on if it's empty or not).
* __\<HOME> button__: The \<HOME> button enters the HOME menu, including the scripts / payloads submenus, options for formatting the SD, setting the RTC, and more. The \<POWER> button is an alternative way of entering the HOME menu.
* __\<R+UP> combo__: This little known keycombo, when held at startup, pauses the GodMode9 boot so that you can stare at the splash screen for a little longer.
* __\<R+LEFT> combo__: If you have installed GodMode9 as your bootloader, this keycombo enters the bootmenu. Hold on startup! If you built GodMode9 as SALTMODE and have it as a bootloader, the keycombo is simply the \<START> button.
## How to build this / developer info
Build `GodMode9.firm` via `make firm`. This requires [firmtool](https://github.com/TuxSH/firmtool), [Python 3.5+](https://www.python.org/downloads/) and [devkitARM](https://sourceforge.net/projects/devkitpro/) installed).
You may run `make release` to get a nice, release-ready package of all required files. To build __SafeMode9__ (a bricksafe variant of GodMode9, with limited write permissions) instead of GodMode9, compile with `make FLAVOR=SafeMode9`. To switch screens, compile with `make SWITCH_SCREENS=1`. For additional customization, you may choose the internal font by replacing `font_default.frf` inside the `data` directory. You may also hardcode the brightness via `make FIXED_BRIGHTNESS=x`, whereas `x` is a value between 0...15.
Further customization is possible by hardcoding `aeskeydb.bin` (just put the file into the `data` folder when compiling). All files put into the `data` folder will turn up in the `V:` drive, but keep in mind there's a hard 223.5KiB limit for all files inside, including overhead. A standalone script runner is compiled by providing `autorun.lua` or `autorun.gm9` (again, in the `data` folder) and building with `make SCRIPT_RUNNER=1`. There's more possibility for customization, read the Makefiles to learn more.
To build a .firm signed with SPI boot keys (for ntrboot and the like), run `make NTRBOOT=1`. You may need to rename the output files if the ntrboot installer you use uses hardcoded filenames. Some features such as boot9 / boot11 access are not currently available from the ntrboot environment.
## Bootloader mode
Same as [boot9strap](https://github.com/SciresM/boot9strap) or [fastboot3ds](https://github.com/derrekr/fastboot3DS), GodMode9 can be installed to the system FIRM partition ('FIRM0'). When executed from a FIRM partition, GodMode9 will default to bootloader mode and try to boot, in order, `FIRM from FCRAM` (see [A9NC](https://github.com/d0k3/A9NC/releases)), `0:/bootonce.firm` (will be deleted on a successful boot), `0:/boot.firm`, `1:/boot.firm`. In bootloader mode, hold R+LEFT on boot to enter the boot menu. *Installing GodMode9 to a FIRM partition is only recommended for developers and will overwrite [boot9strap](https://github.com/SciresM/boot9strap) or any other bootloader you have installed in there*.
## Write permissions system
GodMode9 provides a write permissions system, which will protect you from accidentally damaging your system, losing data and/or modifying important system data. To unlock a write permission, an unlock sequence must be entered. This is not possible by accident. The write permission system is based on colors and the top bar on the top screen will change color according to the current write permission level. No permission above the yellow level can be unlocked on SafeMode9.
* __Green:__ Modification to system files is not possible on this permission level. You can't edit or delete savegames and installed data. However, keep in mind that any non-system related or custom stuff on your SD card is not protected.
* __Yellow:__ You can modify system files on this permission level. Data that is unique to your console and cannot be gotten from anywhere else is still not modifiable. Any damages you introduce can be fixed in software, but loss of savegames and installed data is possible if you are not careful. __A NAND backup is highly recommended starting at this level.__
* __Orange:__ This is similar to the yellow permission level, but, in addition, allows edits to console unique data. Any damages you introduce are still fixable in software, but if you play around with this, __having a NAND backup is an absolute requirement__.
* __Red:__ The highest regular permission level. There are no limits to system file edits, and if you are not careful enough, you can brick your console and/or remove your A9LH/B9S installation. Bricks on this level may only be fixable in hardware. __If you don't have a NAND backup at this point, you seem to have a deathwish for your console__.
* __Blue:__ This permission level is reserved for edits to system memory. While, most likely, nothing bad at all will happen, consequences of edits can be unforeseen. There is even a (albeit very small) chance of bricking your console, maybe even permanently. __Tread with caution on this level__.
## Support files
For certain functionality, GodMode9 may need 'support files'. Support files should be placed into either `0:/gm9/support` or `1:/gm9/support`. Support files contain additional information that is required in decryption operations. A list of support files, and what they do, is found below. Please don't ask for support files - find them yourself.
* __`aeskeydb.bin`__: This should contain 0x25keyX, 0x18keyX and 0x1BkeyX to enable decryption of 7x / Secure3 / Secure4 encrypted NCCH files, 0x11key95 / 0x11key96 for FIRM decrypt support and 0x11keyOTP / 0x11keyIVOTP for 'secret' sector 0x96 crypto support. Entrypoints other than [boot9strap](https://github.com/SciresM/boot9strap) or [fastboot3ds](https://github.com/derrekr/fastboot3DS) may require a aeskeydb.bin file. This is now included in standard releases of GM9. No need to hunt down the file!
* __`seeddb.bin`__: This file is optional and required to decrypt and mount seed-encrypted NCCHs and CIAs (if the seed in question is not installed to your NAND). Note that your seeddb.bin must also contain the seed for the specific game you need to decrypt.
* __`encTitleKeys.bin`__ / __`decTitleKeys.bin`__: These files are optional and provide titlekeys, which are required to decrypt and install contents downloaded from CDN (for DSi and 3DS content).
### Fonts and translations
GodMode9 also supports custom fonts and translations as support files. These both use custom formats, fonts use FRF (Font RIFF) files which can be created using the `fontriff.py` Python script in the 'utils' folder. Translations use TRF (Translation RIFF) files from the `transriff.py` script. Examples of the inputs to these scripts can be found in the 'fonts' and 'languages' folders of the 'resources' folder respectively.
TRF files can be placed in `0:/gm9/languages` to show in the language menu accessible from the HOME menu and shown on first load. Official translations are provided from the community via the [GodMode9 Crowdin](https://crowdin.com/project/GodMode9). Languages can use a special font by having an FRF with the same name, for example `en.trf` and `en.frf`.
## Drives in GodMode9
GodMode9 provides access to system data via drives, a listing of what each drive contains and additional info follows below. Some of these drives are removable (such as drive `7:`), some will only turn up if they are available (drive `8:` and everything associated with EmuNAND, f.e.). Information on the 3DS console file system is also found on [3Dbrew.org](https://3dbrew.org/wiki/Flash_Filesystem).
* __`0: SDCARD`__: The SD card currently inserted into the SD card slot. The `0:/Nintendo 3DS` folder contains software installs and extdata and is specially protected via the write permission system. The SD card can be unmounted from the root directory via the R+B buttons, otherwise the SD card is always available.
* __`1: SYSNAND CTRNAND`__: The CTRNAND partition on SysNAND. This contains your 3DS console's operating system and system software installs. Data in here is protected by the write permissions system.
* __`2: SYSNAND TWLN`__: The TWLN partition on SysNAND. This contains your 3DS console's TWL mode operating system and system software installs. Data in here is protected by the write permissions system.
* __`3: SYSNAND TWLP`__: The TWLP partition on SysNAND. This contains photos taken while in TWL mode.
* __`A: SYSNAND SD`__: This drive is used for special access to data on your SD card. It actually links to a subfolder inside `0:/Nintendo 3DS` and contains software and extdata installed to SD from SysNAND. Crypto in this folder is handled only when accessed via the `A:` drive (not from `0:`). This is protected by the write permissions system.
* __`S: SYSNAND VIRTUAL`__: This drive provides access to all partitions of the SysNAND, some of them critical for base system functionality. This is protected by the write permissions system, but, when unlocked, modifications can brick the system.
* __`4: EMUNAND CTRNAND`__: Same as `1:`, but handles the CTRNAND on EmuNAND. For multi EmuNAND setups, the currently active EmuNAND partition can be switched via the HOME menu.
* __`5: EMUNAND TWLN`__: Same as `2`, but handles TWLN on EmuNAND. No write protection here, cause this partition is never used on EmuNAND.
* __`6: EMUNAND TWLP`__: Same as `3`, but handles TWLP on EmuNAND.
* __`B: EMUNAND SD`__: Same as `A:`, but handles the `0:/Nintendo 3DS` subfolder associated with EmuNAND. In case of linked NANDs, this is identical with `A:`. This is also protected by the write permissions system.
* __`E: EMUNAND VIRTUAL`__: Same as `S:`, but handles system partitions on EmuNAND. No bricking risk here as EmuNAND is never critical to system functionality.
* __`7: FAT IMAGE / IMGNAND CTRNAND`__: This provides access to mounted FAT images. When a NAND image is mounted, it provides access to the mounted NAND image's CTRNAND.
* __`8: BONUS DRIVE / IMGNAND TWLN`__: This provides access to the bonus drive on SysNAND. The bonus drive can be setup via the HOME menu on 3DS consoles that provide the space for it. When a NAND image is mounted, this provides access to the mounted NAND image's TWLN.
* __`9: RAM DRIVE / IMGNAND TWLP`__: This provides access to the RAM drive. All data stored inside the RAM drive is temporary and will be wiped after a reboot. When a NAND image is mounted, this provides access to the mounted NAND image's TWLP.
* __`I: IMGNAND VIRTUAL`__: When a NAND image is mounted, this provides access to the partitions inside the NAND image.
* __`C: GAMECART`__: This is read-only and provides access to the game cartridge currently inserted into the cart slot. This can be used for dumps of CTR and TWL mode cartridges. Flash cards are supported only to a limited extent.
* __`G: GAME IMAGE`__: CIA/NCSD/NCCH/EXEFS/ROMFS/FIRM images can be accessed via this drive when mounted. This is read-only.
* __`K: AESKEYDB IMAGE`__: An `aeskeydb.bin` image can be mounted and accessed via this drive. The drive shows all keys inside the aeskeydb.bin. This is read-only.
* __`T: TICKET.DB IMAGE / BDRI IMAGE`__: Ticket database files can be mounted and accessed via this drive. This provides easy and quick access to all tickets inside the `ticket.db`. This drive also provides access to other BDRI images, such as the Title database (`title.db`).
* __`M: MEMORY VIRTUAL`__: This provides access to various memory regions. This is protected by a special write permission, and caution is advised when doing modifications inside this drive. This drive also gives access to `boot9.bin`, `boot11.bin` (boot9strap only) and `otp.mem` (sighaxed systems only).
* __`V: VRAM VIRTUAL`__: This drive resides in part of ARM9 internal memory and contains files essential to GodMode9. The font (in FRF format), the splash logo (in PNG format) and the readme file are found there, as well as any file that is provided inside the `data` folder at build time. This is read-only.
* __`Y: TITLE MANAGER`__: The title manager is accessed via the HOME menu and provides easy access to all installed titles.
* __`Z: LAST SEARCH`__: After a search operation, search results are found inside this drive. The drive can be accessed at a later point to return to the former search results.
## Digital preservation
GodMode9 is one of the most important tools for digital preservation of 3DS content data. Here's some stuff you should know:
* __Dumping game cartridges (size < 4GiB)__: Game cartridges turn up inside the `C:` drive (see above). For most carts all you need to do is copy the `.3DS` game image to some place of your choice. Game images dumped by GodMode9 contain no identifying info such as private headers or savegames. Private headers can be dumped in a separate image.
* __Dumping game cartridges (size = 4GiB)__: Everything written above applies here as well. However, the FAT32 file system (which is what the 3DS uses) is limited to _4GiB - 1byte_. Take note that the `.3DS` game image, as provided by GodMode9 actually misses the last byte in these cases. That byte is 0xFF and unused in all known cases. It is not required for playing the image. If you need to check, we also provide split files (`.000`, `.001)`, which contain all the data. If you need a valid checksum for the `.3DS` game image, append a 0xFF byte before checking.
* __Building CIAs (all types)__: You may convert compatible file types (game images, installed content, CDN content) to the CIA installable format using the A button menu. To get a list of installed content, press HOME, select `Title manager` and choose a drive. Take note that `standard` built CIAs are decrypted by default (decryption allows better compression by ZIP and 7Z). If you should need an encrypted CIA for some reason, apply the encryption to the CIA afterwards.
* __Building CIAs (legit type)__: Installed content can be built as `legit` or `standard` CIA. Legit CIAs preserve more of the original data and are thus recommended for preservation purposes. When building legit CIAs, GodMode9 keeps the original crypto and tries to find a genuine, signature-valid ticket. If it doesn't find one on your system, it will use a generic ticket instead. If it only finds a personalized one, it still offers to use a generic ticket. It is not recommended to use personalized tickets - only choose this if you know what you're doing.
* __Checking CIAs__: You may also check your CIA files with the builtin `CIA checker tool`. Legit CIAs with generic tickets are identified as `Universal Pirate Legit`, which is the recommended preservation format where `Universal Legit` is not available. Note: apart from system titles, `Universal Legit` is only available for a handful of preinstalled games from special edition 3DS consoles.
## What you can do with GodMode9
With the possibilites GodMode9 provides, not everything may be obvious at first glance. In short, __GodMode9 includes improved versions of basically everything that Decrypt9 has, and more__. Any kind of dumps and injections are handled via standard copy operations and more specific operations are found inside the A button menu. The A button menu also works for batch operations when multiple files are selected. For your convenience a (incomplete!) list of what GodMode9 can do follows below.
### Basic functionality
* __Manage files on all your data storages__: You wouldn't have expected this, right? Included are all standard file operations such as copy, delete, rename files and create folders. Use the L button to mark multiple files and apply file operations to multiple files at once.
* __Make screenshots__: Press R+L anywhere. Screenshots are stored in PNG format.
* __Use multiple panes__: Press R+left|right. This enables you to stay in one location in the first pane and open another in the second pane.
* __Search drives and folders__: Just press R+A on the drive / folder you want to search.
* __Compare and verify files__: Press the A button on the first file, select `Calculate SHA-256`. Do the same for the second file. If the two files are identical, you will get a message about them being identical. On the SDCARD drive (`0:`) you can also write an SHA file, so you can check for any modifications at a later point.
* __Hexview and hexedit any file__: Press the A button on a file and select `Show in Hexeditor`. A button again enables edit mode, hold the A button and press arrow buttons to edit bytes. You will get an additional confirmation prompt to take over changes. Take note that for certain files, write permissions can't be enabled.
* __View text files in a text viewer__: Press the A button on a file and select `Show in Textviewer` (only shows up for actual text files). You can enable wordwrapped mode via R+Y, and navigate around the file via R+X and the dpad.
* __Chainload FIRM payloads__: Press the A button on a FIRM file, select `FIRM options` -> `Boot FIRM`. Keep in mind you should not run FIRMs from dubious sources and that the write permissions system is no longer in place after booting a payload.
* __Chainload FIRM payloads from a neat menu__: The `payloads` menu is found inside the HOME button menu. It provides any FIRM found in `0:/gm9/payloads` for quick chainloading.
* __Inject a file to another file__: Put exactly one file (the file to be injected from) into the clipboard (via the Y button). Press A on the file to be injected to. There will be an option to inject the first file into it.
### Scripting functionality
* __Run .lua scripts from anywhere on your SD card__: You can run Lua scripts via the A button menu. For an overview of usable commands have a look into the documentation and sample scripts included in the release archive. *Don't run scripts from untrusted sources.*
* __Run Lua scripts via a neat menu__: Press the HOME button, select `More...` -> `Lua scripts...`. Any script you put into `0:/gm9/luascripts` (subdirs included) will be found here. Scripts ran via this method won't have the confirmation at the beginning either.
* __Run legacy .gm9 scripts__: The old format of .gm9 scripts is still available, but is deprecated and will see no further development.
### SD card handling
* __Format your SD card / setup an EmuNAND__: Press the HOME button, select `More...` -> `SD format menu`. This also allows to setup a RedNAND (single/multi) or GW type EmuNAND on your SD card. You will get a warning prompt and an unlock sequence before any operation starts.
* __Handle multiple EmuNANDs__: Press the HOME button, select `More...` -> `Switch EmuNAND` to switch between EmuNANDs / RedNANDs. (Only available on multi EmuNAND / RedNAND systems.)
* __Run it without an SD card / unmount the SD card__: If no SD card is found, you will be offered to run without the SD card. You can also unmount and remount your SD card from the file system root at any point.
* __Direct access to SD installed contents__: Just take a look inside the `A:`/`B:` drives. On-the-fly-crypto is taken care for, you can access this the same as any other content.
* __Set (and use) the RTC clock__: For correct modification / creation dates in your file system, you need to setup the RTC clock first. Press the HOME Button and select `More...` to find the option. Keep in mind that modifying the RTC clock means you should also fix system OS time afterwards.
### Game file handling
* __List titles installed on your system__: Press HOME and select `Title manager`. This will also work via R+A for `CTRNAND` and `A:`/`B:` drives. This will list all titles installed in the selected location.
* __Install titles to your system__: Just press A on any file you want installed and select `Install game image` from the submenu. Works with NCCH / NCSD / CIA / DSiWare SRLs / 3DS CDN TMDs / DSi CDN TMDs / NUS TMDs.
* __(Batch) Uninstall titles from your system__: Most easily done via the HOME menu `Title manager`. Just select one or more titles and find the option inside the `Manage title...` submenu.
* __Build CIAs from NCCH / NCSD (.3DS) / SRL / TMD__: Press A on the file you want converted and the option will be shown. Installed contents are found most easily via the HOME menu `Title manager`. Where applicable, you will also be able to generate legit CIAs. Note: this works also from a file search and title listing.
* __Dump CXIs / NDS from TMD (installed contents)__: This works the same as building CIAs, but dumps decrypted CXIs or NDS rom dumps instead. Note: this works also from a file search and title listing.
* __Decrypt, encrypt and verify NCCH / NCSD / CIA / BOSS / FIRM images__: Options are found inside the A button menu. You will be able to decrypt/encrypt to the standard output directory or (where applicable) in place.
* __Decrypt content downloaded from CDN / NUS__: Press A on the file you want decrypted. For this to work, you need at least a TMD file (`encTitlekeys.bin` / `decTitlekeys.bin` also required, see _Support files_ below) or a CETK file. Either keep the names provided by CDN / NUS, or rename the downloaded content to `(anything).nus` or `(anything).cdn` and the CETK to `(anything).cetk`.
* __Batch mode for the above operations__: Just select multiple files of the same type via the L button, then press the A button on one of the selected files.
* __Access any file inside NCCH / NCSD / CIA / FIRM / NDS images__: Just mount the file via the A button menu and browse to the file you want. For CDN / NUS content, prior decryption is required for full access.
* __Rename your NCCH / NCSD / CIA / NDS / GBA files to proper names__: Find this feature inside the A button menu. Proper names include title id, game name, product code and region.
* __Trim NCCH / NCSD / NDS / GBA / FIRM / NAND images__: This feature is found inside the A button menu. It allows you to trim excess data from supported file types. *Warning: Excess data may not be empty, bonus drives are stored there for NAND images, NCSD card2 images store savedata there, for FIRMs parts of the A9LH exploit may be stored there*.
* __Dump 3DS / NDS / DSi type retail game cartridges__: Insert the cartridge and take a look inside the `C:` drive. You may also dump private headers from 3DS game cartridges. The `C:` drive also gives you read/write access to the saves on the cartridges. Note: For 4GiB cartridges, the last byte is not included in the .3ds file dump. This is due to restrictrions of the FAT32 file system.
### NAND handling
* __Directly mount and access NAND dumps or standard FAT images__: Just press the A button on these files to get the option. You can only mount NAND dumps from the same console.
* __Restore NAND dumps while keeping your A9LH / sighax installation intact__: Select `Restore SysNAND (safe)` from inside the A button menu for NAND dumps.
* __Restore / dump NAND partitions or even full NANDs__: Just take a look into the `S:` (or `E:`/ `I:`) drive. This is done the same as any other file operation.
* __Transfer CTRNAND images between systems__: Transfer the file located at `S:/ctrnand_full.bin` (or `E:`/ `I:`). On the receiving system, press A, select `CTRNAND Options...`, then `Transfer to NAND`.
* __Embed an essential backup right into a NAND dump__: This is available in the A button menu for NAND dumps. Essential backups contain NAND header, `movable.sed`, `LocalFriendCodeSeed_B`, `SecureInfo_A`, NAND CID and OTP. If your local SysNAND does not contain an embedded backup, you will be asked to do one at startup. To update the essential SysNAND backup at a later point in time, press A on `S:/nand.bin` and select `NAND image options...` -> `Update embedded backup`.
* __Install an AES key database to your NAND__: For `aeskeydb.bin` files the option is found in `aeskeydb.bin options` -> `Install aeskeydb.bin`. Only the recommended key database can be installed (see above). With an installed key database, it is possible to run the GodMode9 bootloader completely from NAND.
* __Install FIRM files to your NAND__: Found inside the A button menu for FIRM files, select `FIRM options` -> `Install FIRM`. __Use this with caution__ - installing an incompatible FIRM file will lead to a __brick__. The FIRMs signature will automagically be replaced with a sighax signature to ensure compatibility.
* __Actually use that extra NAND space__: You can set up a __bonus drive__ via the HOME menu, which will be available via drive letter `8:`. (Only available on systems that have the extra space.)
* __Fix certain problems on your NANDs__: You can fix CMACs for a whole drive (works on `A:`, `B:`, `S:` and `E:`) via an entry in the R+A button menu, or even restore borked NAND headers back to a functional state (inside the A button menu of borked NANDs and available for `S:/nand_hdr.bin`). Recommended only for advanced users!
### System file handling
* __Check and fix CMACs (for any file that has them)__: The option will turn up in the A button menu if it is available for a given file (f.e. system savegames, `ticket.db`, etc...). This can also be done for multiple files at once if they are marked.
* __Mount ticket.db files and dump tickets__: Mount the file via the A button menu. Tickets are sorted into `eshop` (stuff from eshop), `system` (system tickets), `unknown` (typically empty) and `hidden` (hidden tickets, found via a deeper scan) categories. All tickets displayed are legit, fake tickets are ignored
* __Inject any NCCH CXI file into Health & Safety__: The option is found inside the A button menu for any NCCH CXI file. NCCH CXIs are found, f.e. inside of CIAs. Keep in mind there is a (system internal) size restriction on H&S injectable apps.
* __Inject and dump GBA VC saves__: Find the options to do this inside the A button menu for `agbsave.bin` in the `S:` drive. Keep in mind that you need to start the specific GBA game on your console before dumping / injecting the save. _To inject a save it needs to be in the clipboard_.
* __Dump a copy of boot9, boot11 & your OTP__: This works on sighax, via boot9strap only. These files are found inside the `M:` drive and can be copied from there to any other place.
### Support file handling
* __Build `decTitleKeys.bin` / `encTitleKeys.bin` / `seeddb.bin`__: Press the HOME button, select `More...` -> `Build support files`. `decTitleKeys.bin` / `encTitleKeys.bin` can also be created / merged from tickets, `ticket.db` and merged from other `decTitleKeys.bin` / `encTitleKeys.bin` files via the A button menu.
* __Build, mount, decrypt and encrypt `aeskeydb.bin`__: AES key databases can be merged from other `aeskeydb.bin` or build from legacy `slot??Key?.bin` files. Just select one or more files, press A on one of them and then select `Build aeskeydb.bin`. Options for mounting, decrypting and encrypting are also found in the A button menu.
## License
You may use this under the terms of the GNU General Public License GPL v2 or under the terms of any later revisions of the GPL. Refer to the provided `LICENSE.txt` file for further information.
## Contact info
You can chat directly with us via IRC @ #GodMode9 on [libera.chat](https://web.libera.chat/#GodMode9) or [Discord](https://discord.gg/BRcbvtFxX4)!
## Credits
This tool would not have been possible without the help of numerous people. Thanks go to...
* **Archshift**, for providing the bas eproject infrastructure
* **Normmatt**, for sdmmc.c / sdmmc.h
* **Cha(N)**, **Kane49**, and all other FatFS contributors for FatFS
* **b1l1s**, for helping me figure out A9LH compatibility
* **Al3x_10m**, **Supster131** and all other fearless testers
This tool would not have been possible without the help of numerous people. Thanks go to (in no particular order)...
* **Archshift**, for providing the base project infrastructure
* **Normmatt**, for sdmmc.c / sdmmc.h and gamecart code, and for being of great help on countless other occasions
* **Cha(N)**, **Kane49**, and all other FatFS contributors for [FatFS](http://elm-chan.org/fsw/ff/00index_e.html)
* **Wolfvak** for ARM11 code, FIRM binary launcher, exception handlers, PCX code, Makefile and for help on countless other occasions
* **SciresM** for helping me figure out RomFS and for boot9strap
* **SciresM**, **Myria**, **Normmatt**, **TuxSH** and **hedgeberg** for figuring out sighax and giving us access to bootrom
* **ihaveamac** for implementing Lua support, and first developing the simple CIA generation method and for being of great help in porting it
* **DarkRTA** for linker support during the implementation of Lua
* **luigoalma** for fixing Lua to compile without issues
* **Gruetzig** for re-implementing the Lua os module
* **wwylele** and **aspargas2** for documenting and implementing the DISA, DIFF, and BDRI formats
* **dratini0** for savefile management, based on [TWLSaveTool](https://github.com/TuxSH/TWLSaveTool/)
* **Pk11** for unicode support and her ongoing work on GodMode9 translations and translation support
* **b1l1s** for helping me figure out A9LH compatibility
* **Gelex** and **AuroraWright** for helping me figure out various things
* **stuckpixel** for the new 6x10 font and help on various things
* **Al3x_10m** for help with countless hours of testing and useful advice
* **WinterMute** for helping me with his vast knowledge on everything gamecart related
* **profi200** for always useful advice and helpful hints on various things
* **windows-server-2003** for the initial implementation of if-else-goto in .gm9 scripts
* **Kazuma77** for pushing forward scripting, for testing and for always useful advice
* **TurdPooCharger** for being one of the most meticulous software testers around
* **JaySea**, **YodaDaCoda**, **liomajor**, **Supster131**, **imanoob**, **Kasher_CS** and countless others from freenode #Cakey and the GBAtemp forums for testing, feedback and helpful hints
* **Shadowhand** for being awesome and [hosting my nightlies](https://d0k3.secretalgorithm.com/)
* **Plailect** for putting his trust in my tools and recommending this in [The Guide](https://3ds.guide/)
* **SirNapkin1334** for testing, bug reports and for hosting the original GodMode9 Discord server
* **Lilith Valentine** for testing and helpful advice
* **Project Nayuki** for [qrcodegen](https://github.com/nayuki/QR-Code-generator)
* **Amazingmax fonts** for the Amazdoom font
* **TakWolf** for [fusion-pixel-font](https://github.com/TakWolf/fusion-pixel-font) used for Chinese and Korean
* The fine folks on **the official GodMode9 IRC channel and Discord server**
* The fine folks on **freenode #Cakey**
* Everyone I possibly forgot, if you think you deserve to be mentioned, just contact me!
* All **[3dbrew.org](https://www.3dbrew.org/wiki/Main_Page) editors**
* Everyone I possibly forgot, if you think you deserve to be mentioned, just contact us!

17
arm11/Makefile Normal file
View File

@ -0,0 +1,17 @@
PROCESSOR := ARM11
TARGET := $(shell basename "$(CURDIR)")
SOURCE := source
BUILD := build
SUBARCH := -D$(PROCESSOR) -march=armv6k -mtune=mpcore -marm -mfloat-abi=hard -mfpu=vfpv2 -mtp=soft
INCDIRS := source
INCLUDE := $(foreach dir,$(INCDIRS),-I"$(shell pwd)/$(dir)")
ASFLAGS += $(SUBARCH) $(INCLUDE)
CFLAGS += $(SUBARCH) $(INCLUDE) -flto
LDFLAGS += $(SUBARCH) -Wl,--use-blx,-Map,$(TARGET).map -flto
include ../Makefile.common
include ../Makefile.build

57
arm11/link.ld Normal file
View File

@ -0,0 +1,57 @@
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(__boot)
MEMORY
{
AXIWRAM (RWX) : ORIGIN = 0x1FF80000, LENGTH = 96K
HIGHRAM (RWX) : ORIGIN = 0xFFFF0000, LENGTH = 4K
}
SECTIONS
{
.text : ALIGN(4K)
{
__text_pa = LOADADDR(.text);
__text_va = ABSOLUTE(.);
*(.text*)
. = ALIGN(4K);
__text_va_end = .;
} >AXIWRAM
.data : ALIGN(4K)
{
__data_pa = LOADADDR(.data);
__data_va = ABSOLUTE(.);
*(.data*)
. = ALIGN(4K);
__data_va_end = .;
} >AXIWRAM
.rodata : ALIGN(4K)
{
__rodata_pa = LOADADDR(.rodata);
__rodata_va = ABSOLUTE(.);
*(.rodata*)
. = ALIGN(4K);
__rodata_va_end = .;
} >AXIWRAM
.shared (NOLOAD) : ALIGN(4K)
{
__shared_pa = LOADADDR(.shared);
__shared_va = ABSOLUTE(.);
*(.shared*)
. = ALIGN(4K);
__shared_va_end = .;
} >AXIWRAM
.bss (NOLOAD) : ALIGN(4K)
{
__bss_pa = LOADADDR(.bss);
__bss_va = ABSOLUTE(.);
*(.bss*)
. = ALIGN(4K);
__bss_va_end = .;
} >AXIWRAM
}

300
arm11/source/arm/gic.c Normal file
View File

@ -0,0 +1,300 @@
/*
* This file is part of GodMode9
* Copyright (C) 2017-2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <common.h>
#include <arm.h>
#include <stdatomic.h>
#include "arm/gic.h"
#include "system/event.h"
/* Generic Interrupt Controller Registers */
#define REG_GIC(cpu, o, t) REG_ARM_PMR(0x200 + ((cpu) * 0x100) + (o), t)
#define REG_GIC_CONTROL(c) (*REG_GIC(c, 0x00, u32))
#define REG_GIC_PRIOMASK(c) (*REG_GIC(c, 0x04, u32))
#define REG_GIC_POI(c) (*REG_GIC(c, 0x08, u32))
#define REG_GIC_IRQACK(c) (*REG_GIC(c, 0x0C, u32))
#define REG_GIC_IRQEND(c) (*REG_GIC(c, 0x10, u32))
#define REG_GIC_LASTPRIO(c) (*REG_GIC(c, 0x14, u32))
#define REG_GIC_PENDING(c) (*REG_GIC(c, 0x18, u32))
#define GIC_THIS_CPU_ALIAS (-1)
#define GIC_IRQ_SPURIOUS (1023)
/* Interrupt Distributor Registers */
#define REG_DIC(off, type) REG_ARM_PMR(0x1000 + (off), type)
#define REG_DIC_CONTROL (*REG_DIC(0x00, u32))
#define REG_DIC_TYPE (*REG_DIC(0x04, u32))
#define REG_DIC_SETENABLE REG_DIC(0x100, u32) // 32 intcfg per reg
#define REG_DIC_CLRENABLE REG_DIC(0x180, u32)
#define REG_DIC_SETPENDING REG_DIC(0x200, u32)
#define REG_DIC_CLRPENDING REG_DIC(0x280, u32)
#define REG_DIC_PRIORITY REG_DIC(0x400, u8) // 1 intcfg per reg (in upper 4 bits)
#define REG_DIC_TARGETCPU REG_DIC(0x800, u8) // 1 intcfg per reg
#define REG_DIC_CFGREG REG_DIC(0xC00, u32) // 16 intcfg per reg
#define REG_DIC_SOFTINT (*REG_DIC(0xF00, u32))
// used only on reset routines
#define REG_DIC_PRIORITY32 REG_DIC(0x400, u32) // 4 intcfg per reg (in upper 4 bits)
#define REG_DIC_TARGETCPU32 REG_DIC(0x800, u32) // 4 intcfg per reg
#define GIC_PRIO_NEVER32 \
(GIC_PRIO_NEVER | (GIC_PRIO_NEVER << 8) | \
(GIC_PRIO_NEVER << 16) | (GIC_PRIO_NEVER << 24))
#define GIC_PRIO_HIGH32 \
(GIC_PRIO_HIGHEST | (GIC_PRIO_HIGHEST << 8) | \
(GIC_PRIO_HIGHEST << 16) | (GIC_PRIO_HIGHEST << 24))
/* CPU source ID is present in Interrupt Acknowledge register? */
#define IRQN_SRC_MASK (0x7 << 10)
/* Interrupt Handling */
#define LOCAL_IRQS (32)
#define DIC_MAX_IRQ (LOCAL_IRQS + MAX_IRQ)
#define COREMASK_VALID(x) (((x) > 0) && ((x) < BIT(MAX_CPU)))
#define IRQN_IS_VALID(n) ((n) < DIC_MAX_IRQ)
static gicIrqHandler gicIrqHandlers[DIC_MAX_IRQ];
static _Atomic(u32) gicIrqPending[DIC_MAX_IRQ / 32];
static struct {
u8 tgt;
u8 prio;
} gicIrqConfig[DIC_MAX_IRQ];
// gets used whenever a NULL pointer is passed to gicEnableInterrupt
static void gicDummyHandler(u32 irqn) { (void)irqn; return; }
static const struct {
u8 low, high, mode;
} gicDefaultIrqCfg[] = {
{ .low = 0x00, .high = 0x1F, .mode = GIC_RISINGEDGE_NN },
{ .low = 0x20, .high = 0x23, .mode = GIC_LEVELHIGH_1N },
{ .low = 0x24, .high = 0x24, .mode = GIC_RISINGEDGE_1N },
{ .low = 0x25, .high = 0x27, .mode = GIC_LEVELHIGH_1N },
{ .low = 0x28, .high = 0x2D, .mode = GIC_RISINGEDGE_1N },
{ .low = 0x30, .high = 0x3B, .mode = GIC_LEVELHIGH_1N },
{ .low = 0x40, .high = 0x4E, .mode = GIC_RISINGEDGE_1N },
{ .low = 0x4F, .high = 0x4F, .mode = GIC_LEVELHIGH_1N },
{ .low = 0x50, .high = 0x57, .mode = GIC_RISINGEDGE_1N },
{ .low = 0x58, .high = 0x58, .mode = GIC_LEVELHIGH_1N },
{ .low = 0x59, .high = 0x75, .mode = GIC_RISINGEDGE_1N },
{ .low = 0x76, .high = 0x77, .mode = GIC_LEVELHIGH_1N },
{ .low = 0x78, .high = 0x78, .mode = GIC_RISINGEDGE_1N },
{ .low = 0x79, .high = 0x7d, .mode = GIC_LEVELHIGH_1N },
};
static u8 gicGetDefaultIrqCfg(u32 irqn) {
for (unsigned i = 0; i < countof(gicDefaultIrqCfg); i++) {
if ((irqn >= gicDefaultIrqCfg[i].low) && (irqn <= gicDefaultIrqCfg[i].high))
return gicDefaultIrqCfg[i].mode;
}
// TODO: would it be considerably faster to use bsearch?
return GIC_RISINGEDGE_1N;
}
void gicTopHandler(void)
{
while(1) {
u32 irqn, irqsource, index, mask;
/**
If more than one of these CPUs reads the Interrupt Acknowledge Register at the
same time, they can all acknowledge the same interrupt. The interrupt service
routine must ensure that only one of them tries to process the interrupt, with the
others returning after writing the ID to the End of Interrupt Register.
*/
irqsource = REG_GIC_IRQACK(GIC_THIS_CPU_ALIAS);
if (irqsource == GIC_IRQ_SPURIOUS) // no further processing is needed
break;
irqn = irqsource & ~IRQN_SRC_MASK;
index = irqn / 32;
mask = BIT(irqn % 32);
atomic_fetch_or(&gicIrqPending[index], mask);
(gicIrqHandlers[irqn])(irqsource);
// if the id is < 16, the source CPU can be obtained from irqn
// if the handler isn't set, it'll try to branch to 0 and trigger a prefetch abort
REG_GIC_IRQEND(GIC_THIS_CPU_ALIAS) = irqsource;
}
}
void gicGlobalReset(void)
{
u32 dic_type;
unsigned gicn, intn;
dic_type = REG_DIC_TYPE;
// number of local controllers
gicn = ((dic_type >> 5) & 3) + 1;
// number of interrupt lines (up to 224 external + 32 fixed internal per CPU)
intn = ((dic_type & 7) + 1) * 32;
// clamp it down to the amount of CPUs designed to handle
if (gicn > MAX_CPU)
gicn = MAX_CPU;
// clear the interrupt handler and config table
getEventIRQ()->reset();
memset(gicIrqHandlers, 0, sizeof(gicIrqHandlers));
memset(gicIrqConfig, 0, sizeof(gicIrqConfig));
// disable all MP11 GICs
for (unsigned i = 0; i < gicn; i++)
REG_GIC_CONTROL(i) = 0;
// disable the main DIC
REG_DIC_CONTROL = 0;
// clear all external interrupts
for (unsigned i = 1; i < (intn / 32); i++) {
REG_DIC_CLRENABLE[i] = ~0;
REG_DIC_CLRPENDING[i] = ~0;
}
// reset all external priorities to highest by default
// clear target processor regs
for (unsigned i = 4; i < (intn / 4); i++) {
REG_DIC_PRIORITY32[i] = GIC_PRIO_HIGH32;
REG_DIC_TARGETCPU32[i] = 0;
}
// set all interrupts to active level triggered in N-N model
for (unsigned i = 16; i < (intn / 16); i++)
REG_DIC_CFGREG[i] = 0;
// re enable the main DIC
REG_DIC_CONTROL = 1;
for (unsigned i = 0; i < gicn; i++) {
// compare all priority bits
REG_GIC_POI(i) = 3;
// don't mask any interrupt with low priority
REG_GIC_PRIOMASK(i) = 0xF0;
// enable all the MP11 GICs
REG_GIC_CONTROL(i) = 1;
}
}
void gicLocalReset(void)
{
u32 irq_s;
// disable all local interrupts
REG_DIC_CLRENABLE[0] = ~0;
REG_DIC_CLRPENDING[0] = ~0;
for (unsigned i = 0; i < 4; i++) {
REG_DIC_PRIORITY32[i] = GIC_PRIO_HIGH32;
// local IRQs are always unmasked by default
// REG_DIC_TARGETCPU[i] = 0;
// not needed, always read as corresponding MP11 core
}
// ack until it gets a spurious IRQ
do {
irq_s = REG_GIC_PENDING(GIC_THIS_CPU_ALIAS);
REG_GIC_IRQEND(GIC_THIS_CPU_ALIAS) = irq_s;
} while(irq_s != GIC_IRQ_SPURIOUS);
}
static void gicSetIrqCfg(u32 irqn) {
u32 smt, cfg;
smt = irqn & 15;
cfg = REG_DIC_CFGREG[irqn / 16];
cfg &= ~(3 << smt);
cfg |= gicGetDefaultIrqCfg(irqn) << smt;
REG_DIC_CFGREG[irqn / 16] = cfg;
}
void gicSetInterruptConfig(u32 irqn, u32 coremask, u32 prio, gicIrqHandler handler)
{
if (handler == NULL) // maybe add runtime ptr checks here too?
handler = gicDummyHandler;
gicIrqConfig[irqn].tgt = coremask;
gicIrqConfig[irqn].prio = prio;
gicIrqHandlers[irqn] = handler;
}
void gicClearInterruptConfig(u32 irqn)
{
memset(&gicIrqConfig[irqn], 0, sizeof(gicIrqConfig[irqn]));
gicIrqHandlers[irqn] = NULL;
}
void gicEnableInterrupt(u32 irqn)
{
REG_DIC_PRIORITY[irqn] = gicIrqConfig[irqn].prio;
REG_DIC_TARGETCPU[irqn] = gicIrqConfig[irqn].tgt;
gicSetIrqCfg(irqn);
REG_DIC_CLRPENDING[irqn / 32] |= BIT(irqn & 0x1F);
REG_DIC_SETENABLE[irqn / 32] |= BIT(irqn & 0x1F);
}
void gicDisableInterrupt(u32 irqn)
{
REG_DIC_CLRENABLE[irqn / 32] |= BIT(irqn & 0x1F);
REG_DIC_CLRPENDING[irqn / 32] |= BIT(irqn & 0x1F);
}
void gicTriggerSoftInterrupt(u32 softirq)
{
REG_DIC_SOFTINT = softirq;
}
static void irqEvReset(void) {
memset(&gicIrqPending, 0, sizeof(gicIrqPending));
}
static u32 irqEvTest(u32 param, u32 clear) {
u32 index, tstmask, clrmask;
if (param >= DIC_MAX_IRQ)
bkpt;
index = param / 32;
tstmask = BIT(param % 32);
clrmask = clear ? tstmask : 0;
return !!(atomic_fetch_and(&gicIrqPending[index], ~clrmask) & tstmask);
}
static const EventInterface evIRQ = {
.reset = irqEvReset,
.test = irqEvTest
};
const EventInterface *getEventIRQ(void) {
return &evIRQ;
}

112
arm11/source/arm/gic.h Normal file
View File

@ -0,0 +1,112 @@
/*
* This file is part of GodMode9
* Copyright (C) 2017-2020 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <common.h>
#include <arm.h>
typedef void (*gicIrqHandler)(u32 irqn);
enum {
GIC_LEVELHIGH_NN = 0, // no interrupts use level high triggers so far
GIC_LEVELHIGH_1N = 1,
GIC_RISINGEDGE_NN = 2,
GIC_RISINGEDGE_1N = 3
// With the 1-N model, an interrupt that is taken on any CPU clears the Pending
// status on all CPUs.
// With the N-N model, all CPUs receive the interrupt independently. The Pending
// status is cleared only for the CPU that takes it, not for the other CPUs
};
enum {
GIC_PRIO0 = 0x00,
GIC_PRIO1 = 0x10,
GIC_PRIO2 = 0x20,
GIC_PRIO3 = 0x30,
GIC_PRIO4 = 0x40,
GIC_PRIO5 = 0x50,
GIC_PRIO6 = 0x60,
GIC_PRIO7 = 0x70,
GIC_PRIO14 = 0xE0,
GIC_PRIO15 = 0xF0,
};
#define GIC_PRIO_HIGHEST GIC_PRIO0
#define GIC_PRIO_LOWEST GIC_PRIO14
#define GIC_PRIO_NEVER GIC_PRIO15
void gicGlobalReset(void);
void gicLocalReset(void);
/*
Notes from https://static.docs.arm.com/ddi0360/f/DDI0360F_arm11_mpcore_r2p0_trm.pdf
INTERRUPT ENABLE:
Interrupts 0-15 fields are read as one, that is, always enabled, and write to these fields
have no effect.
Notpresent interrupts (depending on the Interrupt Controller Type Register and
interrupt number field) related fields are read as zero and writes to these fields have no
effect.
INTERRUPT PRIORITY:
The first four registers are aliased for each MP11 CPU, that is, the priority set for
ID0-15 and ID29-31 can be different for each MP11 CPU. The priority of IPIs ID0-15
depends on the receiving CPU, not the sending CPU.
INTERRUPT CPU TARGET:
For MP11 CPU n, CPU targets 29, 30 and 31 are read as (1 << n). Writes are ignored.
For IT0-IT28, these fields are read as zero and writes are ignored.
INTERRUPT CONFIGURATION:
For ID0-ID15, bit 1 of the configuration pair is always read as one, that is, rising edge
sensitive.
For ID0-ID15, bit 0 (software model) can be configured and applies to the interrupts
sent from the writing MP11 CPU.
For ID29, and ID30, the configuration pair is always read as b10, that is rising edge
sensitive and N-N software model because these IDs are allocated to timer and
watchdog interrupts that are CPU-specific
*/
#define COREMASK_ALL (BIT(MAX_CPU) - 1)
void gicSetInterruptConfig(u32 irqn, u32 coremask, u32 prio, gicIrqHandler handler);
void gicClearInterruptConfig(u32 irqn);
void gicEnableInterrupt(u32 irqn);
void gicDisableInterrupt(u32 irqn);
enum {
GIC_SOFTIRQ_LIST = 0,
GIC_SOFTIRQ_OTHERS = 1, // all except self
GIC_SOFTIRQ_SELF = 2,
};
#define GIC_SOFTIRQ_SOURCE(n) (((n) >> 10) & 0xF)
#define GIC_SOFTIRQ_ID(n) ((n) & 0x3FF)
#define GIC_SOFTIRQ_FMT(id, filter, coremask) \
((id) | ((coremask) << 16) | ((filter) << 24))
// id & 0xf, coremask & 3, filter & 3
// coremask is only used with filter == GIC_SOFTIRQ_LIST
#define GIC_SOFTIRQ_SRC(x) (((x) >> 10) % MAX_CPU)
void gicTriggerSoftInterrupt(u32 softirq);

279
arm11/source/arm/mmu.c Executable file
View File

@ -0,0 +1,279 @@
/*
* This file is part of GodMode9
* Copyright (C) 2018-2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <types.h>
#include <common.h>
#include <arm.h>
#include "arm/mmu.h"
/* Virtual Memory Mapper */
#define L1_VA_IDX(v) (((v) >> 20) & 0xFFF)
#define L2_VA_IDX(v) (((v) >> 12) & 0xFF)
#define SECT_ADDR_SHIFT (20)
#define COARSE_ADDR_SHIFT (10)
#define PAGE_ADDR_SHIFT (12)
#define LPAGE_ADDR_SHIFT (16)
#define SECT_SIZE (BIT(SECT_ADDR_SHIFT))
#define COARSE_SIZE (BIT(COARSE_ADDR_SHIFT))
#define PAGE_SIZE (BIT(PAGE_ADDR_SHIFT))
#define LPAGE_SIZE (BIT(LPAGE_ADDR_SHIFT))
#define SECT_MASK (~(SECT_SIZE - 1))
#define COARSE_MASK (~(COARSE_SIZE - 1))
#define PAGE_MASK (~(PAGE_SIZE - 1))
#define LPAGE_MASK (~(LPAGE_SIZE - 1))
#define DESCRIPTOR_L1_UNMAPPED (0)
#define DESCRIPTOR_L1_COARSE (1)
#define DESCRIPTOR_L1_SECTION (2)
#define DESCRIPTOR_L1_RESERVED (3)
#define DESCRIPTOR_L2_UNMAPPED (0)
#define DESCRIPTOR_L2_LARGEPAGE (1)
#define DESCRIPTOR_L2_PAGE_EXEC (2)
#define DESCRIPTOR_L2_PAGE_NX (3)
#define DESCRIPTOR_TYPE_MASK (3)
enum {
L1_UNMAPPED,
L1_COARSE,
L1_SECTION,
L1_RESERVED,
L2_UNMAPPED,
L2_LARGEPAGE,
L2_PAGE,
};
typedef struct {
u32 desc[4096];
} __attribute__((aligned(16384))) mmuLevel1Table;
typedef struct {
u32 desc[256];
} __attribute__((aligned(1024))) mmuLevel2Table;
static mmuLevel1Table mmuGlobalTT;
// simple watermark allocator for 2nd level page tables
#define MAX_SECOND_LEVEL (8)
static mmuLevel2Table mmuCoarseTables[MAX_SECOND_LEVEL];
static u32 mmuCoarseAllocated = 0;
static mmuLevel2Table *mmuAllocateLevel2Table(void)
{
return &mmuCoarseTables[mmuCoarseAllocated++];
}
// functions to convert from internal page flag format to ARM
// {TEX, CB} pairs
static const u8 mmuTypeLUT[MMU_MEMORY_TYPES][2] = {
[MMU_STRONG_ORDER] = {0, 0},
[MMU_UNCACHEABLE] = {1, 0},
[MMU_DEV_SHARED] = {0, 1},
[MMU_DEV_NONSHARED] = {2, 0},
[MMU_CACHE_WT] = {0, 2},
[MMU_CACHE_WB] = {1, 3},
[MMU_CACHE_WBA] = {1, 3},
};
static u32 mmuGetTEX(u32 f)
{ return mmuTypeLUT[MMU_FLAGS_TYPE(f)][0]; }
static u32 mmuGetCB(u32 f)
{ return mmuTypeLUT[MMU_FLAGS_TYPE(f)][1]; }
static u32 mmuGetNX(u32 f)
{ return MMU_FLAGS_NOEXEC(f) ? 1 : 0; }
static u32 mmuGetShared(u32 f)
{ return MMU_FLAGS_SHARED(f) ? 1 : 0; }
// access permissions
static const u8 mmuAccessLUT[MMU_ACCESS_TYPES] = {
[MMU_NO_ACCESS] = 0,
[MMU_READ_ONLY] = 0x21,
[MMU_READ_WRITE] = 0x01,
};
static u32 mmuGetAP(u32 f)
{ return mmuAccessLUT[MMU_FLAGS_ACCESS(f)]; }
// other misc helper functions
static unsigned mmuWalkTT(u32 va)
{
mmuLevel2Table *coarsepd;
u32 desc = mmuGlobalTT.desc[L1_VA_IDX(va)];
switch(desc & DESCRIPTOR_TYPE_MASK) {
case DESCRIPTOR_L1_UNMAPPED:
return L1_UNMAPPED;
case DESCRIPTOR_L1_COARSE:
break;
case DESCRIPTOR_L1_SECTION:
return L1_SECTION;
case DESCRIPTOR_L1_RESERVED:
return L1_RESERVED;
}
coarsepd = (mmuLevel2Table*)(desc & COARSE_MASK);
desc = coarsepd->desc[L2_VA_IDX(va)];
switch(desc & DESCRIPTOR_TYPE_MASK) {
default:
case DESCRIPTOR_L2_UNMAPPED:
return L2_UNMAPPED;
case DESCRIPTOR_L2_LARGEPAGE:
return L2_LARGEPAGE;
case DESCRIPTOR_L2_PAGE_NX:
case DESCRIPTOR_L2_PAGE_EXEC:
return L2_PAGE;
}
}
static mmuLevel2Table *mmuCoarseFix(u32 va)
{
u32 type;
mmuLevel2Table *coarsepd;
type = mmuWalkTT(va);
switch(type) {
case L1_UNMAPPED:
coarsepd = mmuAllocateLevel2Table();
mmuGlobalTT.desc[L1_VA_IDX(va)] = (u32)coarsepd | DESCRIPTOR_L1_COARSE;
break;
case L2_UNMAPPED:
coarsepd = (mmuLevel2Table*)(mmuGlobalTT.desc[L1_VA_IDX(va)] & COARSE_MASK);
break;
default:
coarsepd = NULL;
break;
}
return coarsepd;
}
/* Sections */
static u32 mmuSectionFlags(u32 f)
{ // converts the internal format to the hardware L1 section format
return (mmuGetShared(f) << 16) | (mmuGetTEX(f) << 12) |
(mmuGetAP(f) << 10) | (mmuGetNX(f) << 4) |
(mmuGetCB(f) << 2) | DESCRIPTOR_L1_SECTION;
}
static void mmuMapSection(u32 va, u32 pa, u32 flags)
{
mmuGlobalTT.desc[L1_VA_IDX(va)] = pa | mmuSectionFlags(flags);
}
/* Pages */
static u32 mmuPageFlags(u32 f)
{
return (mmuGetShared(f) << 10) | (mmuGetTEX(f) << 6) |
(mmuGetAP(f) << 4) | (mmuGetCB(f) << 2) |
(mmuGetNX(f) ? DESCRIPTOR_L2_PAGE_NX : DESCRIPTOR_L2_PAGE_EXEC);
}
static void mmuMapPage(u32 va, u32 pa, u32 flags)
{
mmuLevel2Table *l2 = mmuCoarseFix(va);
l2->desc[L2_VA_IDX(va)] = pa | mmuPageFlags(flags);
}
static bool mmuMappingFits(u32 va, u32 pa, u32 sz, u32 alignment)
{
return !((va | pa | sz) & (alignment));
}
u32 mmuMapArea(u32 va, u32 pa, u32 size, u32 flags)
{
static const struct {
u32 size;
void (*mapfn)(u32,u32,u32);
} VMappers[] = {
{
.size = BIT(SECT_ADDR_SHIFT),
.mapfn = mmuMapSection,
},
{
.size = BIT(PAGE_ADDR_SHIFT),
.mapfn = mmuMapPage,
},
};
while(size > 0) {
size_t i = 0;
for (i = 0; i < countof(VMappers); i++) {
u32 pgsize = VMappers[i].size;
if (mmuMappingFits(va, pa, size, pgsize-1)) {
(VMappers[i].mapfn)(va, pa, flags);
va += pgsize;
pa += pgsize;
size -= pgsize;
break;
}
}
/* alternatively return the unmapped remaining size:
if (i == countof(VMappers))
return size;
*/
}
return 0;
}
void mmuInvalidate(void)
{
ARM_MCR(p15, 0, 0, c8, c7, 0);
}
void mmuInvalidateVA(u32 addr)
{
ARM_MCR(p15, 0, addr, c8, c7, 2);
}
void mmuInitRegisters(void)
{
u32 ttbr0 = (u32)(&mmuGlobalTT) | 0x12;
// Set up TTBR0/1 and the TTCR
ARM_MCR(p15, 0, ttbr0, c2, c0, 0);
ARM_MCR(p15, 0, 0, c2, c0, 1);
ARM_MCR(p15, 0, 0, c2, c0, 2);
// Set up the DACR
ARM_MCR(p15, 0, 0x55555555, c3, c0, 0);
// Invalidate the unified TLB
ARM_MCR(p15, 0, 0, c8, c7, 0);
}

54
arm11/source/arm/mmu.h Executable file
View File

@ -0,0 +1,54 @@
/*
* This file is part of GodMode9
* Copyright (C) 2018-2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <types.h>
enum {
MMU_STRONG_ORDER = 0,
MMU_UNCACHEABLE,
MMU_DEV_SHARED,
MMU_DEV_NONSHARED,
MMU_CACHE_WT,
MMU_CACHE_WB,
MMU_CACHE_WBA,
MMU_MEMORY_TYPES,
};
enum {
MMU_NO_ACCESS = 0,
MMU_READ_ONLY,
MMU_READ_WRITE,
MMU_ACCESS_TYPES,
};
#define MMU_FLAGS(t, ap, nx, s) ((s) << 25 | (nx) << 24 | (ap) << 8 | (t))
#define MMU_FLAGS_TYPE(f) ((f) & 0xFF)
#define MMU_FLAGS_ACCESS(f) (((f) >> 8) & 0xFF)
#define MMU_FLAGS_NOEXEC(f) ((f) & BIT(24))
#define MMU_FLAGS_SHARED(f) ((f) & BIT(25))
u32 mmuMapArea(u32 va, u32 pa, u32 size, u32 flags);
void mmuInvalidate(void);
void mmuInvalidateVA(u32 addr); // DO NOT USE
void mmuInitRegisters(void);

32
arm11/source/arm/scu.c Executable file
View File

@ -0,0 +1,32 @@
/*
* This file is part of GodMode9
* Copyright (C) 2018-2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <types.h>
#include <arm.h>
#define REG_SCU_CNT (*REG_ARM_PMR(0x00, u32))
#define REG_SCU_CFG (*REG_ARM_PMR(0x04, u32))
#define REG_SCU_CPU (*REG_ARM_PMR(0x08, u32))
#define REG_SCU_INV (*REG_ARM_PMR(0x0C, u32))
void SCU_Init(void)
{
REG_SCU_CNT = 0x1FFE;
REG_SCU_INV = 0xFFFF;
REG_SCU_CNT = 0x3FFF;
}

23
arm11/source/arm/scu.h Executable file
View File

@ -0,0 +1,23 @@
/*
* This file is part of GodMode9
* Copyright (C) 2018-2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <types.h>
void SCU_Init(void);

47
arm11/source/arm/timer.c Executable file
View File

@ -0,0 +1,47 @@
/*
* This file is part of GodMode9
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <types.h>
#include <arm.h>
#include "arm/gic.h"
#include "arm/timer.h"
#define TIMER_INTERRUPT (0x1E)
#define REG_TIMER(c, n) REG_ARM_PMR(0x700 + ((c) * 0x100) + (n), u32)
#define TIMER_THIS_CPU (-1)
#define REG_TIMER_LOAD(c) *REG_TIMER((c), 0x00)
#define REG_TIMER_COUNT(c) *REG_TIMER((c), 0x04)
#define REG_TIMER_CNT(c) *REG_TIMER((c), 0x08)
#define REG_TIMER_IRQ(c) *REG_TIMER((c), 0x0C)
#define TIMER_CNT_SCALE(n) ((n) << 8)
#define TIMER_CNT_INT_EN BIT(2)
#define TIMER_CNT_RELOAD BIT(1)
#define TIMER_CNT_ENABLE BIT(0)
void TIMER_WaitTicks(u32 ticks)
{
REG_TIMER_IRQ(TIMER_THIS_CPU) = 1;
REG_TIMER_CNT(TIMER_THIS_CPU) = 0;
REG_TIMER_LOAD(TIMER_THIS_CPU) = ticks;
REG_TIMER_CNT(TIMER_THIS_CPU) = TIMER_CNT_ENABLE;
while(REG_TIMER_COUNT(TIMER_THIS_CPU));
}

36
arm11/source/arm/timer.h Executable file
View File

@ -0,0 +1,36 @@
/*
* This file is part of GodMode9
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <types.h>
// The timer interval is calculated using the following equation:
// T = [(PRESCALER_value + 1) * (Load_value + 1) * 2] / CPU_CLK
// therefore
// Load_value = [(CPU_CLK / 2) * (T / (PRESCALER_value + 1))] - 1
#define BASE_CLKRATE (268111856 / 2)
#define CLK_MS_TO_TICKS(m) (((BASE_CLKRATE / 1000) * (m)) - 1)
void TIMER_WaitTicks(u32 ticks);
static inline void TIMER_WaitMS(u32 ms) {
TIMER_WaitTicks(CLK_MS_TO_TICKS(ms));
}

219
arm11/source/arm/xrq.c Normal file
View File

@ -0,0 +1,219 @@
/*
* This file is part of GodMode9
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// kinda hardcoded and all over the place, but it needs to stay simple
#include <types.h>
#include <arm.h>
#include <vram.h>
static const u8 num_font[16*8];
#define SCREEN ((u16*)(VRAM_TOP_LA))
void draw_char(u16 *fb, int c, int x, int y)
{
for (int _y = 0; _y < 8; _y++) {
for (int _x = 0; _x < 8; _x++) {
u16 *fbpos = fb + (240 - (y + _y)) + (240 * (x + _x));
u8 mask = (num_font[(c * 8) + _y] >> (8 - _x)) & 1;
if (mask)
*fbpos = ~0;
else
*fbpos = 0;
}
}
}
void draw_hex(u16 *fb, u32 num, int x, int y)
{
x += 7*8;
for (int i = 0; i < 8; i++) {
draw_char(fb, num & 0xf, x, y);
num >>= 4;
x -= 8;
}
}
void do_exception(u32 type, u32 *regs)
{
for (int i = 0; i < 400*240; i++)
SCREEN[i] = 0;
draw_hex(SCREEN, type, 8, 16);
for (int i = 0; i < 20; i += 2) {
draw_hex(SCREEN, i, 8, 32 + (i * 4));
draw_hex(SCREEN, regs[i], 80, 32 + (i * 4));
draw_hex(SCREEN, i + 1, 208, 32 + (i * 4));
draw_hex(SCREEN, regs[i + 1], 280, 32 + (i * 4));
}
while(1)
ARM_WFI();
}
static const u8 num_font[] = {
0b00000000,
0b00011000,
0b00100100,
0b00101100,
0b00110100,
0b00100100,
0b00011000,
0b00000000, // 0
0b00000000,
0b00011000,
0b00101000,
0b00001000,
0b00001000,
0b00001000,
0b00111100,
0b00000000, // 1
0b00000000,
0b00011000,
0b00100100,
0b00000100,
0b00001000,
0b00010000,
0b00111100,
0b00000000, // 2
0b00000000,
0b00111000,
0b00000100,
0b00011000,
0b00000100,
0b00000100,
0b00111000,
0b00000000, // 3
0b00000000,
0b00100100,
0b00100100,
0b00111100,
0b00000100,
0b00000100,
0b00000100,
0b00000000, // 4
0b00000000,
0b00111100,
0b00100000,
0b00111000,
0b00000100,
0b00000100,
0b00111000,
0b00000000, // 5
0b00000000,
0b00011100,
0b00100000,
0b00111000,
0b00100100,
0b00100100,
0b00011000,
0b00000000, // 6
0b00000000,
0b00111100,
0b00000100,
0b00000100,
0b00001000,
0b00010000,
0b00010000,
0b00000000, // 7
0b00000000,
0b00011000,
0b00100100,
0b00011000,
0b00100100,
0b00100100,
0b00011000,
0b00000000, // 8
0b00000000,
0b00011000,
0b00100100,
0b00011100,
0b00000100,
0b00000100,
0b00111000,
0b00000000, // 9
0b00000000,
0b00011000,
0b00100100,
0b00111100,
0b00100100,
0b00100100,
0b00100100,
0b00000000, // A
0b00000000,
0b00111000,
0b00100100,
0b00111000,
0b00100100,
0b00100100,
0b00111000,
0b00000000, // B
0b00000000,
0b00011100,
0b00100000,
0b00100000,
0b00100000,
0b00100000,
0b00011100,
0b00000000, // C
0b00000000,
0b00110000,
0b00101000,
0b00100100,
0b00100100,
0b00101000,
0b00110000,
0b00000000, // C
0b00000000,
0b00111100,
0b00100000,
0b00111100,
0b00100000,
0b00100000,
0b00111100,
0b00000000, // E
0b00000000,
0b00111100,
0b00100000,
0b00111100,
0b00100000,
0b00100000,
0b00100000,
0b00000000, // F
};

21
arm11/source/arm/xrq.h Normal file
View File

@ -0,0 +1,21 @@
/*
* This file is part of GodMode9
* Copyright (C) 2020 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
u32 xrqInstallVectorTable(void);

View File

@ -0,0 +1,129 @@
/*
* This file is part of GodMode9
* Copyright (C) 2017-2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* This is almost the same as the ARM9 exception handler,
* but with a few extra register dumps (DFSR, IFSR and FAR)
*/
#include <arm.h>
.arm
.align 3
.macro TRAP_ENTRY xrq
msr cpsr_f, #(\xrq << 29)
b xrqMain
.endm
xrqVectorTable:
ldr pc, =xrqReset
ldr pc, =xrqUndefined
ldr pc, =xrqSVC
ldr pc, =xrqPrefetchAbort
ldr pc, =xrqDataAbort
b . @ ignore the reserved exception
ldr pc, =xrqIRQ
ldr pc, =xrqFIQ
.pool
xrqVectorTableEnd:
xrqReset:
TRAP_ENTRY 0
xrqUndefined:
TRAP_ENTRY 1
xrqSVC:
TRAP_ENTRY 2
xrqPrefetchAbort:
TRAP_ENTRY 3
xrqDataAbort:
TRAP_ENTRY 4
xrqFIQ:
TRAP_ENTRY 7
xrqMain:
clrex
cpsid aif
ldr sp, =(xrqStackTop - 32*4)
stmia sp, {r0-r7}
mrs r1, cpsr
lsr r0, r1, #29
mrs r2, spsr
str lr, [sp, #15*4]
str r2, [sp, #16*4]
ands r2, r2, #SR_PMODE_MASK
orreq r2, r2, #SR_SYS_MODE
orr r2, r2, #(0x10 | SR_NOINT)
add r3, sp, #8*4
msr cpsr_c, r2
stmia r3!, {r8-r14}
msr cpsr_c, r1
mrc p15, 0, r4, c5, c0, 0 @ data fault status register
mrc p15, 0, r5, c5, c0, 1 @ instruction fault status register
mrc p15, 0, r6, c6, c0, 0 @ data fault address
add r3, r3, #2*4 @ skip saved PC and CPSR
stmia r3!, {r4, r5, r6}
mov r1, sp
bl do_exception
xrqIRQ:
clrex
sub lr, lr, #4 @ Fix return address
srsfd sp!, #SR_SVC_MODE @ Store IRQ mode LR and SPSR on the SVC stack
cps #SR_SVC_MODE @ Switch to SVC mode
push {r0-r4, r12, lr} @ Preserve registers
and r4, sp, #7 @ Fix SP to be 8byte aligned
sub sp, sp, r4
bl gicTopHandler
add sp, sp, r4
pop {r0-r4, r12, lr}
rfeia sp! @ Return from exception
@ u32 xrqInstallVectorTable(void)
.global xrqInstallVectorTable
.type xrqInstallVectorTable, %function
xrqInstallVectorTable:
ldr r0, =xrqPage
ldr r1, =xrqVectorTable
mov r2, #(xrqVectorTableEnd - xrqVectorTable)
b memcpy
.section .bss.xrqPage
.align 12
.global xrqPage
xrqPage:
.space 8192 @ reserve two 4K aligned pages for vectors and abort stack
.global xrqStackTop
xrqStackTop:

107
arm11/source/boot.s Normal file
View File

@ -0,0 +1,107 @@
/*
* This file is part of GodMode9
* Copyright (C) 2017-2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
.section .text.boot
.align 4
#include <arm.h>
#define STACK_SZ (8192)
.global __boot
__boot:
cpsid aif, #SR_SVC_MODE
clrex
@ Writeback and invalidate all DCache
@ Invalidate all caches
@ Data Synchronization Barrier
mov r0, #0
mcr p15, 0, r0, c7, c10, 0
mcr p15, 0, r0, c7, c7, 0
mcr p15, 0, r0, c7, c10, 4
@ Reset control registers
ldr r0, =0x00054078
ldr r1, =0x0000000F
ldr r2, =0x00F00000
mcr p15, 0, r0, c1, c0, 0
mcr p15, 0, r1, c1, c0, 1
mcr p15, 0, r2, c1, c0, 2
@ VFPv2 init
@ https://github.com/derrekr/fastboot3DS/blob/f63c967369451b1fd0078e649cf0010fe10a62fd/source/arm11/start.s#L195
mov r0, #0
mov r1, #0xF00000 @ Give full access to cp10/11 in user and privileged mode
mov r2, #0x40000000 @ Clear exception bits and enable VFP11
mov r3, #0x3C00000 @ Round towards zero (RZ) mode, flush-to-zero mode, default NaN mode
mcr p15, 0, r1, c1, c0, 2 @ Write Coprocessor Access Control Register
mcr p15, 0, r0, c7, c5, 4 @ Flush Prefetch Buffer
fmxr fpexc, r2 @ Write Floating-point exception register
fmxr fpscr, r3 @ Write Floating-Point Status and Control Register
@ Get CPU ID
mrc p15, 0, r12, c0, c0, 5
ands r12, r12, #3
@ Setup stack according to CPU ID
ldr sp, =(_stack_base + STACK_SZ)
ldr r0, =STACK_SZ
mla sp, r0, r12, sp
beq corezero_start
cmp r12, #MAX_CPU
blo coresmp_start
1:
wfi
b 1b
corezero_start:
@ assumes the .bss section size is 128 byte aligned (or zero)
ldr r0, =__bss_pa
ldr r1, =__bss_va_end @ calculate the length of .bss using the VA start and end
ldr r2, =__bss_va
sub r1, r1, r2
add r1, r0, r1 @ fixup to be PA start and end
mov r2, #0
mov r3, #0
mov r4, #0
mov r5, #0
.Lclearbss:
cmp r0, r1
.rept (128 / 16) @ 16 bytes copied per block
stmloia r0!, {r2-r5}
.endr
blo .Lclearbss
bl SYS_CoreZeroInit
coresmp_start:
bl SYS_CoreInit
ldr lr, =MainLoop
bx lr
.section .bss.stack
.align 12 @ make sure stack is aligned to a page boundary
.global _stack_base
_stack_base:
.space (MAX_CPU * STACK_SZ)

146
arm11/source/hw/codec.c Executable file
View File

@ -0,0 +1,146 @@
// Somewhat based on xerpi's CODEC driver for Linux
/*
* This file is part of GodMode9
* Copyright (C) 2017 Sergi Granell, Paul LaMendola
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <common.h>
#include <types.h>
#include <hid_map.h>
#include "hw/codec.h"
#include <spi.h>
#define CPAD_THRESH_X (750)
#define CPAD_THRESH_Y (150)
/* SPI stuff */
static void CODEC_WriteRead(u32 *txb, u8 txl, u32 *rxb, u8 rxl)
{
SPI_XferInfo xfers[2];
xfers[0].buf = txb;
xfers[0].len = txl;
xfers[0].read = false;
xfers[1].buf = rxb;
xfers[1].len = rxl;
xfers[1].read = true;
SPI_DoXfer(SPI_DEV_CODEC, xfers, 2, true);
}
static void CODEC_RegSelect(u8 reg)
{
SPI_XferInfo xfer;
u32 cmd;
cmd = reg << 8;
xfer.buf = &cmd;
xfer.len = 2;
xfer.read = false;
SPI_DoXfer(SPI_DEV_CODEC, &xfer, 1, true);
}
static u8 CODEC_RegRead(u8 reg)
{
u32 cmd, ret;
cmd = (reg << 1) | 1;
CODEC_WriteRead(&cmd, 1, &ret, 1);
return ret;
}
static void CODEC_RegReadBuf(u8 reg, u32 *out, u8 size)
{
u32 cmd = (reg << 1) | 1;
CODEC_WriteRead(&cmd, 1, out, size);
}
static void CODEC_RegWrite(u8 reg, u8 val)
{
SPI_XferInfo xfer;
u32 cmd;
cmd = (val << 8) | (reg << 1);
xfer.buf = &cmd;
xfer.len = 2;
xfer.read = false;
SPI_DoXfer(SPI_DEV_CODEC, &xfer, 1, true);
}
static void CODEC_RegMask(u8 reg, u8 mask0, u8 mask1)
{
CODEC_RegWrite(reg, (CODEC_RegRead(reg) & ~mask1) | (mask0 & mask1));
}
// elder god magic
void CODEC_Init(void)
{
CODEC_RegSelect(0x67);
CODEC_RegWrite(0x24, 0x98);
CODEC_RegWrite(0x26, 0x00);
CODEC_RegWrite(0x25, 0x43);
CODEC_RegWrite(0x24, 0x18);
CODEC_RegWrite(0x17, 0x43);
CODEC_RegWrite(0x19, 0x69);
CODEC_RegWrite(0x1B, 0x80);
CODEC_RegWrite(0x27, 0x11);
CODEC_RegWrite(0x26, 0xEC);
CODEC_RegWrite(0x24, 0x18);
CODEC_RegWrite(0x25, 0x53);
CODEC_RegMask(0x26, 0x80, 0x80);
CODEC_RegMask(0x24, 0x00, 0x80);
CODEC_RegMask(0x25, 0x10, 0x3C);
}
void CODEC_GetRawData(u32 *buffer)
{
CODEC_RegSelect(0xFB);
CODEC_RegReadBuf(1, buffer, 0x34);
}
void CODEC_Get(CODEC_Input *input)
{
u32 raw_data_buf[0x34 / 4];
u8 *raw_data = (u8*)raw_data_buf;
s16 cpad_x, cpad_y;
bool ts_pressed;
CODEC_GetRawData(raw_data_buf);
cpad_x = ((raw_data[0x24] << 8 | raw_data[0x25]) & 0xFFF) - 2048;
cpad_y = ((raw_data[0x14] << 8 | raw_data[0x15]) & 0xFFF) - 2048;
// X axis is inverted
input->cpad_x = (abs(cpad_x) > CPAD_THRESH_X) ? -cpad_x : 0;
input->cpad_y = (abs(cpad_y) > CPAD_THRESH_Y) ? cpad_y : 0;
ts_pressed = !(raw_data[0] & BIT(4));
if (ts_pressed) {
input->ts_x = (raw_data[0] << 8) | raw_data[1];
input->ts_y = (raw_data[10] << 8) | raw_data[11];
} else {
input->ts_x = 0xFFFF;
input->ts_y = 0xFFFF;
}
}

32
arm11/source/hw/codec.h Executable file
View File

@ -0,0 +1,32 @@
/*
* This file is part of GodMode9
* Copyright (C) 2017 Sergi Granell, Paul LaMendola
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <types.h>
typedef struct {
s16 cpad_x, cpad_y;
u16 ts_x, ts_y;
} CODEC_Input;
void CODEC_Init(void);
void CODEC_GetRawData(u32 *buffer);
void CODEC_Get(CODEC_Input *input);

34
arm11/source/hw/gpio.h Executable file
View File

@ -0,0 +1,34 @@
/*
* This file is part of GodMode9
* Copyright (C) 2017 derrek, profi200
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <types.h>
#define REG_GPIO ((vu16*)(0x10100000 + 0x47000))
static inline void GPIO_setBit(u16 reg, u8 bitNum)
{
REG_GPIO[reg] |= 1u<<bitNum;
}
static inline void GPIO_clearBit(u16 reg, u8 bitNum)
{
REG_GPIO[reg] &= ~(1u<<bitNum);
}

304
arm11/source/hw/gpulcd.c Normal file
View File

@ -0,0 +1,304 @@
/*
* This file is part of GodMode9
* Copyright (C) 2017-2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <common.h>
#include <types.h>
#include <vram.h>
#include <arm.h>
#include "arm/timer.h"
#include "hw/i2c.h"
#include "hw/mcu.h"
#include "hw/gpulcd.h"
#include "system/event.h"
static struct
{
u16 lcdIds; // Bits 0-7 top screen, 8-15 bottom screen.
bool lcdIdsRead;
u8 lcdPower; // 1 = on. Bit 4 top light, bit 2 bottom light, bit 0 LCDs.
u8 lcdLights[2]; // LCD backlight brightness. Top, bottom.
u32 framebufs[2]; // For each screen
u8 doubleBuf[2]; // Top, bottom, 1 = enable.
u16 strides[2]; // Top, bottom
u32 formats[2]; // Top, bottom
} g_gfxState = {0};
static void setupDisplayController(u8 lcd);
static void resetLcdsMaybe(void);
static void waitLcdsReady(void);
static u32 gxModeWidth(unsigned c) {
switch(c) {
case 0: return 4;
case 1: return 3;
default: return 2;
}
}
unsigned GFX_init(GfxFbFmt mode)
{
unsigned err = 0;
REG_CFG11_GPUPROT = 0;
// Reset
REG_PDN_GPU_CNT = PDN_GPU_CNT_CLK_E;
ARM_WaitCycles(12);
REG_PDN_GPU_CNT = PDN_GPU_CNT_CLK_E | PDN_GPU_CNT_RST_ALL;
REG_GX_GPU_CLK = 0x100;
REG_GX_PSC_VRAM = 0;
REG_GX_PSC_FILL0_CNT = 0;
REG_GX_PSC_FILL1_CNT = 0;
REG_GX_PPF_CNT = 0;
// LCD framebuffer setup.
g_gfxState.strides[0] = 240 * gxModeWidth(mode);
g_gfxState.strides[1] = 240 * gxModeWidth(mode);
g_gfxState.framebufs[0] = VRAM_TOP_LA;
g_gfxState.framebufs[1] = VRAM_BOT_A;
g_gfxState.formats[0] = mode | BIT(6) | BIT(9);
g_gfxState.formats[1] = mode | BIT(9);
setupDisplayController(0);
setupDisplayController(1);
REG_LCD_PDC0_SWAP = 0; // Select framebuf 0.
REG_LCD_PDC1_SWAP = 0;
REG_LCD_PDC0_CNT = PDC_CNT_OUT_E | PDC_CNT_I_MASK_ERR | PDC_CNT_I_MASK_H | PDC_CNT_E; // Start
REG_LCD_PDC1_CNT = PDC_CNT_OUT_E | PDC_CNT_I_MASK_ERR | PDC_CNT_I_MASK_H | PDC_CNT_E;
// LCD reg setup.
REG_LCD_ABL0_FILL = 1u<<24; // Force blackscreen
REG_LCD_ABL1_FILL = 1u<<24; // Force blackscreen
REG_LCD_PARALLAX_CNT = 0;
REG_LCD_PARALLAX_PWM = 0xA390A39;
REG_LCD_RST = 0;
REG_LCD_UNK00C = 0x10001;
// Clear used VRAM
REG_GX_PSC_FILL0_S_ADDR = VRAM_TOP_LA >> 3;
REG_GX_PSC_FILL0_E_ADDR = VRAM_END >> 3;
REG_GX_PSC_FILL0_VAL = 0;
REG_GX_PSC_FILL0_CNT = BIT(9) | BIT(0);
// Backlight and other stuff.
REG_LCD_ABL0_LIGHT = 0;
REG_LCD_ABL0_CNT = 0;
REG_LCD_ABL0_LIGHT_PWM = 0;
REG_LCD_ABL1_LIGHT = 0;
REG_LCD_ABL1_CNT = 0;
REG_LCD_ABL1_LIGHT_PWM = 0;
REG_LCD_RST = 1;
REG_LCD_UNK00C = 0;
TIMER_WaitMS(10);
resetLcdsMaybe();
MCU_controlLCDPower(2u); // Power on LCDs.
if(eventWait(getEventMCU(), 0x3Fu<<24, 0x3Fu<<24) != 2u<<24) __builtin_trap();
waitLcdsReady();
REG_LCD_ABL0_LIGHT_PWM = 0x1023E;
REG_LCD_ABL1_LIGHT_PWM = 0x1023E;
MCU_controlLCDPower(0x28u); // Power on backlights.
if(eventWait(getEventMCU(), 0x3Fu<<24, 0x3Fu<<24) != 0x28u<<24) __builtin_trap();
g_gfxState.lcdPower = 0x15; // All on.
// Make sure the fills finished.
REG_LCD_ABL0_FILL = 0;
REG_LCD_ABL1_FILL = 0;
// GPU stuff.
REG_GX_GPU_CLK = 0x70100;
*((vu32*)0x10400050) = 0x22221200;
*((vu32*)0x10400054) = 0xFF2;
GFX_setBrightness(0x80, 0x80);
return err;
}
static u16 getLcdIds(void)
{
u16 ids;
if(!g_gfxState.lcdIdsRead)
{
g_gfxState.lcdIdsRead = true;
u16 top, bot;
I2C_writeReg(I2C_DEV_LCD0, 0x40, 0xFF);
I2C_readRegBuf(I2C_DEV_LCD0, 0x40, (u8*)&top, 2);
I2C_writeReg(I2C_DEV_LCD1, 0x40, 0xFF);
I2C_readRegBuf(I2C_DEV_LCD1, 0x40, (u8*)&bot, 2);
ids = top>>8;
ids |= bot & 0xFF00u;
g_gfxState.lcdIds = ids;
}
else ids = g_gfxState.lcdIds;
return ids;
}
static void resetLcdsMaybe(void)
{
const u16 ids = getLcdIds();
// Top screen
if(ids & 0xFFu) I2C_writeReg(I2C_DEV_LCD0, 0xFE, 0xAA);
else
{
I2C_writeReg(I2C_DEV_LCD0, 0x11, 0x10);
I2C_writeReg(I2C_DEV_LCD0, 0x50, 1);
}
// Bottom screen
if(ids>>8) I2C_writeReg(I2C_DEV_LCD1, 0xFE, 0xAA);
else I2C_writeReg(I2C_DEV_LCD1, 0x11, 0x10);
I2C_writeReg(I2C_DEV_LCD0, 0x60, 0);
I2C_writeReg(I2C_DEV_LCD1, 0x60, 0);
I2C_writeReg(I2C_DEV_LCD0, 1, 0x10);
I2C_writeReg(I2C_DEV_LCD1, 1, 0x10);
}
static void waitLcdsReady(void)
{
const u16 ids = getLcdIds();
if((ids & 0xFFu) == 0 || (ids>>8) == 0) // Unknown LCD?
{
TIMER_WaitMS(150);
}
else
{
u32 i = 0;
do
{
u16 top, bot;
I2C_writeReg(I2C_DEV_LCD0, 0x40, 0x62);
I2C_readRegBuf(I2C_DEV_LCD0, 0x40, (u8*)&top, 2);
I2C_writeReg(I2C_DEV_LCD1, 0x40, 0x62);
I2C_readRegBuf(I2C_DEV_LCD1, 0x40, (u8*)&bot, 2);
if((top>>8) == 1 && (bot>>8) == 1) break;
TIMER_WaitMS(33);
} while(i++ < 10);
}
}
void GFX_powerOnBacklights(GfxBlight mask)
{
g_gfxState.lcdPower |= mask;
mask <<= 1;
MCU_controlLCDPower(mask); // Power on backlights.
eventWait(getEventMCU(), 0x3F<<24, 0x3F<<24);
/*if(mcuEventWait(0x3Fu<<24) != (u32)mask<<24)
__builtin_trap();*/
}
void GFX_powerOffBacklights(GfxBlight mask)
{
g_gfxState.lcdPower &= ~mask;
MCU_controlLCDPower(mask); // Power off backlights.
eventWait(getEventMCU(), 0x3F<<24, 0x3F<<24);
/*if(mcuEventWait(0x3Fu<<24) != (u32)mask<<24)
__builtin_trap();*/
}
u8 GFX_getBrightness(void)
{
return REG_LCD_ABL0_LIGHT;
}
void GFX_setBrightness(u8 top, u8 bot)
{
g_gfxState.lcdLights[0] = top;
g_gfxState.lcdLights[1] = bot;
REG_LCD_ABL0_LIGHT = top;
REG_LCD_ABL1_LIGHT = bot;
}
void GFX_setForceBlack(bool top, bool bot)
{
REG_LCD_ABL0_FILL = (u32)top<<24; // Force blackscreen
REG_LCD_ABL1_FILL = (u32)bot<<24; // Force blackscreen
}
static void setupDisplayController(u8 lcd)
{
if(lcd > 1) return;
static const u32 displayCfgs[2][24] =
{
{
// PDC0 regs 0-0x4C.
450, 209, 449, 449, 0, 207, 209, 453<<16 | 449,
1<<16 | 0, 413, 2, 402, 402, 402, 1, 2,
406<<16 | 402, 0, 0<<4 | 0, 0<<16 | 0xFF<<8 | 0,
// PDC0 regs 0x5C-0x64.
400<<16 | 240, // Width and height.
449<<16 | 209,
402<<16 | 2,
// PDC0 reg 0x9C.
0<<16 | 0
},
{
// PDC1 regs 0-0x4C.
450, 209, 449, 449, 205, 207, 209, 453<<16 | 449,
1<<16 | 0, 413, 82, 402, 402, 79, 80, 82,
408<<16 | 404, 0, 1<<4 | 1, 0<<16 | 0<<8 | 0xFF,
// PDC1 regs 0x5C-0x64.
320<<16 | 240, // Width and height.
449<<16 | 209,
402<<16 | 82,
// PDC1 reg 0x9C.
0<<16 | 0
}
};
const u32 *const cfg = displayCfgs[lcd];
vu32 *const regs = (vu32*)(GX_REGS_BASE + 0x400 + (0x100u * lcd));
for (unsigned i = 0; i < 0x50/4; i++)
regs[i] = cfg[i];
for (unsigned i = 0; i < 0xC/4; i++)
regs[23 + i] = cfg[20 + i];
regs[36] = g_gfxState.strides[lcd]; // PDC reg 0x90 stride.
regs[39] = cfg[23]; // PDC reg 0x9C.
// PDC regs 0x68, 0x6C, 0x94, 0x98 and 0x70.
regs[26] = g_gfxState.framebufs[lcd]; // Framebuffer A first address.
regs[27] = g_gfxState.framebufs[lcd]; // Framebuffer A second address.
regs[37] = g_gfxState.framebufs[lcd]; // Framebuffer B first address.
regs[38] = g_gfxState.framebufs[lcd]; // Framebuffer B second address.
regs[28] = g_gfxState.formats[lcd]; // Format
regs[32] = 0; // Gamma table index 0.
for(u32 i = 0; i < 256; i++) regs[33] = 0x10101u * i;
}

186
arm11/source/hw/gpulcd.h Normal file
View File

@ -0,0 +1,186 @@
/*
* This file is part of GodMode9
* Copyright (C) 2017-2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <types.h>
#define VBLANK_INTERRUPT (0x2A)
enum
{
PDN_GPU_CNT_RST_REGS = 1u, // And more?
PDN_GPU_CNT_RST_PSC = 1u<<1, // ?
PDN_GPU_CNT_RST_GEOSHADER = 1u<<2, // ?
PDN_GPU_CNT_RST_RASTERIZER = 1u<<3, // ?
PDN_GPU_CNT_RST_PPF = 1u<<4,
PDN_GPU_CNT_RST_PDC = 1u<<5, // ?
PDN_GPU_CNT_RST_PDC2 = 1u<<6, // Maybe pixel pipeline or so?
PDN_GPU_CNT_RST_ALL = (PDN_GPU_CNT_RST_PDC2<<1) - 1
};
typedef enum
{
GFX_RGBA8 = 0, ///< RGBA8. (4 bytes)
GFX_BGR8 = 1, ///< BGR8. (3 bytes)
GFX_RGB565 = 2, ///< RGB565. (2 bytes)
GFX_RGB5A1 = 3, ///< RGB5A1. (2 bytes)
GFX_RGBA4 = 4 ///< RGBA4. (2 bytes)
} GfxFbFmt;
typedef enum
{
GFX_EVENT_PSC0 = 0u,
GFX_EVENT_PSC1 = 1u,
GFX_EVENT_PDC0 = 2u,
GFX_EVENT_PDC1 = 3u,
GFX_EVENT_PPF = 4u,
GFX_EVENT_P3D = 5u
} GfxEvent;
typedef enum
{
GFX_BLIGHT_BOT = 1u<<2,
GFX_BLIGHT_TOP = 1u<<4,
GFX_BLIGHT_BOTH = GFX_BLIGHT_TOP | GFX_BLIGHT_BOT
} GfxBlight;
#define REG_CFG11_GPUPROT *((vu16*)(0x10140140))
#define REG_PDN_GPU_CNT *((vu32*)(0x10141200))
#define PDN_GPU_CNT_CLK_E (1u<<16)
#define PDN_VRAM_CNT_CLK_E (1u)
#define GX_REGS_BASE (0x10400000)
#define REG_GX_GPU_CLK *((vu32*)(GX_REGS_BASE + 0x0004)) // ?
// PSC (memory fill) regs.
#define REG_GX_PSC_FILL0_S_ADDR *((vu32*)(GX_REGS_BASE + 0x0010)) // Start address
#define REG_GX_PSC_FILL0_E_ADDR *((vu32*)(GX_REGS_BASE + 0x0014)) // End address
#define REG_GX_PSC_FILL0_VAL *((vu32*)(GX_REGS_BASE + 0x0018)) // Fill value
#define REG_GX_PSC_FILL0_CNT *((vu32*)(GX_REGS_BASE + 0x001C))
#define REG_GX_PSC_FILL1_S_ADDR *((vu32*)(GX_REGS_BASE + 0x0020))
#define REG_GX_PSC_FILL1_E_ADDR *((vu32*)(GX_REGS_BASE + 0x0024))
#define REG_GX_PSC_FILL1_VAL *((vu32*)(GX_REGS_BASE + 0x0028))
#define REG_GX_PSC_FILL1_CNT *((vu32*)(GX_REGS_BASE + 0x002C))
#define REG_GX_PSC_VRAM *((vu32*)(GX_REGS_BASE + 0x0030)) // gsp mudule only changes bit 8-11.
#define REG_GX_PSC_STAT *((vu32*)(GX_REGS_BASE + 0x0034))
// PDC0/1 regs see lcd.h.
// PPF (transfer engine) regs.
#define REG_GX_PPF_IN_ADDR *((vu32*)(GX_REGS_BASE + 0x0C00))
#define REG_GX_PPF_OUT_ADDR *((vu32*)(GX_REGS_BASE + 0x0C04))
#define REG_GX_PPF_DT_OUTDIM *((vu32*)(GX_REGS_BASE + 0x0C08)) // Display transfer output dimensions.
#define REG_GX_PPF_DT_INDIM *((vu32*)(GX_REGS_BASE + 0x0C0C)) // Display transfer input dimensions.
#define REG_GX_PPF_FlAGS *((vu32*)(GX_REGS_BASE + 0x0C10))
#define REG_GX_PPF_UNK14 *((vu32*)(GX_REGS_BASE + 0x0C14)) // Transfer interval?
#define REG_GX_PPF_CNT *((vu32*)(GX_REGS_BASE + 0x0C18))
#define REG_GX_PPF_IRQ_POS *((vu32*)(GX_REGS_BASE + 0x0C1C)) // ?
#define REG_GX_PPF_LEN *((vu32*)(GX_REGS_BASE + 0x0C20)) // Texture copy size in bytes.
#define REG_GX_PPF_TC_INDIM *((vu32*)(GX_REGS_BASE + 0x0C24)) // Texture copy input width and gap in 16 byte units.
#define REG_GX_PPF_TC_OUTDIM *((vu32*)(GX_REGS_BASE + 0x0C28)) // Texture copy output width and gap in 16 byte units.
// P3D (GPU internal) regs. See gpu_regs.h.
#define REG_GX_P3D(reg) *((vu32*)(GX_REGS_BASE + 0x1000 + ((reg) * 4)))
// LCD/ABL regs.
#define LCD_REGS_BASE (0x10202000)
#define REG_LCD_PARALLAX_CNT *((vu32*)(LCD_REGS_BASE + 0x000)) // Controls PWM for the parallax barrier?
#define REG_LCD_PARALLAX_PWM *((vu32*)(LCD_REGS_BASE + 0x004)) // Frequency/other PWM stuff maybe?
#define REG_LCD_UNK00C *((vu32*)(LCD_REGS_BASE + 0x00C)) // Wtf is "FIX"?
#define REG_LCD_RST *((vu32*)(LCD_REGS_BASE + 0x014)) // Reset active low.
#define REG_LCD_ABL0_CNT *((vu32*)(LCD_REGS_BASE + 0x200)) // Bit 0 enables ABL aka power saving mode.
#define REG_LCD_ABL0_FILL *((vu32*)(LCD_REGS_BASE + 0x204))
#define REG_LCD_ABL0_LIGHT *((vu32*)(LCD_REGS_BASE + 0x240))
#define REG_LCD_ABL0_LIGHT_PWM *((vu32*)(LCD_REGS_BASE + 0x244))
#define REG_LCD_ABL1_CNT *((vu32*)(LCD_REGS_BASE + 0xA00)) // Bit 0 enables ABL aka power saving mode.
#define REG_LCD_ABL1_FILL *((vu32*)(LCD_REGS_BASE + 0xA04))
#define REG_LCD_ABL1_LIGHT *((vu32*)(LCD_REGS_BASE + 0xA40))
#define REG_LCD_ABL1_LIGHT_PWM *((vu32*)(LCD_REGS_BASE + 0xA44))
// Technically these regs belong in gx.h but they are used for LCD configuration so...
// Pitfall warning: The 3DS LCDs are physically rotated 90° CCW.
// PDC0 (top screen display controller) regs.
#define REG_LCD_PDC0_HTOTAL *((vu32*)(GX_REGS_BASE + 0x400))
#define REG_LCD_PDC0_VTOTAL *((vu32*)(GX_REGS_BASE + 0x424))
#define REG_LCD_PDC0_HPOS *((const vu32*)(GX_REGS_BASE + 0x450))
#define REG_LCD_PDC0_VPOS *((const vu32*)(GX_REGS_BASE + 0x454))
#define REG_LCD_PDC0_FB_A1 *((vu32*)(GX_REGS_BASE + 0x468))
#define REG_LCD_PDC0_FB_A2 *((vu32*)(GX_REGS_BASE + 0x46C))
#define REG_LCD_PDC0_FMT *((vu32*)(GX_REGS_BASE + 0x470))
#define REG_LCD_PDC0_CNT *((vu32*)(GX_REGS_BASE + 0x474))
#define REG_LCD_PDC0_SWAP *((vu32*)(GX_REGS_BASE + 0x478))
#define REG_LCD_PDC0_STAT *((const vu32*)(GX_REGS_BASE + 0x47C))
#define REG_LCD_PDC0_GTBL_IDX *((vu32*)(GX_REGS_BASE + 0x480)) // Gamma table index.
#define REG_LCD_PDC0_GTBL_FIFO *((vu32*)(GX_REGS_BASE + 0x484)) // Gamma table FIFO.
#define REG_LCD_PDC0_STRIDE *((vu32*)(GX_REGS_BASE + 0x490))
#define REG_LCD_PDC0_FB_B1 *((vu32*)(GX_REGS_BASE + 0x494))
#define REG_LCD_PDC0_FB_B2 *((vu32*)(GX_REGS_BASE + 0x498))
// PDC1 (bottom screen display controller) regs.
#define REG_LCD_PDC1_HTOTAL *((vu32*)(GX_REGS_BASE + 0x500))
#define REG_LCD_PDC1_VTOTAL *((vu32*)(GX_REGS_BASE + 0x524))
#define REG_LCD_PDC1_HPOS *((const vu32*)(GX_REGS_BASE + 0x550))
#define REG_LCD_PDC1_VPOS *((const vu32*)(GX_REGS_BASE + 0x554))
#define REG_LCD_PDC1_FB_A1 *((vu32*)(GX_REGS_BASE + 0x568))
#define REG_LCD_PDC1_FB_A2 *((vu32*)(GX_REGS_BASE + 0x56C))
#define REG_LCD_PDC1_FMT *((vu32*)(GX_REGS_BASE + 0x570))
#define REG_LCD_PDC1_CNT *((vu32*)(GX_REGS_BASE + 0x574))
#define REG_LCD_PDC1_SWAP *((vu32*)(GX_REGS_BASE + 0x578))
#define REG_LCD_PDC1_STAT *((const vu32*)(GX_REGS_BASE + 0x57C))
#define REG_LCD_PDC1_GTBL_IDX *((vu32*)(GX_REGS_BASE + 0x580)) // Gamma table index.
#define REG_LCD_PDC1_GTBL_FIFO *((vu32*)(GX_REGS_BASE + 0x584)) // Gamma table FIFO.
#define REG_LCD_PDC1_STRIDE *((vu32*)(GX_REGS_BASE + 0x590))
#define REG_LCD_PDC1_FB_B1 *((vu32*)(GX_REGS_BASE + 0x594))
#define REG_LCD_PDC1_FB_B2 *((vu32*)(GX_REGS_BASE + 0x598))
// REG_LCD_PDC_CNT
#define PDC_CNT_E (1u)
#define PDC_CNT_I_MASK_H (1u<<8) // Disables H(Blank?) IRQs.
#define PDC_CNT_I_MASK_V (1u<<9) // Disables VBlank IRQs.
#define PDC_CNT_I_MASK_ERR (1u<<10) // Disables error IRQs. What kind of errors?
#define PDC_CNT_OUT_E (1u<<16) // Output enable?
// REG_LCD_PDC_SWAP
// Masks
#define PDC_SWAP_NEXT (1u) // Next framebuffer.
#define PDC_SWAP_CUR (1u<<4) // Currently displaying framebuffer?
// Bits
#define PDC_SWAP_RST_FIFO (1u<<8) // Which FIFO?
#define PDC_SWAP_I_H (1u<<16) // H(Blank?) IRQ bit.
#define PDC_SWAP_I_V (1u<<17) // VBlank IRQ bit.
#define PDC_SWAP_I_ERR (1u<<18) // Error IRQ bit?
#define PDC_SWAP_I_ALL (PDC_SWAP_I_ERR | PDC_SWAP_I_V | PDC_SWAP_I_H)
unsigned GFX_init(GfxFbFmt mode);
void GFX_setForceBlack(bool top, bool bot);
void GFX_powerOnBacklights(GfxBlight mask);
void GFX_powerOffBacklights(GfxBlight mask);
u8 GFX_getBrightness(void);
void GFX_setBrightness(u8 top, u8 bot);

65
arm11/source/hw/hid.c Executable file
View File

@ -0,0 +1,65 @@
/*
* This file is part of GodMode9
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <common.h>
#include <types.h>
#include <hid_map.h>
#include "hw/codec.h"
#include "hw/hid.h"
#include "hw/mcu.h"
#define REG_HID (~(*(vu16*)(0x10146000)) & BUTTON_ANY)
static u32 HID_ConvertCPAD(s16 cpad_x, s16 cpad_y)
{
u32 ret = 0;
if (cpad_x > 0) {
ret |= BUTTON_RIGHT;
} else if (cpad_x < 0) {
ret |= BUTTON_LEFT;
}
if (cpad_y > 0) {
ret |= BUTTON_UP;
} else if (cpad_y < 0) {
ret |= BUTTON_DOWN;
}
return ret;
}
u64 HID_GetState(void)
{
CODEC_Input codec;
u64 ret = 0;
CODEC_Get(&codec);
ret = REG_HID | mcuGetSpecialHID();
if (!(ret & BUTTON_ARROW))
ret |= HID_ConvertCPAD(codec.cpad_x, codec.cpad_y);
if (codec.ts_x <= 0xFFF)
ret |= BUTTON_TOUCH;
ret |= (((u64)codec.ts_x << 16) | (u64)codec.ts_y) << 32;
return ret;
}

24
arm11/source/hw/hid.h Executable file
View File

@ -0,0 +1,24 @@
/*
* This file is part of GodMode9
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <types.h>
#include <hid_map.h>
u64 HID_GetState(void);

214
arm11/source/hw/i2c.c Normal file
View File

@ -0,0 +1,214 @@
/*
* This file is part of fastboot 3DS
* Copyright (C) 2017 derrek, profi200
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <types.h>
#include "hw/i2c.h"
#define I2C1_REGS_BASE (0x10161000)
#define I2C2_REGS_BASE (0x10144000)
#define I2C3_REGS_BASE (0x10148000)
typedef struct
{
vu8 REG_I2C_DATA;
vu8 REG_I2C_CNT;
vu16 REG_I2C_CNTEX;
vu16 REG_I2C_SCL;
} I2cRegs;
static const struct
{
u8 busId;
u8 devAddr;
} i2cDevTable[] =
{
{0, 0x4A},
{0, 0x7A},
{0, 0x78},
{1, 0x4A},
{1, 0x78},
{1, 0x2C},
{1, 0x2E},
{1, 0x40},
{1, 0x44},
{2, 0xD6},
{2, 0xD0},
{2, 0xD2},
{2, 0xA4},
{2, 0x9A},
{2, 0xA0},
{1, 0xEE},
{0, 0x40},
{2, 0x54}
};
static void i2cWaitBusy(I2cRegs *const regs)
{
while(regs->REG_I2C_CNT & I2C_ENABLE);
}
static I2cRegs* i2cGetBusRegsBase(u8 busId)
{
I2cRegs *base;
switch(busId)
{
case 0:
base = (I2cRegs*)I2C1_REGS_BASE;
break;
case 1:
base = (I2cRegs*)I2C2_REGS_BASE;
break;
case 2:
base = (I2cRegs*)I2C3_REGS_BASE;
break;
default:
base = NULL;
}
return base;
}
void I2C_init(void)
{
I2cRegs *regs = i2cGetBusRegsBase(0); // Bus 1
i2cWaitBusy(regs);
regs->REG_I2C_CNTEX = 2; // ?
regs->REG_I2C_SCL = 1280; // ?
regs = i2cGetBusRegsBase(1); // Bus 2
i2cWaitBusy(regs);
regs->REG_I2C_CNTEX = 2; // ?
regs->REG_I2C_SCL = 1280; // ?
regs = i2cGetBusRegsBase(2); // Bus 3
i2cWaitBusy(regs);
regs->REG_I2C_CNTEX = 2; // ?
regs->REG_I2C_SCL = 1280; // ?
}
static bool i2cStartTransfer(int devId, u8 regAddr, bool read, I2cRegs *const regs)
{
const u8 devAddr = i2cDevTable[devId].devAddr;
u32 i = 0;
for(; i < 8; i++)
{
i2cWaitBusy(regs);
// Select device and start.
regs->REG_I2C_DATA = devAddr;
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_START;
i2cWaitBusy(regs);
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
{
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
continue;
}
// Select register and change direction to write.
regs->REG_I2C_DATA = regAddr;
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_WRITE;
i2cWaitBusy(regs);
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
{
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
continue;
}
// Select device in read mode for read transfer.
if(read)
{
regs->REG_I2C_DATA = devAddr | 1u; // Set bit 0 for read.
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_START;
i2cWaitBusy(regs);
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
{
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
continue;
}
}
break;
}
if(i < 8) return true;
else return false;
}
bool I2C_readRegBuf(int devId, u8 regAddr, u8 *out, u32 size)
{
const u8 busId = i2cDevTable[devId].busId;
I2cRegs *const regs = i2cGetBusRegsBase(busId);
if(!i2cStartTransfer(devId, regAddr, true, regs)) return false;
while(--size)
{
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_READ | I2C_ACK;
i2cWaitBusy(regs);
*out++ = regs->REG_I2C_DATA;
}
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_READ | I2C_STOP;
i2cWaitBusy(regs);
*out = regs->REG_I2C_DATA; // Last byte
return true;
}
bool I2C_writeRegBuf(int devId, u8 regAddr, const u8 *in, u32 size)
{
const u8 busId = i2cDevTable[devId].busId;
I2cRegs *const regs = i2cGetBusRegsBase(busId);
if(!i2cStartTransfer(devId, regAddr, false, regs)) return false;
while(--size)
{
regs->REG_I2C_DATA = *in++;
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_WRITE;
i2cWaitBusy(regs);
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
{
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
return false;
}
}
regs->REG_I2C_DATA = *in;
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_WRITE | I2C_STOP;
i2cWaitBusy(regs);
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
{
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
return false;
}
return true;
}

77
arm11/source/hw/i2c.h Normal file
View File

@ -0,0 +1,77 @@
/*
* This file is part of fastboot 3DS
* Copyright (C) 2017 derrek, profi200
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdbool.h>
#include <types.h>
#define I2C_STOP (1u)
#define I2C_START (1u<<1)
#define I2C_ERROR (1u<<2)
#define I2C_ACK (1u<<4)
#define I2C_DIRE_WRITE (0u)
#define I2C_DIRE_READ (1u<<5)
#define I2C_IRQ_ENABLE (1u<<6)
#define I2C_ENABLE (1u<<7)
#define I2C_DEV_LCD0 5
#define I2C_DEV_LCD1 6
#define I2C_GET_ACK(reg) ((bool)((reg)>>4 & 1u))
/**
* @brief Initializes the I2C buses. Call this only once.
*/
void I2C_init(void);
/**
* @brief Reads data from a I2C register to a buffer.
*
* @param[in] devId The device ID. Use the enum above.
* @param[in] regAddr The register address.
* @param out The output buffer pointer.
* @param[in] size The read size.
*
* @return Returns true on success and false on failure.
*/
bool I2C_readRegBuf(int devId, u8 regAddr, u8 *out, u32 size);
/**
* @brief Writes a buffer to a I2C register.
*
* @param[in] devId The device ID. Use the enum above.
* @param[in] regAddr The register address.
* @param[in] in The input buffer pointer.
* @param[in] size The write size.
*
* @return Returns true on success and false on failure.
*/
bool I2C_writeRegBuf(int devId, u8 regAddr, const u8 *in, u32 size);
static inline u8 I2C_readReg(int devId, u8 regAddr) {
u8 v;
I2C_readRegBuf(devId, regAddr, &v, 1);
return v;
}
static inline void I2C_writeReg(int devId, u8 regAddr, u8 v) {
I2C_writeRegBuf(devId, regAddr, &v, 1);
}

198
arm11/source/hw/mcu.c Executable file
View File

@ -0,0 +1,198 @@
/*
* This file is part of GodMode9
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <hid_map.h>
#include <types.h>
#include <arm.h>
#include <stdatomic.h>
#include "common.h"
#include "arm/timer.h"
#include "hw/gpio.h"
#include "hw/gpulcd.h"
#include "hw/mcu.h"
#include "system/event.h"
#define MCUEV_HID_MASK ( \
MCUEV_HID_PWR_DOWN | MCUEV_HID_PWR_HOLD | \
MCUEV_HID_HOME_DOWN | MCUEV_HID_HOME_UP | MCUEV_HID_WIFI_SWITCH)
enum {
MCUREG_VOLUME_SLIDER = 0x09,
MCUREG_BATTERY_LEVEL = 0x0B,
MCUREG_CONSOLE_STATE = 0x0F,
MCUREG_INT_MASK = 0x10,
MCUREG_INT_EN = 0x18,
MCUREG_LCD_STATE = 0x22,
MCUREG_LED_WIFI = 0x2A,
MCUREG_LED_CAMERA = 0x2B,
MCUREG_LED_SLIDER = 0x2C,
MCUREG_LED_STATUS = 0x2D,
MCUREG_RTC = 0x30,
};
typedef struct {
u8 delay;
u8 smoothing;
u8 loop_delay;
u8 unk;
u32 red[8];
u32 green[8];
u32 blue[8];
} PACKED_STRUCT mcuStatusLED;
static u8 volumeSliderValue;
static u32 shellState;
static _Atomic(u32) pendingEvents;
static void mcuEventUpdate(void)
{
u32 mask;
// lazily update the mask on each test attempt
if (!getEventIRQ()->test(MCU_INTERRUPT, true))
return;
// reading the pending mask automagically acknowledges
// the interrupts so all of them must be processed in one go
mcuReadRegBuf(MCUREG_INT_MASK, (u8*)&mask, sizeof(mask));
if (mask & MCUEV_HID_VOLUME_SLIDER)
volumeSliderValue = mcuReadReg(MCUREG_VOLUME_SLIDER);
if (mask & MCUEV_HID_SHELL_OPEN) {
mcuResetLEDs();
shellState = SHELL_OPEN;
}
if (mask & MCUEV_HID_SHELL_CLOSE) {
shellState = SHELL_CLOSED;
}
atomic_fetch_or(&pendingEvents, mask);
}
u8 mcuGetVolumeSlider(void)
{
mcuEventUpdate();
return volumeSliderValue;
}
u32 mcuGetSpecialHID(void)
{
u32 ret = 0, pend = getEventMCU()->test(MCUEV_HID_MASK, MCUEV_HID_MASK);
// hopefully gets unrolled
if (pend & (MCUEV_HID_PWR_DOWN | MCUEV_HID_PWR_HOLD))
ret |= BUTTON_POWER;
if (pend & MCUEV_HID_HOME_DOWN)
ret |= BUTTON_HOME;
if (pend & MCUEV_HID_HOME_UP)
ret &= ~BUTTON_HOME;
return ret | shellState;
}
void mcuSetStatusLED(u32 period_ms, u32 color)
{
u32 r, g, b, delay;
mcuStatusLED ledState;
delay = clamp((period_ms * 0x200) / 1000, 1, 0xFF);
ledState.delay = delay;
ledState.smoothing = delay;
ledState.loop_delay = 0x10;
ledState.unk = 0;
// all colors look like 0x00ZZ00ZZ
// in order to alternate between
// LED "off" and the wanted color
r = (color >> 16) & 0xFF;
r |= r << 16;
for (int i = 0; i < 8; i++)
ledState.red[i] = r;
g = (color >> 8) & 0xFF;
g |= g << 16;
for (int i = 0; i < 8; i++)
ledState.green[i] = g;
b = color & 0xFF;
b |= b << 16;
for (int i = 0; i < 8; i++)
ledState.blue[i] = b;
mcuWriteRegBuf(MCUREG_LED_STATUS, (const u8*)&ledState, sizeof(ledState));
}
void mcuResetLEDs(void)
{
mcuWriteReg(MCUREG_LED_WIFI, 0);
mcuWriteReg(MCUREG_LED_CAMERA, 0);
mcuWriteReg(MCUREG_LED_SLIDER, 0);
mcuSetStatusLED(0, 0);
}
void mcuReset(void)
{
u32 intmask = 0;
atomic_init(&pendingEvents, 0);
// set register mask and clear any pending registers
mcuWriteRegBuf(MCUREG_INT_EN, (const u8*)&intmask, sizeof(intmask));
mcuReadRegBuf(MCUREG_INT_MASK, (u8*)&intmask, sizeof(intmask));
mcuResetLEDs();
volumeSliderValue = mcuReadReg(MCUREG_VOLUME_SLIDER);
shellState = SHELL_OPEN;
// assume the shell is always open on boot
// knowing the average 3DS user, there will be plenty
// of laughs when this comes back to bite us in the rear
GPIO_setBit(19, 9);
}
static void evReset(void) {
atomic_store(&pendingEvents, 0);
}
static u32 evTest(u32 mask, u32 clear) {
mcuEventUpdate();
return atomic_fetch_and(&pendingEvents, ~clear) & mask;
}
static const EventInterface evMCU = {
.reset = evReset,
.test = evTest
};
const EventInterface *getEventMCU(void) {
return &evMCU;
}

73
arm11/source/hw/mcu.h Executable file
View File

@ -0,0 +1,73 @@
/*
* This file is part of GodMode9
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <types.h>
#include "arm/timer.h"
#include "hw/i2c.h"
#define MCU_INTERRUPT (0x71)
#define I2C_MCU_DEVICE (3)
enum {
MCUEV_HID_PWR_DOWN = BIT(0),
MCUEV_HID_PWR_HOLD = BIT(1),
MCUEV_HID_HOME_DOWN = BIT(2),
MCUEV_HID_HOME_UP = BIT(3),
MCUEV_HID_WIFI_SWITCH = BIT(4),
MCUEV_HID_SHELL_CLOSE = BIT(5),
MCUEV_HID_SHELL_OPEN = BIT(6),
MCUEV_HID_VOLUME_SLIDER = BIT(22),
};
u8 mcuGetVolumeSlider(void);
u32 mcuGetSpecialHID(void);
void mcuSetStatusLED(u32 period_ms, u32 color);
void mcuResetLEDs(void);
void mcuReset(void);
static inline u8 mcuReadReg(u8 addr)
{
u8 val;
I2C_readRegBuf(I2C_MCU_DEVICE, addr, &val, 1);
return val;
}
static inline bool mcuReadRegBuf(u8 addr, u8 *buf, u32 size)
{
return I2C_readRegBuf(I2C_MCU_DEVICE, addr, buf, size);
}
static inline bool mcuWriteReg(u8 addr, u8 val)
{
return I2C_writeRegBuf(I2C_MCU_DEVICE, addr, &val, 1);
}
static inline bool mcuWriteRegBuf(u8 addr, const u8 *buf, u32 size)
{
return I2C_writeRegBuf(I2C_MCU_DEVICE, addr, buf, size);
}
static inline void MCU_controlLCDPower(u8 bits)
{
mcuWriteReg(0x22u, bits);
}

93
arm11/source/hw/nvram.c Executable file
View File

@ -0,0 +1,93 @@
/*
* This file is part of GodMode9
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <types.h>
#include <spi.h>
#include "hw/nvram.h"
// returns manuf id, memory type and size
// size = (1 << id[2]) ?
// apparently unreliable on some Sanyo chips?
#define CMD_RDID 0x9F
#define CMD_READ 0x03
#define CMD_WREN 0x06
#define CMD_WRDI 0x04
#define CMD_RDSR 0x05
#define CMD_DPD 0xB9 // deep power down
#define CMD_RDP 0xAB // release from deep power down
static u32 NVRAM_SendStatusCommand(u32 cmd, u32 width)
{
u32 ret;
SPI_XferInfo xfer[2];
xfer[0].buf = &cmd;
xfer[0].len = 1;
xfer[0].read = false;
xfer[1].buf = &ret;
xfer[1].len = width;
xfer[1].read = true;
ret = 0;
SPI_DoXfer(SPI_DEV_NVRAM, xfer, 2, true);
return ret;
}
u32 NVRAM_Status(void)
{
return NVRAM_SendStatusCommand(CMD_RDSR, 1);
}
u32 NVRAM_ReadID(void)
{
return NVRAM_SendStatusCommand(CMD_RDID, 3);
}
void NVRAM_DeepStandby(void)
{
NVRAM_SendStatusCommand(CMD_DPD, 0);
}
void NVRAM_Wakeup(void)
{
NVRAM_SendStatusCommand(CMD_RDP, 0);
}
void NVRAM_Read(u32 address, u32 *buffer, u32 len)
{
SPI_XferInfo xfer[2];
u32 cmd;
address &= BIT(24) - 1;
cmd = __builtin_bswap32(address) | CMD_READ;
xfer[0].buf = &cmd;
xfer[0].len = 4;
xfer[0].read = false;
xfer[1].buf = buffer;
xfer[1].len = len;
xfer[1].read = true;
SPI_DoXfer(SPI_DEV_NVRAM, xfer, 2, true);
}

34
arm11/source/hw/nvram.h Executable file
View File

@ -0,0 +1,34 @@
/*
* This file is part of GodMode9
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <types.h>
#include <spi.h>
#define NVRAM_SR_WIP BIT(0) // work in progress / busy
#define NVRAM_SR_WEL BIT(1) // write enable latch
u32 NVRAM_Status(void);
u32 NVRAM_ReadID(void);
void NVRAM_Read(u32 offset, u32 *buffer, u32 len);
void NVRAM_DeepStandby(void);
void NVRAM_Wakeup(void);

229
arm11/source/main.c Normal file
View File

@ -0,0 +1,229 @@
/*
* This file is part of GodMode9
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <common.h>
#include <types.h>
#include <shmem.h>
#include <arm.h>
#include <pxi.h>
#include "arm/gic.h"
#include "hw/hid.h"
#include "hw/gpulcd.h"
#include "hw/i2c.h"
#include "hw/mcu.h"
#include "hw/nvram.h"
#include "system/sys.h"
#include "system/event.h"
static const u8 brightness_lvls[] = {
0x10, 0x17, 0x1E, 0x25,
0x2C, 0x34, 0x3C, 0x44,
0x4D, 0x56, 0x60, 0x6B,
0x79, 0x8C, 0xA7, 0xD2
};
#ifndef FIXED_BRIGHTNESS
static int prev_bright_lvl;
static bool auto_brightness;
#endif
static SystemSHMEM __attribute__((section(".shared"))) sharedMem;
static void vblankUpdate(void)
{
if (!getEventIRQ()->test(VBLANK_INTERRUPT, true))
return;
#ifndef FIXED_BRIGHTNESS
int cur_bright_lvl = (mcuGetVolumeSlider() >> 2) % countof(brightness_lvls);
if ((cur_bright_lvl != prev_bright_lvl) && auto_brightness) {
prev_bright_lvl = cur_bright_lvl;
u8 br = brightness_lvls[cur_bright_lvl];
GFX_setBrightness(br, br);
}
#endif
// handle shell events
static const u32 mcuEvShell = MCUEV_HID_SHELL_OPEN | MCUEV_HID_SHELL_CLOSE;
u32 shell = getEventMCU()->test(mcuEvShell, mcuEvShell);
if (shell & MCUEV_HID_SHELL_CLOSE) {
GFX_powerOffBacklights(GFX_BLIGHT_BOTH);
} else if (shell & MCUEV_HID_SHELL_OPEN) {
GFX_powerOnBacklights(GFX_BLIGHT_BOTH);
}
sharedMem.hidState.full = HID_GetState();
}
static u32 pxiRxUpdate(u32 *args)
{
u32 msg, lo, hi;
if (!getEventIRQ()->test(PXI_RX_INTERRUPT, true))
return PXICMD_NONE;
msg = PXI_Recv();
lo = msg & 0xFFFF;
hi = msg >> 16;
PXI_RecvArray(args, hi);
return lo;
}
void __attribute__((noreturn)) MainLoop(void)
{
bool runPxiCmdProcessor = true;
#ifdef FIXED_BRIGHTNESS
u8 fixed_bright_lvl = brightness_lvls[clamp(FIXED_BRIGHTNESS, 0, countof(brightness_lvls)-1)];
GFX_setBrightness(fixed_bright_lvl, fixed_bright_lvl);
#else
prev_bright_lvl = -1;
auto_brightness = true;
#endif
// initialize state stuff
getEventIRQ()->reset();
getEventMCU()->reset();
memset(&sharedMem, 0, sizeof(sharedMem));
// configure interrupts
gicSetInterruptConfig(PXI_RX_INTERRUPT, BIT(0), GIC_PRIO0, NULL);
gicSetInterruptConfig(VBLANK_INTERRUPT, BIT(0), GIC_PRIO0, NULL);
gicSetInterruptConfig(MCU_INTERRUPT, BIT(0), GIC_PRIO0, NULL);
// enable interrupts
gicEnableInterrupt(MCU_INTERRUPT);
// perform gpu init after initializing mcu but before
// enabling the pxi system and the vblank handler
GFX_init(GFX_RGB565);
gicEnableInterrupt(PXI_RX_INTERRUPT);
gicEnableInterrupt(VBLANK_INTERRUPT);
// ARM9 won't try anything funny until this point
PXI_Barrier(PXI_BOOT_BARRIER);
// Process commands until the ARM9 tells
// us it's time to boot something else
// also handles VBlank events as needed
do {
u32 pxiCmd, pxiReply, args[PXI_MAX_ARGS];
vblankUpdate();
pxiCmd = pxiRxUpdate(args);
switch(pxiCmd) {
// ignore args and just wait until the next event
case PXICMD_NONE:
ARM_WFI();
break;
// revert to legacy boot mode
case PXICMD_LEGACY_BOOT:
runPxiCmdProcessor = false;
pxiReply = 0;
break;
// returns the shared memory address
case PXICMD_GET_SHMEM_ADDRESS:
pxiReply = (u32)&sharedMem;
break;
// takes in a single argument word and performs either an
// I2C read or write depending on the value of the top bit
case PXICMD_I2C_OP:
{
u32 devId, regAddr, size;
devId = (args[0] & 0xff);
regAddr = (args[0] >> 8) & 0xFF;
size = (args[0] >> 16) % SHMEM_BUFFER_SIZE;
if (args[0] & BIT(31)) {
pxiReply = I2C_writeRegBuf(devId, regAddr, sharedMem.dataBuffer.b, size);
} else {
pxiReply = I2C_readRegBuf(devId, regAddr, sharedMem.dataBuffer.b, size);
}
break;
}
// checks whether the NVRAM chip is online (not doing any work)
case PXICMD_NVRAM_ONLINE:
pxiReply = (NVRAM_Status() & NVRAM_SR_WIP) == 0;
break;
// reads data from the NVRAM chip
case PXICMD_NVRAM_READ:
NVRAM_Read(args[0], sharedMem.dataBuffer.w, args[1]);
pxiReply = 0;
break;
// sets the notification LED with the given color and period
case PXICMD_SET_NOTIFY_LED:
mcuSetStatusLED(args[0], args[1]);
pxiReply = 0;
break;
// sets the LCDs brightness (if FIXED_BRIGHTNESS is disabled)
case PXICMD_SET_BRIGHTNESS:
{
pxiReply = GFX_getBrightness();
#ifndef FIXED_BRIGHTNESS
s32 newbrightness = (s32)args[0];
if ((newbrightness > 0) && (newbrightness < 0x100)) {
GFX_setBrightness(newbrightness, newbrightness);
auto_brightness = false;
} else {
prev_bright_lvl = -1;
auto_brightness = true;
}
#endif
break;
}
// replies -1 on default
default:
pxiReply = 0xFFFFFFFF;
break;
}
if (pxiCmd != PXICMD_NONE)
PXI_Send(pxiReply); // was a command sent from the ARM9, send a response
} while(runPxiCmdProcessor);
// perform deinit in reverse order
gicDisableInterrupt(VBLANK_INTERRUPT);
gicDisableInterrupt(PXI_RX_INTERRUPT);
// unconditionally reinitialize the screens
// in RGB24 framebuffer mode
GFX_init(GFX_BGR8);
gicDisableInterrupt(MCU_INTERRUPT);
// Wait for the ARM9 to do its firmlaunch setup
PXI_Barrier(PXI_FIRMLAUNCH_BARRIER);
SYS_CoreZeroShutdown();
SYS_CoreShutdown();
}

View File

@ -0,0 +1,26 @@
#pragma once
#include <types.h>
typedef struct {
void (*reset)(void);
u32 (*test)(u32 param, u32 clear);
} EventInterface;
const EventInterface *getEventIRQ(void);
const EventInterface *getEventMCU(void);
static inline void eventReset(const EventInterface *ei) {
ei->reset();
}
static inline u32 eventTest(const EventInterface *ei, u32 param, u32 clear) {
return ei->test(param, clear);
}
static inline u32 eventWait(const EventInterface *ei, u32 param, u32 clear) {
while(1) {
u32 ret = ei->test(param, clear);
if (ret) return ret;
}
}

35
arm11/source/system/sections.h Executable file
View File

@ -0,0 +1,35 @@
/*
* This file is part of GodMode9
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <types.h>
#define DEF_SECT_(n) extern u32 __##n##_pa, __##n##_va, __##n##_va_end;
DEF_SECT_(text)
DEF_SECT_(data)
DEF_SECT_(rodata)
DEF_SECT_(bss)
DEF_SECT_(shared)
#undef DEF_SECT_
#define SECTION_VA(n) ((u32)&__##n##_va)
#define SECTION_PA(n) ((u32)&__##n##_pa)
#define SECTION_LEN(n) (((u32)(&__##n##_va_end) - (u32)(&__##n##_va)))
#define SECTION_TRI(n) SECTION_VA(n), SECTION_PA(n), SECTION_LEN(n)

176
arm11/source/system/sys.c Executable file
View File

@ -0,0 +1,176 @@
/*
* This file is part of GodMode9
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <types.h>
#include <vram.h>
#include <arm.h>
#include <pxi.h>
#include "arm/gic.h"
#include "arm/mmu.h"
#include "arm/scu.h"
#include "arm/xrq.h"
#include "hw/codec.h"
#include "hw/gpulcd.h"
#include "hw/i2c.h"
#include "hw/mcu.h"
#include <spi.h>
#include "system/sections.h"
#define CFG11_MPCORE_CLKCNT ((vu16*)(0x10141300))
#define CFG11_SOCINFO ((vu16*)(0x10140FFC))
#define LEGACY_BOOT_ENTRYPOINT ((vu32*)0x1FFFFFFC)
#define LEGACY_BOOT_ROUTINE_SMP (0x0001004C)
static bool SYS_IsNewConsole(void)
{
return (*CFG11_SOCINFO & 2) != 0;
}
static bool SYS_ClkMultEnabled(void)
{
return (*CFG11_MPCORE_CLKCNT & 1) != 0;
}
static void SYS_EnableClkMult(void)
{
// magic bit twiddling to enable extra FCRAM
// only done on N3DS and when it hasn't been done yet
// state might get a bit messed up so it has to be done
// as early as possible in the initialization chain
if (SYS_IsNewConsole() && !SYS_ClkMultEnabled()) {
gicSetInterruptConfig(88, BIT(0), GIC_PRIO_HIGHEST, NULL);
gicEnableInterrupt(88);
*CFG11_MPCORE_CLKCNT = 0x8001;
do {
ARM_WFI();
} while(!(*CFG11_MPCORE_CLKCNT & 0x8000));
gicDisableInterrupt(88);
gicClearInterruptConfig(88);
}
}
void SYS_CoreZeroInit(void)
{
gicGlobalReset();
*LEGACY_BOOT_ENTRYPOINT = 0;
SYS_EnableClkMult();
SCU_Init();
// Map all sections here
mmuMapArea(SECTION_TRI(text), MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 0, 1));
mmuMapArea(SECTION_TRI(data), MMU_FLAGS(MMU_CACHE_WBA, MMU_READ_WRITE, 1, 1));
mmuMapArea(SECTION_TRI(rodata), MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 1, 1));
mmuMapArea(SECTION_TRI(bss), MMU_FLAGS(MMU_CACHE_WBA, MMU_READ_WRITE, 1, 1));
mmuMapArea(SECTION_TRI(shared), MMU_FLAGS(MMU_STRONG_ORDER, MMU_READ_WRITE, 1, 1));
// High exception vectors
mmuMapArea(0xFFFF0000, xrqInstallVectorTable(), 4UL << 10, MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 0, 0));
// BootROM
mmuMapArea(0x00010000, 0x00010000, 32UL << 10, MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 0, 1));
// IO Registers
mmuMapArea(0x10100000, 0x10100000, 4UL << 20, MMU_FLAGS(MMU_DEV_SHARED, MMU_READ_WRITE, 1, 1));
// MPCore Private Memory Region
mmuMapArea(0x17E00000, 0x17E00000, 8UL << 10, MMU_FLAGS(MMU_DEV_SHARED, MMU_READ_WRITE, 1, 1));
// VRAM
mmuMapArea(0x18000000, 0x18000000, 6UL << 20, MMU_FLAGS(MMU_CACHE_WT, MMU_READ_WRITE, 1, 1));
// FCRAM
if (SYS_IsNewConsole()) {
mmuMapArea(0x20000000, 0x20000000, 256UL << 20, MMU_FLAGS(MMU_CACHE_WB, MMU_READ_WRITE, 1, 1));
} else {
mmuMapArea(0x20000000, 0x20000000, 128UL << 20, MMU_FLAGS(MMU_CACHE_WB, MMU_READ_WRITE, 1, 1));
}
// screen init magicks
TIMER_WaitMS(64);
// Initialize peripherals
PXI_Reset();
I2C_init();
mcuReset();
SPI_Init();
CODEC_Init();
}
void SYS_CoreInit(void)
{
// Reset local GIC registers
gicLocalReset();
// Set up MMU registers
mmuInitRegisters();
// Enable fancy ARM11 features
ARM_SetACR(ARM_GetACR() |
ACR_RETSTK | ACR_DBPRED | ACR_SBPRED | ACR_FOLDING | ACR_SMP);
ARM_SetCR(ARM_GetCR() |
CR_MMU | CR_CACHES | CR_FLOWPRED | CR_HIGHVEC | CR_DSUBPAGE);
ARM_DSB();
ARM_EnableInterrupts();
}
void SYS_CoreZeroShutdown(void)
{
ARM_DisableInterrupts();
gicGlobalReset();
}
void __attribute__((noreturn)) SYS_CoreShutdown(void)
{
u32 core = ARM_CoreID();
ARM_DisableInterrupts();
gicLocalReset();
ARM_WbInvDC();
ARM_InvIC();
ARM_DSB();
ARM_SetCR(ARM_GetCR() & ~(CR_MMU | CR_CACHES | CR_FLOWPRED));
ARM_SetACR(ARM_GetACR() &
~(ACR_RETSTK | ACR_DBPRED | ACR_SBPRED | ACR_FOLDING | ACR_SMP));
SPI_Deinit();
if (!core) {
while(*LEGACY_BOOT_ENTRYPOINT == 0);
((void (*)(void))(*LEGACY_BOOT_ENTRYPOINT))();
} else {
// Branch to bootrom function that does SMP reinit magic
// (waits for IPI + branches to word @ 0x1FFFFFDC)
((void (*)(void))LEGACY_BOOT_ROUTINE_SMP)();
}
__builtin_unreachable();
}

38
arm11/source/system/sys.h Executable file
View File

@ -0,0 +1,38 @@
/*
* This file is part of GodMode9
* Copyright (C) 2019 Wolfvak
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <types.h>
/*
how to run the SYS_Core(Zero){Init,Shutdown} functions:
for init:
- FIRST run CoreZeroInit ONCE
- all cores must run CoreInit ONCE
for shutdown:
- all non-zero cores must call CoreShutdown
- core zero must call CoreZeroShutdown, then CoreShutdown
*/
void SYS_CoreZeroInit(void);
void SYS_CoreInit(void);
void SYS_CoreZeroShutdown(void);
void __attribute__((noreturn)) SYS_CoreShutdown(void);

24
arm9/Makefile Normal file
View File

@ -0,0 +1,24 @@
PROCESSOR := ARM9
TARGET := $(shell basename "$(CURDIR)")
SOURCE := source
BUILD := build
SUBARCH := -D$(PROCESSOR) -march=armv5te -mtune=arm946e-s -mthumb -mfloat-abi=soft
INCDIRS := source source/common source/filesys source/crypto source/fatfs source/nand source/virtual source/game source/gamecart source/lodepng source/lua source/qrcodegen source/system source/utils
INCLUDE := $(foreach dir,$(INCDIRS),-I"$(shell pwd)/$(dir)")
ASFLAGS += $(SUBARCH) $(INCLUDE)
CFLAGS += $(SUBARCH) $(INCLUDE) -fno-builtin-memcpy -flto
LDFLAGS += $(SUBARCH) -Wl,--use-blx,-Map,$(TARGET).map -flto
LIBS += -lm
include ../Makefile.common
include ../Makefile.build
arm9_data.elf: arm9.elf
$(OBJCOPY) -O elf32-littlearm -j .rodata* -j .data* -j .bss* $< $@
arm9_code.elf: arm9.elf
$(OBJCOPY) -O elf32-littlearm -j .text* -j .vectors* $< $@

53
arm9/link.ld Normal file
View File

@ -0,0 +1,53 @@
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)
MEMORY
{
VECTORS (RX) : ORIGIN = 0x08000000, LENGTH = 64
CODEMEM (RX) : ORIGIN = 0x08000040, LENGTH = 512K - 64
BOOTROM (R) : ORIGIN = 0x08080000, LENGTH = 128K /* BootROM mirrors, don't touch! */
DATAMEM (RW) : ORIGIN = 0x080A0000, LENGTH = 384K
}
SECTIONS
{
.vectors : ALIGN(4) {
__vectors_lma = LOADADDR(.vectors);
__vectors_vma = ABSOLUTE(.);
KEEP(*(.vectors));
. = ALIGN(4);
__vectors_len = ABSOLUTE(.) - __vectors_vma;
} >VECTORS AT>CODEMEM
.text : ALIGN(4) {
__text_s = ABSOLUTE(.);
*(.text.start);
*(.text*);
. = ALIGN(4);
__text_e = ABSOLUTE(.);
} >CODEMEM
.rodata : ALIGN(4) {
*(.rodata*);
. = ALIGN(4);
__exidx_start = .;
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
__exidx_end = .;
. = ALIGN(4);
} >DATAMEM
.data : ALIGN(4) {
*(.data*);
. = ALIGN(4);
} >DATAMEM
.bss (NOLOAD) : ALIGN(4) {
__bss_start = .;
*(.bss*);
. = ALIGN(4);
__bss_end = .;
} >DATAMEM
__end__ = ABSOLUTE(.);
}

View File

@ -0,0 +1,32 @@
#pragma once
/*
* This file is part of fastboot 3DS
* Copyright (C) 2017 derrek, profi200
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if !__ASSEMBLER__
#error Only include this in assembly files!
#endif
.macro ASM_FUNC name
.section .text.\name, "ax", %progbits
.global \name
.type \name %function
.align 2
\name:
.endm

View File

@ -0,0 +1,69 @@
#pragma once
#define RGB(r,g,b) \
(((u32)(r) >> 3) << 11 | \
((u32)(g) >> 2) << 5 | \
((u32)(b) >> 3))
// a base set of colors below
#define COLOR_BLACK RGB(0x00, 0x00, 0x00)
#define COLOR_WHITE RGB(0xFF, 0xFF, 0xFF)
#define COLOR_GREY RGB(0x80, 0x80, 0x80)
#define COLOR_RED RGB(0xFF, 0x00, 0x00)
#define COLOR_GREEN RGB(0x00, 0xFF, 0x00)
#define COLOR_BLUE RGB(0x00, 0x00, 0xFF)
#define COLOR_YELLOW RGB(0xFF, 0xFF, 0x00)
#define COLOR_CYAN RGB(0xFF, 0x00, 0xFF)
#define COLOR_ORANGE RGB(0xFF, 0xA5, 0x00)
#define COLOR_BRIGHTRED RGB(0xFF, 0x30, 0x30)
#define COLOR_DARKRED RGB(0x80, 0x00, 0x00)
#define COLOR_BRIGHTYELLOW RGB(0xFF, 0xFF, 0x30)
#define COLOR_BRIGHTGREEN RGB(0x30, 0xFF, 0x30)
#define COLOR_BRIGHTBLUE RGB(0x30, 0x30, 0xFF)
#define COLOR_TINTEDBLUE RGB(0x60, 0x60, 0x80)
#define COLOR_TINTEDYELLOW RGB(0xD0, 0xD0, 0x60)
#define COLOR_TINTEDGREEN RGB(0x70, 0x80, 0x70)
#define COLOR_LIGHTGREY RGB(0xB0, 0xB0, 0xB0)
#define COLOR_LIGHTERGREY RGB(0xD0, 0xD0, 0xD0)
#define COLOR_DARKGREY RGB(0x50, 0x50, 0x50)
#define COLOR_DARKESTGREY RGB(0x20, 0x20, 0x20)
#define COLOR_SUPERFUCHSIA RGB(0xFF, 0x00, 0xEF)
// standard colors - used everywhere
#ifndef COLOR_STD_BG
#define COLOR_STD_BG COLOR_BLACK
#endif
#ifndef COLOR_STD_FONT
#define COLOR_STD_FONT COLOR_WHITE
#endif
// colors for GodMode9 file browser
#define COLOR_SIDE_BAR COLOR_DARKGREY
#define COLOR_MARKED COLOR_TINTEDYELLOW
#define COLOR_FILE COLOR_TINTEDGREEN
#define COLOR_DIR COLOR_TINTEDBLUE
#define COLOR_ROOT COLOR_GREY
#define COLOR_ENTRY(e) (((e)->marked) ? COLOR_MARKED : ((e)->type == T_DIR) ? COLOR_DIR : ((e)->type == T_FILE) ? COLOR_FILE : ((e)->type == T_ROOT) ? COLOR_ROOT : COLOR_GREY)
// hex viewer colors
#define COLOR_HVOFFS RGB(0x40, 0x60, 0x50)
#define COLOR_HVOFFSI COLOR_DARKESTGREY
#define COLOR_HVASCII RGB(0x40, 0x80, 0x50)
#define COLOR_HVHEX(i) ((i % 2) ? RGB(0x30, 0x90, 0x30) : RGB(0x30, 0x80, 0x30))
// text viewer / script viewer colors
#define COLOR_TVOFFS RGB(0x40, 0x40, 0x40)
#define COLOR_TVOFFSL RGB(0x30, 0x30, 0x30)
#define COLOR_TVTEXT RGB(0xA0, 0xA0, 0xA0)
#define COLOR_TVRUN RGB(0xC0, 0x00, 0x00)
#define COLOR_TVCMT RGB(0x60, 0x60, 0x70)
#define COLOR_TVCMD RGB(0xA0, 0xA0, 0xA0)
// battery symbol colors
#define COLOR_BATTERY_CHARGING RGB(0x3D, 0xB7, 0xE4)
#define COLOR_BATTERY_FULL RGB(0x0F, 0xB0, 0x1B)
#define COLOR_BATTERY_MEDIUM RGB(0xFF, 0x88, 0x49)
#define COLOR_BATTERY_LOW RGB(0xB4, 0x00, 0x00)

213
arm9/source/common/hid.c Normal file
View File

@ -0,0 +1,213 @@
#include "hid.h"
#include "i2c.h"
#include "timer.h"
#include "colors.h"
#include "screenshot.h" // for screenshots
#include "arm.h"
#include "fixp.h"
#include "shmem.h"
#define HID_TOUCH_MAXPOINT (0x1000)
#define HID_TOUCH_MIDPOINT (HID_TOUCH_MAXPOINT / 2)
static void SetNotificationLED(u32 period_ms, u32 rgb565_color)
{
u32 rgb888_color =
((rgb565_color >> 11) << (16+3) |
(rgb565_color >> 5) << (8+2) |
(rgb565_color << 3));
u32 args[] = {period_ms, rgb888_color};
PXI_DoCMD(PXICMD_SET_NOTIFY_LED, args, 2);
}
// there's some weird thing going on when reading this
// with an LDRD instruction so for now they'll be two
// separate things - hopefully LTO won't get in the way
u32 HID_ReadState(void)
{
return ARM_GetSHMEM()->hidState.keys;
}
u32 HID_ReadRawTouchState(void)
{
return ARM_GetSHMEM()->hidState.touch;
}
// ts_mult indicates a scalar for each axis
// if |ts_mult| > 1 => point must be "scaled out"
// if |ts_mult| < 1 => point must be "scaled in"
// if ts_mult < 0 => axis is inverted
static fixp_t ts_mult[2];
// ts_org indicates the coordinate system origin
static int ts_org[2];
bool HID_TouchCalibratedTransform(u32 ts, u16 *x, u16 *y)
{
int xc, yc;
int tx, ty;
if (ts & BIT(31))
return false;
tx = HID_RAW_TX(ts) - HID_TOUCH_MIDPOINT;
ty = HID_RAW_TY(ts) - HID_TOUCH_MIDPOINT;
xc = FIXP_TO_INT(fixp_round(tx * ts_mult[0])) + ts_org[0];
yc = FIXP_TO_INT(fixp_round(ty * ts_mult[1])) + ts_org[1];
*x = clamp(xc, 0, (ts_org[0] * 2) - 1);
*y = clamp(yc, 0, (ts_org[1] * 2) - 1);
return true;
}
bool HID_ReadTouchState(u16 *x, u16 *y)
{
return HID_TouchCalibratedTransform(HID_ReadRawTouchState(), x, y);
}
bool HID_SetCalibrationData(const HID_CalibrationData *calibs, u32 point_cnt, u32 screen_w, u32 screen_h)
{
u32 mid_x, mid_y;
fixp_t avg_x, avg_y;
if (!screen_w || !screen_h || point_cnt <= 0 || point_cnt > 7)
return false;
mid_x = screen_w / 2;
mid_y = screen_h / 2;
avg_x = 0;
avg_y = 0;
for (u32 i = 0; i < point_cnt; i++) {
const HID_CalibrationData *data = &calibs[i];
fixp_t screen_x, screen_y, touch_x, touch_y;
// translate the [0, screen_w] x [0, screen_h] system
// to [-screen_w/2, screen_w/2] x [-screen_h/2, screen_h/2]
screen_x = INT_TO_FIXP(data->screen_x - mid_x);
screen_y = INT_TO_FIXP(data->screen_y - mid_y);
// same thing for raw touchscreen data
touch_x = INT_TO_FIXP(HID_RAW_TX(data->ts_raw) - HID_TOUCH_MIDPOINT);
touch_y = INT_TO_FIXP(HID_RAW_TY(data->ts_raw) - HID_TOUCH_MIDPOINT);
// if the data retrieved came right in the middle, it's invalid
if (!screen_x || !screen_y || !touch_x || !touch_y)
return false;
// prevent integer overflows by dividing in this step
avg_x += fixp_quotient(screen_x, touch_x * point_cnt);
avg_y += fixp_quotient(screen_y, touch_y * point_cnt);
}
// set state variables
ts_mult[0] = avg_x;
ts_mult[1] = avg_y;
ts_org[0] = mid_x;
ts_org[1] = mid_y;
return true;
}
const TouchBox* TouchBoxGet(u32* id, const u16 x, const u16 y, const TouchBox* tbs, const u32 tbn) {
// check if inside touchbox
for (u32 i = 0; !tbn || (i < tbn); i++) {
const TouchBox* tb = tbs + i;
if (tb->id == 0) break;
if ((x >= tb->x) && (y >= tb->y) &&
(x < tb->x + tb->w) && (y < tb->y + tb->h)) {
if (id) *id = tb->id;
return tb; // we know const is discarded here
}
}
if (id) *id = 0;
return NULL;
}
u32 InputWait(u32 timeout_sec) {
static u64 delay = 0;
u64 timer = timer_start();
u32 oldpad = HID_ReadState();
u32 oldcart = CART_STATE;
u32 oldsd = SD_STATE;
// enable notification LED if shell is closed
// (this means we're waiting for user input)
if (oldpad & SHELL_CLOSED) {
SetNotificationLED(1000, COLOR_GREEN);
while (HID_ReadState() & SHELL_CLOSED);
}
delay = delay ? 144 : 256;
do {
u32 newpad = HID_ReadState();
// handle closed shell (wait for open)
if (newpad & SHELL_CLOSED) {
while (HID_ReadState() & SHELL_CLOSED);
continue;
}
// no buttons pressed, check for I/O changes instead
if (!(newpad & ~(SHELL_OPEN|SHELL_CLOSED))) {
u32 state = CART_STATE;
if (state != oldcart)
return state ? CART_INSERT : CART_EJECT;
state = SD_STATE;
if (state != oldsd)
return state ? SD_INSERT : SD_EJECT;
oldpad = 0;
delay = 0;
continue;
}
// special case for dpad keys
// if any of those are held, don't wait for key changes
// but do insert a small latency to make
// sure any menus don't go flying off
if ((newpad == oldpad) &&
(!(newpad & BUTTON_ARROW) ||
(delay && (timer_msec(timer) < delay))))
continue;
// screenshot handling
if ((newpad & BUTTON_ANY) == (BUTTON_R1 | BUTTON_L1))
CreateScreenshot();
return newpad;
} while (!timeout_sec || (timeout_sec && (timer_sec(timer) < timeout_sec)));
return TIMEOUT_HID;
}
bool CheckButton(u32 button) {
return (HID_ReadState() & button) == button;
}
void ButtonToString(u32 button, char* str) {
const char* strings[] = { BUTTON_STRINGS };
*str = '\0';
if (button) {
u32 b = 0;
for (b = 0; !((button>>b)&0x1); b++);
if (b < countof(strings)) strcpy(str, strings[b]);
}
}
u32 StringToButton(char* str) {
const char* strings[] = { BUTTON_STRINGS };
u32 b = 0;
for (b = 0; b < countof(strings); b++)
if (strcmp(str, strings[b]) == 0) break;
return (b == countof(strings)) ? 0 : 1<<b;
}

45
arm9/source/common/hid.h Normal file
View File

@ -0,0 +1,45 @@
#pragma once
#include "common.h"
#include "hid_map.h"
// see: http://3dbrew.org/wiki/CONFIG9_Registers
// see: http://3dbrew.org/wiki/EMMC_Registers
#define CART_STATE (~(*(volatile u8*)0x10000010) & 0x1)
#define SD_STATE ((*(volatile u16*)0x1000601C) & (0x1<<5))
#define HID_RAW_TX(t) ((s32)(((t) / (1 << 16)) & 0xFFF))
#define HID_RAW_TY(t) ((s32)((t) & 0xFFF))
u32 HID_ReadState(void);
// ts_raw is the raw touchscreen value obtained when pressing down
// the touchscreen at the screen coordinates [screen_x, screen_y]
// note: no point can be at the center
typedef struct {
u32 ts_raw;
int screen_x, screen_y;
} HID_CalibrationData;
u32 HID_ReadRawTouchState(void);
bool HID_ReadTouchState(u16 *x, u16 *y);
bool HID_TouchCalibratedTransform(u32 ts, u16 *x, u16 *y);
bool HID_SetCalibrationData(const HID_CalibrationData *calibs, u32 point_cnt, u32 screen_w, u32 screen_h);
typedef struct {
u16 x;
u16 y;
u16 w;
u16 h;
u32 id; // shouldn't be zero
} TouchBox;
// abstraction for HID_ReadTouchState, also returns touchbox id (if any)
const TouchBox* TouchBoxGet(u32* id, const u16 x, const u16 y, const TouchBox* tbs, const u32 tbn);
u32 InputWait(u32 timeout_sec);
bool CheckButton(u32 button);
void ButtonToString(u32 button, char* str);
u32 StringToButton(char* str);

View File

@ -0,0 +1,70 @@
@ memcpy_arm946e-s - hand written reimplementation of memcpy to be sequential
@ Written in 2019 by luigoalma <luigoalma at gmail dot com>
@ To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
@ For a copy of CC0 Public Domain Dedication, see <https://creativecommons.org/publicdomain/zero/1.0/>.
.cpu arm946e-s
.arch armv5te
.arm
.section .text.memcpy, "ax", %progbits
.align 2
.global memcpy
.syntax unified
.type memcpy, %function
memcpy:
@ r0 = dest
@ r1 = src
@ r2 = length
@ check if length 0 and return if so
cmp r2, #0
bxeq lr
push {r0,r4-r9,lr}
@ pre-fetch data
pld [r1]
@ alignment check with word size
@ if not aligned but both are in the same misalignment, fix it up
@ otherwise jump to basic loop
orr r12, r0, r1
ands r12, r12, #3
beq .L1
mov r12, r0, LSL#30
cmp r12, r1, LSL#30
bne .L6
.L0:
ldrb r3, [r1], #1
strb r3, [r0], #1
subs r2, r2, #1
popeq {r0,r4-r9,pc}
adds r12, r12, #0x40000000
bne .L0
.L1:
@ check if length higher than 32
@ if so, do the 32 byte block copy loop,
@ until there's nothing left or remainder to copy is less than 32
movs r3, r2, LSR#5
beq .L3
.L2:
ldm r1!, {r4-r9,r12,lr}
stm r0!, {r4-r9,r12,lr}
subs r3, r3, #1
bne .L2
ands r2, r2, #0x1F
popeq {r0,r4-r9,pc}
.L3:
@ copy in word size the remaining data,
@ and finish off with basic loop if can't copy all by word size.
movs r3, r2, LSR#2
beq .L6
.L4:
ldr r12, [r1], #4
str r12, [r0], #4
subs r3, r3, #1
bne .L4
ands r2, r2, #0x3
.L5: @ the basic loop
popeq {r0,r4-r9,pc}
.L6:
ldrb r3, [r1], #1
strb r3, [r0], #1
subs r2, r2, #1
b .L5
.size memcpy, .-memcpy

26
arm9/source/common/mmio.h Normal file
View File

@ -0,0 +1,26 @@
/*
* This file is part of fastboot 3DS
* Copyright (C) 2019 Aurora Wright, TuxSH, derrek, profi200
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Based on https://github.com/AuroraWright/Luma3DS/blob/master/arm9/source/alignedseqmemcpy.s
#include "common.h"
void iomemcpy(vu32 *restrict dst, const vu32 *restrict src, u32 size);
void iomemset(vu32 *ptr, u32 value, u32 size);

87
arm9/source/common/mmio.s Normal file
View File

@ -0,0 +1,87 @@
/*
* This file is part of fastboot 3DS
* Copyright (C) 2019 Aurora Wright, TuxSH, derrek, profi200
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ Based on https://github.com/AuroraWright/Luma3DS/blob/master/arm9/source/alignedseqmemcpy.s
#include "asmfunc.h"
.arm
.cpu arm946e-s
.fpu softvfp
@ void iomemcpy(vu32 *restrict dst, const vu32 *restrict src, u32 size)
ASM_FUNC iomemcpy
bics r12, r2, #31
beq iomemcpy_test_words
stmfd sp!, {r4-r10}
iomemcpy_blocks_lp:
ldmia r1!, {r3-r10}
stmia r0!, {r3-r10}
subs r12, #32
bne iomemcpy_blocks_lp
ldmfd sp!, {r4-r10}
iomemcpy_test_words:
ands r12, r2, #28
beq iomemcpy_halfword_byte
iomemcpy_words_lp:
ldr r3, [r1], #4
str r3, [r0], #4
subs r12, #4
bne iomemcpy_words_lp
iomemcpy_halfword_byte:
tst r2, #2
ldrneh r3, [r1], #2
strneh r3, [r0], #2
tst r2, #1
ldrneb r3, [r1]
strneb r3, [r0]
bx lr
@ void iomemset(vu32 *ptr, u32 value, u32 size)
ASM_FUNC iomemset
bics r12, r2, #31
beq iomemset_test_words
stmfd sp!, {r4-r9}
mov r3, r1
mov r4, r1
mov r5, r1
mov r6, r1
mov r7, r1
mov r8, r1
mov r9, r1
iomemset_blocks_lp:
stmia r0!, {r1, r3-r9}
subs r12, #32
bne iomemset_blocks_lp
ldmfd sp!, {r4-r9}
iomemset_test_words:
ands r12, r2, #28
beq iomemset_halfword_byte
iomemset_words_lp:
str r1, [r0], #4
subs r12, #4
bne iomemset_words_lp
iomemset_halfword_byte:
tst r2, #2
strneh r1, [r0], #2
tst r2, #1
strneb r1, [r0]
bx lr

View File

@ -0,0 +1,45 @@
#include "arm.h"
#include "power.h"
#include "i2c.h"
#include "pxi.h"
u32 SetScreenBrightness(int level) {
u32 arg;
if (level != BRIGHTNESS_AUTOMATIC) {
arg = clamp(level, BRIGHTNESS_MIN, BRIGHTNESS_MAX);
} else {
arg = 0;
}
return PXI_DoCMD(PXICMD_SET_BRIGHTNESS, &arg, 1);
}
u32 GetBatteryPercent() {
u8 battery = 0;
I2C_readRegBuf(I2C_DEV_MCU, 0x0B, &battery, 1);
return battery;
}
bool IsCharging() {
u8 flags = 0;
I2C_readRegBuf(I2C_DEV_MCU, 0x0F, &flags, 1);
return flags & (1<<4);
}
void Reboot() {
I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0); // poweroff LCD to prevent MCU hangs
ARM_WbDC();
ARM_DSB();
I2C_writeReg(I2C_DEV_MCU, 0x20, 1 << 2);
while(true);
}
void PowerOff()
{
I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0); // poweroff LCD to prevent MCU hangs
ARM_WbDC();
ARM_DSB();
I2C_writeReg(I2C_DEV_MCU, 0x20, 1 << 0);
while(true);
}

View File

@ -0,0 +1,13 @@
#pragma once
#include "common.h"
#define BRIGHTNESS_AUTOMATIC (-1)
#define BRIGHTNESS_MIN (10)
#define BRIGHTNESS_MAX (210)
u32 SetScreenBrightness(int level);
u32 GetBatteryPercent();
bool IsCharging();
void Reboot();
void PowerOff();

42
arm9/source/common/rtc.c Normal file
View File

@ -0,0 +1,42 @@
#include "rtc.h"
#include "i2c.h"
bool is_valid_dstime(DsTime* dstime) {
// check the time...
if ((DSTIMEGET(dstime, bcd_h) >= 24) ||
(DSTIMEGET(dstime, bcd_m) >= 60) ||
(DSTIMEGET(dstime, bcd_s) >= 60))
return false;
// check the date...
u32 year = 2000 + DSTIMEGET(dstime, bcd_Y);
u32 month = DSTIMEGET(dstime, bcd_M);
u32 day = DSTIMEGET(dstime, bcd_D);
// date: year & month
if ((year >= 2100) || (month == 0) || (month > 12))
return false;
// date: day
// see: https://github.com/devkitPro/libnds/blob/9678bf09389cb1fcdc99dfa0357ec0cbe51dd0b7/source/arm7/clock.c#L224-L262
u32 months_lastday[1+12] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
u32 leap = (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
u32 days_in_month = months_lastday[month] + ((month == 2) ? leap : 0);
if (day > days_in_month) return false;
return true;
}
bool get_dstime(DsTime* dstime) {
return (I2C_readRegBuf(I2C_DEV_MCU, 0x30, (void*) dstime, sizeof(DsTime)));
}
bool set_dstime(DsTime* dstime) {
if (!is_valid_dstime(dstime)) return false;
for (u32 i = 0; i < sizeof(DsTime); i++) {
if ((i == 3) || (i == 7)) continue; // skip the unused bytes
if (!I2C_writeReg(I2C_DEV_MCU, 0x30+i, ((u8*)dstime)[i]))
return false;
}
return true;
}

24
arm9/source/common/rtc.h Normal file
View File

@ -0,0 +1,24 @@
#pragma once
#include "common.h"
#define BCDVALID(b) (((b)<=0x99)&&(((b)&0xF)<=0x9)&&((((b)>>4)&0xF)<=0x9))
#define BCD2NUM(b) (BCDVALID(b) ? (((b)&0xF)+((((b)>>4)&0xF)*10)) : 0xFF)
#define NUM2BCD(n) ((n<99) ? (((n/10)*0x10)|(n%10)) : 0x99)
#define DSTIMEGET(bcd,n) (BCD2NUM((bcd)->n))
// see: http://3dbrew.org/wiki/I2C_Registers#Device_3 (register 30)
typedef struct {
u8 bcd_s;
u8 bcd_m;
u8 bcd_h;
u8 weekday;
u8 bcd_D;
u8 bcd_M;
u8 bcd_Y;
u8 leap_count;
} PACKED_STRUCT DsTime;
bool is_valid_dstime(DsTime* dstime);
bool get_dstime(DsTime* dstime);
bool set_dstime(DsTime* dstime);

View File

@ -0,0 +1,66 @@
#include "common.h"
#include "ui.h"
#include "rtc.h"
#include "vff.h"
#include "png.h"
static void Screenshot_Transpose(u16 *dest, const u16 *fb, u32 w, u32 stride)
{
for (u32 y = 0; y < SCREEN_HEIGHT; y++) {
for (u32 x = 0; x < w; x++)
*(dest++) = GetColor(fb, x, y);
dest += stride;
}
}
void CreateScreenshot(void) {
u8 *png;
u16 *buffer;
DsTime dstime;
size_t png_size;
char filename[64];
u32 snapbuf_size, snap_w, snap_h, bot_offset;
snapbuf_size = (SCREEN_WIDTH_TOP * SCREEN_HEIGHT * BYTES_PER_PIXEL) * 2;
snap_w = SCREEN_WIDTH_TOP;
snap_h = SCREEN_HEIGHT * 2;
fvx_rmkdir(OUTPUT_PATH);
get_dstime(&dstime);
snprintf(filename, sizeof(filename), OUTPUT_PATH "/snap_%02X%02X%02X%02X%02X%02X.png",
dstime.bcd_Y, dstime.bcd_M, dstime.bcd_D,
dstime.bcd_h, dstime.bcd_m, dstime.bcd_s);
filename[63] = '\0';
buffer = malloc(snapbuf_size);
if (!buffer) return;
for (unsigned i = snapbuf_size/4; i < snapbuf_size/2; i++)
buffer[i] = RGB(0x1F, 0x1F, 0x1F); // gray background
bot_offset = (SCREEN_WIDTH_TOP * SCREEN_HEIGHT) + 40;
Screenshot_Transpose(buffer, TOP_SCREEN, SCREEN_WIDTH_TOP, 0);
Screenshot_Transpose(buffer + bot_offset, BOT_SCREEN, SCREEN_WIDTH_BOT, 80);
png = PNG_Compress(buffer, snap_w, snap_h, &png_size);
if (png && png_size) {
u16 *buffer_top = buffer, *buffer_bottom = buffer + bot_offset;
// "snap effect"
memcpy(buffer_bottom, BOT_SCREEN, SCREEN_SIZE_BOT);
memcpy(buffer_top, TOP_SCREEN, SCREEN_SIZE_TOP);
memset(BOT_SCREEN, 0, SCREEN_SIZE_BOT);
memset(TOP_SCREEN, 0, SCREEN_SIZE_TOP);
fvx_qwrite(filename, png, 0, png_size, NULL);
memcpy(BOT_SCREEN, buffer_bottom, SCREEN_SIZE_BOT);
memcpy(TOP_SCREEN, buffer_top, SCREEN_SIZE_TOP);
}
// what to do on error...?
free(buffer);
free(png);
}

View File

@ -0,0 +1,3 @@
#pragma once
void CreateScreenshot(void);

105
arm9/source/common/sighax.c Normal file
View File

@ -0,0 +1,105 @@
#include "common.h"
// see https://gist.github.com/SciresM/cdd2266efb80175d37eabbe86f9d8c52 for source
// thanks SciresM, Myria, Normmatt, TuxSH and hedgeberg for the signatures!
const u8 sig_nand_firm_retail[256] = {
0xB6, 0x72, 0x45, 0x31, 0xC4, 0x48, 0x65, 0x7A, 0x2A, 0x2E, 0xE3, 0x06, 0x45, 0x7E, 0x35, 0x0A,
0x10, 0xD5, 0x44, 0xB4, 0x28, 0x59, 0xB0, 0xE5, 0xB0, 0xBE, 0xD2, 0x75, 0x34, 0xCC, 0xCC, 0x2A,
0x4D, 0x47, 0xED, 0xEA, 0x60, 0xA7, 0xDD, 0x99, 0x93, 0x99, 0x50, 0xA6, 0x35, 0x7B, 0x1E, 0x35,
0xDF, 0xC7, 0xFA, 0xC7, 0x73, 0xB7, 0xE1, 0x2E, 0x7C, 0x14, 0x81, 0x23, 0x4A, 0xF1, 0x41, 0xB3,
0x1C, 0xF0, 0x8E, 0x9F, 0x62, 0x29, 0x3A, 0xA6, 0xBA, 0xAE, 0x24, 0x6C, 0x15, 0x09, 0x5F, 0x8B,
0x78, 0x40, 0x2A, 0x68, 0x4D, 0x85, 0x2C, 0x68, 0x05, 0x49, 0xFA, 0x5B, 0x3F, 0x14, 0xD9, 0xE8,
0x38, 0xA2, 0xFB, 0x9C, 0x09, 0xA1, 0x5A, 0xBB, 0x40, 0xDC, 0xA2, 0x5E, 0x40, 0xA3, 0xDD, 0xC1,
0xF5, 0x8E, 0x79, 0xCE, 0xC9, 0x01, 0x97, 0x43, 0x63, 0xA9, 0x46, 0xE9, 0x9B, 0x43, 0x46, 0xE8,
0xA3, 0x72, 0xB6, 0xCD, 0x55, 0xA7, 0x07, 0xE1, 0xEA, 0xB9, 0xBE, 0xC0, 0x20, 0x0B, 0x5B, 0xA0,
0xB6, 0x61, 0x23, 0x6A, 0x87, 0x08, 0xD7, 0x04, 0x51, 0x7F, 0x43, 0xC6, 0xC3, 0x8E, 0xE9, 0x56,
0x01, 0x11, 0xE1, 0x40, 0x5E, 0x5E, 0x8E, 0xD3, 0x56, 0xC4, 0x9C, 0x4F, 0xF6, 0x82, 0x3D, 0x12,
0x19, 0xAF, 0xAE, 0xEB, 0x3D, 0xF3, 0xC3, 0x6B, 0x62, 0xBB, 0xA8, 0x8F, 0xC1, 0x5B, 0xA8, 0x64,
0x8F, 0x93, 0x33, 0xFD, 0x9F, 0xC0, 0x92, 0xB8, 0x14, 0x6C, 0x3D, 0x90, 0x8F, 0x73, 0x15, 0x5D,
0x48, 0xBE, 0x89, 0xD7, 0x26, 0x12, 0xE1, 0x8E, 0x4A, 0xA8, 0xEB, 0x9B, 0x7F, 0xD2, 0xA5, 0xF7,
0x32, 0x8C, 0x4E, 0xCB, 0xFB, 0x00, 0x83, 0x83, 0x3C, 0xBD, 0x5C, 0x98, 0x3A, 0x25, 0xCE, 0xB8,
0xB9, 0x41, 0xCC, 0x68, 0xEB, 0x01, 0x7C, 0xE8, 0x7F, 0x5D, 0x79, 0x3A, 0xCA, 0x09, 0xAC, 0xF7
};
const u8 sig_nand_firm_dev[256] = {
0x88, 0x69, 0x7C, 0xDC, 0xA9, 0xD1, 0xEA, 0x31, 0x82, 0x56, 0xFC, 0xD9, 0xCE, 0xD4, 0x29, 0x64,
0xC1, 0xE9, 0x8A, 0xBC, 0x64, 0x86, 0xB2, 0xF1, 0x28, 0xEC, 0x02, 0xE7, 0x1C, 0x5A, 0xE3, 0x5D,
0x63, 0xD3, 0xBF, 0x12, 0x46, 0x13, 0x40, 0x81, 0xAF, 0x68, 0x75, 0x47, 0x87, 0xFC, 0xB9, 0x22,
0x57, 0x1D, 0x7F, 0x61, 0xA3, 0x0D, 0xE4, 0xFC, 0xFA, 0x82, 0x93, 0xA9, 0xDA, 0x51, 0x23, 0x96,
0xF1, 0x31, 0x9A, 0x36, 0x49, 0x68, 0x46, 0x4C, 0xA9, 0x80, 0x6E, 0x0A, 0x52, 0x56, 0x74, 0x86,
0x75, 0x4C, 0xDD, 0xD4, 0xC3, 0xA6, 0x2B, 0xDC, 0xE2, 0x55, 0xE0, 0xDE, 0xEC, 0x23, 0x01, 0x29,
0xC1, 0xBA, 0xE1, 0xAE, 0x95, 0xD7, 0x86, 0x86, 0x56, 0x37, 0xC1, 0xE6, 0x5F, 0xAE, 0x83, 0xED,
0xF8, 0xE7, 0xB0, 0x7D, 0x17, 0xC0, 0xAA, 0xDA, 0x8F, 0x05, 0x5B, 0x64, 0x0D, 0x45, 0xAB, 0x0B,
0xAC, 0x76, 0xFF, 0x7B, 0x34, 0x39, 0xF5, 0xA4, 0xBF, 0xE8, 0xF7, 0xE0, 0xE1, 0x03, 0xBC, 0xE9,
0x95, 0xFA, 0xD9, 0x13, 0xFB, 0x72, 0x9D, 0x3D, 0x03, 0x0B, 0x26, 0x44, 0xEC, 0x48, 0x39, 0x64,
0x24, 0xE0, 0x56, 0x3A, 0x1B, 0x3E, 0x6A, 0x1F, 0x68, 0x0B, 0x39, 0xFC, 0x14, 0x61, 0x88, 0x6F,
0xA7, 0xA6, 0x0B, 0x6B, 0x56, 0xC5, 0xA8, 0x46, 0x55, 0x4A, 0xE6, 0x48, 0xFC, 0x46, 0xE3, 0x0E,
0x24, 0x67, 0x8F, 0xAF, 0x1D, 0xC3, 0xCE, 0xB1, 0x0C, 0x2A, 0x95, 0x0F, 0x4F, 0xFA, 0x20, 0x83,
0x23, 0x4E, 0xD8, 0xDC, 0xC3, 0x58, 0x7A, 0x6D, 0x75, 0x1A, 0x7E, 0x9A, 0xFA, 0x06, 0x15, 0x69,
0x55, 0x08, 0x4F, 0xF2, 0x72, 0x5B, 0x69, 0x8E, 0xB1, 0x74, 0x54, 0xD9, 0xB0, 0x2B, 0x6B, 0x76,
0xBE, 0x47, 0xAB, 0xBE, 0x20, 0x62, 0x94, 0x36, 0x69, 0x87, 0xA4, 0xCA, 0xB4, 0x2C, 0xBD, 0x0B
};
const u8 sig_nand_ncsd_retail[256] = {
0x6C, 0xF5, 0x2F, 0x89, 0xF3, 0x78, 0x12, 0x0B, 0xFA, 0x4E, 0x10, 0x61, 0xD7, 0x36, 0x16, 0x34,
0xD9, 0xA2, 0x54, 0xA4, 0xF5, 0x7A, 0xA5, 0xBD, 0x9F, 0x2C, 0x30, 0x93, 0x4F, 0x0E, 0x68, 0xCB,
0xE6, 0x61, 0x1D, 0x90, 0xD7, 0x4C, 0xAA, 0xAC, 0xB6, 0xA9, 0x95, 0x56, 0x56, 0x47, 0x33, 0x3D,
0xC1, 0x70, 0x92, 0xD3, 0x20, 0x13, 0x10, 0x89, 0xCC, 0xCD, 0x63, 0x31, 0xCB, 0x3A, 0x59, 0x5D,
0x1B, 0xA2, 0x99, 0xA3, 0x2F, 0xF4, 0xD8, 0xE5, 0xDD, 0x1E, 0xB4, 0x6A, 0x2A, 0x57, 0x93, 0x5F,
0x6F, 0xE6, 0x37, 0x32, 0x2D, 0x3B, 0xC4, 0xF6, 0x7C, 0xFE, 0xD6, 0xC2, 0x25, 0x4C, 0x08, 0x9C,
0x62, 0xFA, 0x11, 0xD0, 0x82, 0x4A, 0x84, 0x4C, 0x79, 0xEE, 0x5A, 0x4F, 0x27, 0x3D, 0x46, 0xC2,
0x3B, 0xBB, 0xF0, 0xA2, 0xAF, 0x6A, 0xCA, 0xDB, 0xE6, 0x46, 0xF4, 0x6B, 0x86, 0xD1, 0x28, 0x9C,
0x7F, 0xF7, 0xE8, 0x16, 0xCF, 0xDA, 0x4B, 0xC3, 0x3D, 0xFF, 0x9D, 0x17, 0x5A, 0xC6, 0x9F, 0x72,
0x40, 0x6C, 0x07, 0x1B, 0x51, 0xF4, 0x5A, 0x1A, 0xCB, 0x87, 0xF1, 0x68, 0xC1, 0x77, 0xCB, 0x9B,
0xE6, 0xC3, 0x92, 0xF0, 0x34, 0x18, 0x49, 0xAE, 0x5D, 0x51, 0x0D, 0x26, 0xEE, 0xC1, 0x09, 0x7B,
0xEB, 0xFB, 0x9D, 0x14, 0x4A, 0x16, 0x47, 0x30, 0x1B, 0xEA, 0xF9, 0x52, 0x0D, 0x22, 0xC5, 0x5A,
0xF4, 0x6D, 0x49, 0x28, 0x4C, 0xC7, 0xF9, 0xFB, 0xBA, 0x37, 0x1A, 0x6D, 0x6E, 0x4C, 0x55, 0xF1,
0xE5, 0x36, 0xD6, 0x23, 0x7F, 0xFF, 0x54, 0xB3, 0xE9, 0xC1, 0x1A, 0x20, 0xCF, 0xCC, 0xAC, 0x0C,
0x6B, 0x06, 0xF6, 0x95, 0x76, 0x6A, 0xCE, 0xB1, 0x8B, 0xE3, 0x32, 0x99, 0xA9, 0x4C, 0xFC, 0xA7,
0xE2, 0x58, 0x81, 0x86, 0x52, 0xF7, 0x52, 0x6B, 0x30, 0x6B, 0x52, 0xE0, 0xAE, 0xD0, 0x42, 0x18
};
const u8 sig_nand_ncsd_dev[256] = {
0x53, 0xCB, 0x0E, 0x4E, 0xB1, 0xA6, 0xFF, 0x84, 0x28, 0x4B, 0xE0, 0xE7, 0x38, 0x5A, 0xB4, 0xA6,
0x86, 0xA8, 0xBB, 0xCB, 0xC1, 0x61, 0x02, 0x47, 0x92, 0x80, 0xE0, 0x58, 0x36, 0x55, 0xD2, 0x71,
0x3F, 0xE5, 0x06, 0xFA, 0xEE, 0x74, 0xF8, 0xD1, 0x0F, 0x12, 0x20, 0x44, 0x1C, 0xC2, 0xFF, 0x5D,
0x6D, 0xDE, 0x99, 0xBE, 0x79, 0xC1, 0x9B, 0x38, 0x6C, 0xAF, 0x68, 0xD5, 0xEB, 0x8C, 0xED, 0x1A,
0xAB, 0x4D, 0x24, 0x3C, 0x5F, 0x39, 0x86, 0x80, 0xD3, 0x1C, 0xD2, 0xE3, 0xC9, 0xDD, 0x56, 0x70,
0xF2, 0xA8, 0x8D, 0x56, 0x3B, 0x8F, 0x65, 0xF5, 0xB2, 0x34, 0xFD, 0x2E, 0xBB, 0x3B, 0xE4, 0x4A,
0x3B, 0x6C, 0x30, 0x27, 0x22, 0xA2, 0xAD, 0xFB, 0x56, 0xAE, 0x3E, 0x1F, 0x64, 0x17, 0xBD, 0xEC,
0x1E, 0x5A, 0x86, 0xAA, 0xBB, 0xAF, 0xBE, 0x94, 0x19, 0xAC, 0xA8, 0xFD, 0xCD, 0x45, 0xE2, 0xCD,
0xF1, 0xEB, 0x69, 0x5F, 0x6E, 0xA8, 0x78, 0x16, 0x12, 0x2D, 0x7B, 0xE9, 0x8E, 0xEF, 0x92, 0xC0,
0x81, 0x4B, 0x16, 0xB2, 0x15, 0xB3, 0x1D, 0x8C, 0x81, 0x3B, 0xB3, 0x55, 0xCE, 0xA8, 0x13, 0x8F,
0xB3, 0xBF, 0x23, 0x74, 0x24, 0x68, 0x42, 0xCD, 0x91, 0xE1, 0xF9, 0xAA, 0xFF, 0x76, 0x87, 0x86,
0x17, 0xCE, 0x02, 0x06, 0x47, 0x77, 0xAE, 0xA0, 0x87, 0x6A, 0x2C, 0x24, 0x5C, 0x78, 0x43, 0x41,
0xCD, 0xEE, 0x90, 0xD6, 0x91, 0x74, 0x59, 0x08, 0xA6, 0xFF, 0x9C, 0xE7, 0x81, 0x16, 0x67, 0x96,
0xF9, 0xF1, 0x23, 0x8F, 0x88, 0x4C, 0x84, 0xD6, 0xF1, 0xEE, 0xBB, 0x2E, 0x40, 0xB4, 0xBC, 0xA0,
0x0A, 0x7B, 0x1E, 0x91, 0x3E, 0x09, 0x80, 0xD2, 0x9F, 0xF6, 0x06, 0x1D, 0x8A, 0xA9, 0x44, 0xC6,
0x63, 0xF2, 0x63, 0x81, 0x27, 0xF7, 0xCC, 0xAB, 0x6F, 0xC7, 0x15, 0x38, 0x47, 0x1A, 0x51, 0x38
};
// see http://www.sighax.com/ for source of this signature
// thanks derrek, plutoo, yellows8, smea and profi200
const u8 sig_nand_firm_retail_alt[256] = {
0x6E, 0xFF, 0x20, 0x9C, 0x8F, 0x4A, 0xF6, 0x1F, 0x06, 0x24, 0x13, 0xD6, 0x02, 0xCA, 0x6B, 0x4D,
0xA1, 0xEB, 0x5A, 0xB9, 0xB6, 0xF1, 0xA2, 0xAB, 0x22, 0x6A, 0x71, 0x1D, 0xA2, 0xCC, 0xC2, 0x7C,
0x74, 0xDE, 0x17, 0x41, 0x14, 0x3B, 0xF6, 0x90, 0x58, 0x28, 0x4C, 0xAF, 0x44, 0x4F, 0x92, 0xA4,
0x5A, 0xAF, 0xD5, 0xA0, 0x68, 0x04, 0x33, 0x23, 0xD4, 0x8A, 0xF1, 0xD0, 0xEC, 0x05, 0x56, 0x4E,
0xBC, 0x79, 0xB5, 0x51, 0x34, 0xE9, 0x1A, 0x86, 0xC3, 0x78, 0x8C, 0x97, 0xBC, 0x29, 0xD5, 0xA5,
0x8A, 0x8A, 0x45, 0x25, 0x58, 0x43, 0xB8, 0x91, 0x22, 0xC7, 0x80, 0x45, 0x42, 0xF7, 0x26, 0x77,
0xC8, 0xDA, 0x5E, 0xB7, 0x42, 0x9B, 0xAF, 0x18, 0xF7, 0xA8, 0xB0, 0x2E, 0x8B, 0xB9, 0x40, 0xFE,
0x99, 0x0E, 0x9D, 0xC9, 0x7E, 0xDC, 0xF4, 0x9D, 0xDB, 0x18, 0x09, 0x2C, 0x28, 0x20, 0x6E, 0x74,
0x67, 0x53, 0xCC, 0x7C, 0x6E, 0x92, 0x36, 0x2A, 0xA8, 0xD5, 0x46, 0xB3, 0x8D, 0x9E, 0x8D, 0x43,
0x11, 0xA6, 0xB1, 0x93, 0x0D, 0xA1, 0x48, 0x97, 0x80, 0x7E, 0x30, 0x4B, 0x5E, 0x1E, 0xC0, 0x85,
0x6E, 0xEF, 0xD6, 0x2C, 0xEA, 0xEE, 0xF2, 0x8B, 0x08, 0xBD, 0x80, 0x39, 0x7A, 0x18, 0x15, 0x60,
0xAE, 0x6F, 0xCE, 0x39, 0xD0, 0x9C, 0x39, 0xDC, 0x3D, 0xED, 0x8C, 0x87, 0x0A, 0xB6, 0xAB, 0xCE,
0x28, 0x94, 0x94, 0x0C, 0x0E, 0x9C, 0x41, 0x74, 0xF0, 0x13, 0x1A, 0x0D, 0xA0, 0x74, 0x7C, 0x4A,
0x7A, 0x42, 0xC9, 0xEC, 0x34, 0x87, 0xF1, 0x09, 0xE2, 0x52, 0xB7, 0xA9, 0xB8, 0x65, 0xAE, 0x47,
0x78, 0x95, 0xE8, 0xD6, 0xA4, 0x2A, 0x07, 0x17, 0xC4, 0x0B, 0xCC, 0xC7, 0xA7, 0x35, 0xF3, 0x3B,
0x1E, 0x37, 0x66, 0xAB, 0x0E, 0x4B, 0x5D, 0x68, 0x1B, 0xAB, 0x41, 0x07, 0x34, 0xAB, 0x62, 0xB0
};

View File

@ -0,0 +1,9 @@
#pragma once
#include "common.h"
extern const u8 sig_nand_firm_retail[256];
extern const u8 sig_nand_firm_retail_alt[256];
extern const u8 sig_nand_firm_dev[256];
extern const u8 sig_nand_ncsd_retail[256];
extern const u8 sig_nand_ncsd_dev[256];

388
arm9/source/common/swkbd.c Normal file
View File

@ -0,0 +1,388 @@
#include <stdarg.h>
#include "language.h"
#include "swkbd.h"
#include "timer.h"
#include "hid.h"
#include "utf.h"
static inline char to_uppercase(char c) {
if ((c >= 'a') && (c <= 'z')) c += ('A'-'a');
return c;
}
static bool BuildKeyboard(TouchBox* swkbd, const char* keys, const u8* layout) {
// count # of rows
u32 n_rows = 0;
for (u32 i = 0;; i++) {
if (layout[i] == 0) {
n_rows++;
if (layout[i+1] == 0) break;
}
}
// set p_y start position
u32 height = (n_rows) ? (n_rows * SWKBD_STDKEY_HEIGHT) + ((n_rows-1) * SWKDB_KEY_SPACING) : 0;
u32 p_y = SCREEN_HEIGHT - height - SWKBD_STDKEY_HEIGHT - SWKDB_KEY_SPACING;
// set up the textbox
TouchBox* txtbox = swkbd;
txtbox->x = (SCREEN_WIDTH_BOT - SWKBD_TEXTBOX_WIDTH) / 2;
txtbox->y = p_y - 30;
txtbox->w = SWKBD_TEXTBOX_WIDTH;
txtbox->h = 30;
txtbox->id = KEY_TXTBOX;
// set button positions
TouchBox* tb = swkbd + 1;
for (u32 l = 0, k = 0; layout[l] != 0; ) {
// calculate width of current row
u32 n_keys = layout[l++];
u32 width = (n_keys * SWKBD_STDKEY_WIDTH) + ((n_keys-1) * SWKDB_KEY_SPACING);
for (u32 i = 0; layout[l+i] != 0; i++)
width = width - SWKBD_STDKEY_WIDTH + layout[l+i];
// set p_x start position
if (width > SCREEN_WIDTH_BOT) return false;
u32 p_x = (SCREEN_WIDTH_BOT - width) / 2;
// set up touchboxes
for (u32 i = 0; i < n_keys; i++) {
tb->id = keys[k++];
tb->x = p_x;
tb->y = p_y;
tb->w = ((tb->id >= 0x80) || (tb->id == (u32) ' ')) ? layout[l++] : SWKBD_STDKEY_WIDTH;
tb->h = SWKBD_STDKEY_HEIGHT;
p_x += tb->w + SWKDB_KEY_SPACING;
tb++;
}
// next row
if (layout[l++] != 0) return false;
p_y += SWKBD_STDKEY_HEIGHT + SWKDB_KEY_SPACING;
}
// set last touchbox zero (so the end can be detected)
memset(tb, 0, sizeof(TouchBox));
return true;
}
static void DrawKey(const TouchBox* key, const bool pressed, const u32 uppercase) {
const char* keystrs[] = { SWKBD_KEYSTR };
const u32 color = (pressed) ? COLOR_SWKBD_PRESSED :
(key->id == KEY_ENTER) ? COLOR_SWKBD_ENTER :
((key->id == KEY_CAPS) && (uppercase > 1)) ? COLOR_SWKBD_CAPS :
COLOR_SWKBD_NORMAL;
// don't even try to draw the textbox
if (key->id == KEY_TXTBOX) return;
char keystr[16];
if (key->id >= 0x80) snprintf(keystr, sizeof(keystr), "%s", keystrs[key->id - 0x80]);
else {
keystr[0] = (uppercase) ? to_uppercase(key->id) : key->id;
keystr[1] = 0;
}
const u32 width = GetDrawStringWidth(keystr);
const u32 f_offs_x = (key->w - width) / 2;
const u32 f_offs_y = (key->h - FONT_HEIGHT_EXT) / 2;
DrawRectangle(BOT_SCREEN, key->x, key->y, key->w, key->h, color);
DrawString(BOT_SCREEN, keystr, key->x + f_offs_x, key->y + f_offs_y, COLOR_SWKBD_CHARS, color);
}
static void DrawKeyBoardBox(TouchBox* swkbd, u32 color) {
// we need to make sure to skip the textbox here(first entry)
// calculate / draw keyboard box
u16 x0 = SCREEN_WIDTH_BOT, x1 = 0;
u16 y0 = SCREEN_HEIGHT, y1 = 0;
for (TouchBox* tb = swkbd + 1; tb->id != 0; tb++) {
if (tb->x < x0) x0 = tb->x;
if (tb->y < y0) y0 = tb->y;
if ((tb->x + tb->w) > x1) x1 = tb->x + tb->w;
if ((tb->y + tb->h) > y1) y1 = tb->y + tb->h;
}
DrawRectangle(BOT_SCREEN, 0, y0-1, SCREEN_WIDTH_BOT, y1-y0+2, COLOR_STD_BG);
DrawRectangle(BOT_SCREEN, x0-1, y0-1, x1-x0+2, y1-y0+2, color);
}
static void DrawKeyBoard(TouchBox* swkbd, const u32 uppercase) {
// we need to make sure to skip the textbox here(first entry)
// draw keyboard
for (TouchBox* tb = swkbd + 1; tb->id != 0; tb++) {
DrawKey(tb, false, uppercase);
}
}
static void DrawTextBox(const TouchBox* txtbox, const char* inputstr, const u32 cursor, u32* scroll) {
const u32 input_shown_length = (txtbox->w / FONT_WIDTH_EXT) - 2;
const u32 inputstr_size = strlen(inputstr); // we rely on a zero terminated string
const u16 x = txtbox->x;
const u16 y = txtbox->y;
// fix scroll
if (cursor < *scroll) {
*scroll = cursor;
} else {
int scroll_adjust = -input_shown_length;
for (u32 i = *scroll; i < cursor; i++) {
if (i >= inputstr_size || (inputstr[i] & 0xC0) != 0x80) scroll_adjust++;
}
for (int i = 0; i < scroll_adjust; i++)
*scroll += *scroll >= inputstr_size ? 1 : GetCharSize(inputstr + *scroll);
}
u32 input_shown_size = 0;
for (u32 i = 0; i < input_shown_length || (*scroll + input_shown_size < inputstr_size && (inputstr[*scroll + input_shown_size] & 0xC0) == 0x80); input_shown_size++) {
if (*scroll + input_shown_size >= inputstr_size || (inputstr[*scroll + input_shown_size] & 0xC0) != 0x80) i++;
}
// draw input string
DrawStringF(BOT_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, "%c%-*.*s%c",
(*scroll) ? '<' : '|',
(int) input_shown_size,
(int) input_shown_size,
(*scroll > inputstr_size) ? "" : inputstr + *scroll,
(inputstr_size - (s32) *scroll > input_shown_size) ? '>' : '|'
);
// draw cursor
u16 cpos = 0;
for (u16 i = *scroll; i < cursor; i++) {
if (i >= inputstr_size || (inputstr[i] & 0xC0) != 0x80) cpos++;
}
DrawStringF(BOT_SCREEN, x-(FONT_WIDTH_EXT/2), y+10, COLOR_STD_FONT, COLOR_STD_BG, "%-*.*s^%-*.*s",
(int) (1 + cpos),
(int) (1 + cpos),
"",
(int) (input_shown_length - cpos),
(int) (input_shown_length - cpos),
""
);
}
static void MoveTextBoxCursor(const TouchBox* txtbox, const char* inputstr, const u32 max_size, u32* cursor, u32* scroll) {
const u32 input_shown = (txtbox->w / FONT_WIDTH_EXT) - 2;
const u64 scroll_cooldown = 144;
u64 timer = timer_start();
u32 id = 0;
u16 x, y;
// process touch input
while(HID_ReadTouchState(&x, &y)) {
const TouchBox* tb = TouchBoxGet(&id, x, y, txtbox, 0);
if (id == KEY_TXTBOX) {
u16 x_tb = x - tb->x;
const u32 inputstr_size = strlen(inputstr);
const u16 cpos_x = (x_tb < (FONT_WIDTH_EXT/2)) ? 0 : (x_tb - (FONT_WIDTH_EXT/2)) / FONT_WIDTH_EXT;
u16 cpos_length = 0;
u16 cpos_size = 0;
while ((cpos_length < cpos_x && cpos_length < input_shown) || (*scroll + cpos_size < inputstr_size && (inputstr[*scroll + cpos_size] & 0xC0) == 0x80)) {
if (*scroll + cpos_size >= inputstr_size || (inputstr[*scroll + cpos_size] & 0xC0) != 0x80) cpos_length++;
cpos_size++;
}
u32 cursor_next = *scroll + cpos_size;
// move cursor to position pointed to
if (*cursor != cursor_next) {
if (cursor_next < max_size) *cursor = cursor_next;
DrawTextBox(txtbox, inputstr, *cursor, scroll);
timer = timer_start();
}
// move beyound visible field
if (timer_msec(timer) >= scroll_cooldown) {
if ((cpos_length == 0) && (*scroll > 0))
*scroll -= GetPrevCharSize(inputstr + *scroll);
else if ((cpos_length >= input_shown) && (*cursor < (max_size-1)))
*scroll += GetCharSize(inputstr + *scroll);
}
}
}
}
static char KeyboardWait(TouchBox* swkbd, bool uppercase) {
u32 id = 0;
u16 x, y;
// wait for touch input (handle key input, too)
while (true) {
u32 pressed = InputWait(0);
if (pressed & BUTTON_B) return KEY_ESCAPE;
else if (pressed & BUTTON_A) return KEY_ENTER;
else if (pressed & BUTTON_X) return KEY_BKSPC;
else if (pressed & BUTTON_Y) return KEY_INSERT;
else if (pressed & BUTTON_R1) return KEY_CAPS;
else if (pressed & BUTTON_RIGHT) return KEY_RIGHT;
else if (pressed & BUTTON_LEFT) return KEY_LEFT;
else if (pressed & BUTTON_SELECT) return KEY_SWITCH;
else if (pressed & BUTTON_TOUCH) break;
}
// process touch input
while(HID_ReadTouchState(&x, &y)) {
const TouchBox* tb = TouchBoxGet(&id, x, y, swkbd, 0);
if (tb) {
if (id == KEY_TXTBOX) break; // immediately break on textbox
DrawKey(tb, true, uppercase);
while(HID_ReadTouchState(&x, &y) && (tb == TouchBoxGet(NULL, x, y, swkbd, 0)));
DrawKey(tb, false, uppercase);
}
}
return (uppercase) ? to_uppercase((char) id) : (char) id;
}
bool ShowKeyboard(char* inputstr, const u32 max_size, const char *format, ...) {
static const char keys_alphabet[] = { SWKBD_KEYS_ALPHABET };
static const char keys_special[] = { SWKBD_KEYS_SPECIAL };
static const char keys_numpad[] = { SWKBD_KEYS_NUMPAD };
static const u8 layout_alphabet[] = { SWKBD_LAYOUT_ALPHABET };
static const u8 layout_special[] = { SWKBD_LAYOUT_SPECIAL };
static const u8 layout_numpad[] = { SWKBD_LAYOUT_NUMPAD };
TouchBox swkbd_alphabet[64];
TouchBox swkbd_special[32];
TouchBox swkbd_numpad[32];
TouchBox* textbox = swkbd_alphabet; // always use this textbox
static bool show_instr = true;
const char* instr = STR_KEYBOARD_CONTROLS_DETAILS;
if (show_instr) {
ShowPrompt(false, "%s", instr);
show_instr = false;
}
// generate keyboards
if (!BuildKeyboard(swkbd_alphabet, keys_alphabet, layout_alphabet)) return false;
if (!BuildKeyboard(swkbd_special, keys_special, layout_special)) return false;
if (!BuildKeyboard(swkbd_numpad, keys_numpad, layout_numpad)) return false;
// (instructional) text
char str[512]; // arbitrary limit, should be more than enough
va_list va;
va_start(va, format);
vsnprintf(str, sizeof(str), format, va);
va_end(va);
u32 str_width = GetDrawStringWidth(str);
if (str_width < (24 * FONT_WIDTH_EXT)) str_width = 24 * FONT_WIDTH_EXT;
u32 str_x = (str_width >= SCREEN_WIDTH_BOT) ? 0 : (SCREEN_WIDTH_BOT - str_width) / 2;
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
DrawStringF(BOT_SCREEN, str_x, 20, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
// wait for all keys released
while (HID_ReadState() & BUTTON_ANY);
// handle keyboard
u32 uppercase = 0; // 1 -> uppercase once, 2 -> uppercase always
u32 scroll = 0;
u32 cursor = 0;
u32 inputstr_size = strnlen(inputstr, max_size);
TouchBox* swkbd_prev = NULL;
TouchBox* swkbd = swkbd_alphabet;
bool ret = false;
while (true) {
// draw keyboard if required
if (swkbd != swkbd_prev) {
DrawKeyBoardBox(swkbd, COLOR_SWKBD_BOX);
DrawKeyBoard(swkbd, uppercase);
DrawTextBox(textbox, inputstr, cursor, &scroll);
swkbd_prev = swkbd;
}
// handle user input
char key = KeyboardWait(swkbd, uppercase);
if (key == KEY_INSERT) key = ' '; // impromptu replacement
if (key == KEY_TXTBOX) {
MoveTextBoxCursor(textbox, inputstr, max_size, &cursor, &scroll);
} else if (key == KEY_CAPS) {
uppercase = (uppercase + 1) % 3;
DrawKeyBoard(swkbd, uppercase);
continue;
} else if (key == KEY_ENTER) {
ret = true;
break;
} else if (key == KEY_ESCAPE) {
break;
} else if (key == KEY_BKSPC) {
if (cursor) {
int size = GetPrevCharSize(inputstr + cursor);
if (cursor <= inputstr_size) {
memmove(inputstr + cursor - size, inputstr + cursor, inputstr_size - cursor + size);
inputstr_size -= size;
}
cursor -= size;
}
} else if (key == KEY_LEFT) {
if (cursor) cursor -= GetPrevCharSize(inputstr + cursor);
} else if (key == KEY_RIGHT) {
int size = cursor > inputstr_size ? 1 : GetCharSize(inputstr + cursor);
if (cursor + size < max_size) cursor += size;
} else if (key == KEY_ALPHA) {
swkbd = swkbd_alphabet;
} else if (key == KEY_SPECIAL) {
swkbd = swkbd_special;
} else if (key == KEY_NUMPAD) {
swkbd = swkbd_numpad;
} else if (key == KEY_SWITCH) {
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
return ShowStringPrompt(inputstr, max_size, "%s", str);
} else if (key == KEY_UNICODE) {
if (cursor > 3 && cursor <= inputstr_size) {
u16 codepoint = 0;
for (char *c = inputstr + cursor - 4; c < inputstr + cursor; c++) {
if ((*c >= '0' && *c <= '9') || (*c >= 'A' && *c <= 'F') || (*c >= 'a' && *c <= 'f')) {
codepoint <<= 4;
codepoint |= *c - (*c <= '9' ? '0' : ((*c <= 'F' ? 'A' : 'a') - 10));
} else {
codepoint = 0;
break;
}
}
if(codepoint != 0) {
char character[5] = {0};
u16 input[2] = {codepoint, 0};
utf16_to_utf8((u8*)character, input, 4, 1);
u32 char_size = GetCharSize(character);
memmove(inputstr + cursor - 4 + char_size, inputstr + cursor, max_size - cursor + 4 - char_size);
memcpy(inputstr + cursor - 4, character, char_size);
cursor -= 4 - char_size;
}
}
} else if (key && (key < 0x80)) {
if ((cursor < (max_size-1)) && (inputstr_size < max_size)) {
// pad string (if cursor beyound string size)
while (inputstr_size < cursor) {
inputstr[inputstr_size++] = ' ';
inputstr[inputstr_size] = '\0';
}
// make room
if (inputstr_size < (max_size-1)) { // only if there is still room
memmove(inputstr + cursor + 1, inputstr + cursor, max_size - cursor - 1);
inputstr_size++;
}
// insert char
inputstr[cursor++] = key;
}
if (uppercase == 1) {
uppercase = 0;
DrawKeyBoard(swkbd, uppercase);
}
}
// update text
DrawTextBox(textbox, inputstr, cursor, &scroll);
}
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
return ret;
}

View File

@ -0,0 +1,89 @@
#pragma once
#include "common.h"
#include "ui.h"
#include "touchcal.h"
// special key ids
enum {
KEY_DUMMY = 0x80,
KEY_BKSPC = 0x81,
KEY_INSERT = 0x82,
KEY_ENTER = 0x83,
KEY_CAPS = 0x84,
KEY_SPECIAL = 0x85,
KEY_NUMPAD = 0x86,
KEY_ALPHA = 0x87,
KEY_LEFT = 0x88,
KEY_RIGHT = 0x89,
KEY_ESCAPE = 0x8A,
KEY_SWITCH = 0x8B,
KEY_UNICODE = 0x8C,
KEY_TXTBOX = 0xFF
};
// special key strings
#define SWKBD_KEYSTR "", "DEL", "INS", "SUBMIT", "CAPS", "#$@", "123", "ABC", "←", "→", "ESC", "SWITCH", "U+"
#define COLOR_SWKBD_NORMAL COLOR_GREY
#define COLOR_SWKBD_PRESSED COLOR_LIGHTGREY
#define COLOR_SWKBD_BOX COLOR_DARKGREY
#define COLOR_SWKBD_CHARS COLOR_BLACK
#define COLOR_SWKBD_ENTER COLOR_TINTEDBLUE
#define COLOR_SWKBD_CAPS COLOR_TINTEDYELLOW
#define SWKBD_TEXTBOX_WIDTH 240
#define SWKBD_STDKEY_WIDTH 18
#define SWKBD_STDKEY_HEIGHT 20
#define SWKDB_KEY_SPACING 1
#define SWKBD_KEYS_ALPHABET \
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '+', '-', KEY_BKSPC, \
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '&', KEY_ENTER, \
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', '(', ')', '[', ']', \
'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '_', '#', '!', \
KEY_CAPS, ' ', KEY_NUMPAD, KEY_SPECIAL, KEY_LEFT, KEY_RIGHT
#define SWKBD_KEYS_SPECIAL \
'(', ')', '{', '}', '[', ']', \
'.', ',', '?', '!', '`', '\'', \
'^', '*', '+', '-', '_', '=', \
'@', '#', '$', '%', '&', '~', \
KEY_ALPHA, ' ', KEY_BKSPC
#define SWKBD_KEYS_NUMPAD \
'7', '8', '9', 'F', 'E', \
'4', '5', '6', 'D', 'C', \
'3', '2', '1', 'B', 'A', \
'0', '.', '_', KEY_LEFT, KEY_RIGHT, \
KEY_ALPHA, KEY_UNICODE, ' ', KEY_BKSPC
// offset, num of keys in row, width of special keys (...), 0
#define SWKBD_LAYOUT_ALPHABET \
13, 32, 0, \
12, 51, 0, \
13, 0, \
12, 0, \
6, 32, 123, 32, 32, 18, 18, 0, \
0
#define SWKBD_LAYOUT_SPECIAL \
6, 0, \
6, 0, \
6, 0, \
6, 0, \
3, 32, 46, 32, 0, \
0
#define SWKBD_LAYOUT_NUMPAD \
5, 0, \
5, 0, \
5, 0, \
5, 18, 18, 0, \
4, 20, 20, 31, 20, 0, \
0
#define ShowKeyboardOrPrompt (TouchIsCalibrated() ? ShowKeyboard : ShowStringPrompt)
bool PRINTF_ARGS(3) ShowKeyboard(char* inputstr, u32 max_size, const char *format, ...);

View File

@ -0,0 +1,54 @@
#include "timer.h"
u64 timer_start( void ) {
static bool timer_init = true;
// timer is initialized at least once (right at the beginning)
// this makes sure it is reinitialized in case of inconsistencies
if (!(*TIMER_CNT0 & *TIMER_CNT1 & *TIMER_CNT2 & *TIMER_CNT3 & TIMER_ACTIVE) ||
!(*TIMER_CNT1 & *TIMER_CNT2 & *TIMER_CNT3 & TIMER_COUNT_UP))
timer_init = true;
if (timer_init) {
// deactivate, then reset timers
*TIMER_CNT0 = 0;
*TIMER_CNT1 = *TIMER_CNT2 = *TIMER_CNT3 = TIMER_COUNT_UP;
*TIMER_VAL0 = *TIMER_VAL1 = *TIMER_VAL2 = *TIMER_VAL3 = 0;
// start timers
*TIMER_CNT0 = TIMER_ACTIVE;
*TIMER_CNT1 = *TIMER_CNT2 = *TIMER_CNT3 = TIMER_ACTIVE | TIMER_COUNT_UP;
// timer initialized
timer_init = false;
}
return timer_ticks( 0 );
}
/*void timer_stop( void ) {
*TIMER_CNT0 &= ~TIMER_ACTIVE;
*TIMER_CNT1 &= ~TIMER_ACTIVE;
*TIMER_CNT2 &= ~TIMER_ACTIVE;
*TIMER_CNT3 &= ~TIMER_ACTIVE;
}*/
u64 timer_ticks( u64 start_time ) {
u64 ticks = 0;
ticks |= (u64) *TIMER_VAL0 << 0;
ticks |= (u64) *TIMER_VAL1 << 16;
ticks |= (u64) *TIMER_VAL2 << 32;
ticks |= (u64) *TIMER_VAL3 << 48;
return ticks - start_time;
}
u64 timer_msec( u64 start_time ) {
return timer_ticks( start_time ) / (TICKS_PER_SEC/1000);
}
u64 timer_sec( u64 start_time ) {
return timer_ticks( start_time ) / TICKS_PER_SEC;
}
void wait_msec( u64 msec ) {
u64 timer = timer_start();
while (timer_msec( timer ) < msec );
}

View File

@ -0,0 +1,23 @@
#pragma once
#include "common.h"
// see: https://www.3dbrew.org/wiki/TIMER_Registers
#define TIMER_VAL0 ((vu16*)0x10003000)
#define TIMER_VAL1 ((vu16*)0x10003004)
#define TIMER_VAL2 ((vu16*)0x10003008)
#define TIMER_VAL3 ((vu16*)0x1000300C)
#define TIMER_CNT0 ((vu16*)0x10003002)
#define TIMER_CNT1 ((vu16*)0x10003006)
#define TIMER_CNT2 ((vu16*)0x1000300A)
#define TIMER_CNT3 ((vu16*)0x1000300E)
#define TIMER_COUNT_UP 0x0004
#define TIMER_ACTIVE 0x0080
#define TICKS_PER_SEC 67027964ULL
u64 timer_start( void );
u64 timer_ticks( u64 start_time );
u64 timer_msec( u64 start_time );
u64 timer_sec( u64 start_time );
void wait_msec( u64 msec );

View File

@ -0,0 +1,141 @@
#include "touchcal.h"
#include "ui.h"
#include "hid.h"
#include "crc16.h"
#include "language.h"
#include "spiflash.h"
#include "support.h"
#define TOUCH_CALIB_FILENAME "gm9calib.bin"
static const HID_CalibrationData default_calib = {
.screen_x = 0,
.screen_y = 0,
.ts_raw = 0
// ^ wrong: in my console it's 0x780086
// but this is very much console dependent
// so it's better to go with a sane default
};
static bool is_calibrated = false;
static bool SetCalibrationDefaults(void)
{
// Hardcoding this isn't ideal but it's better than
// leaving the system without any state to work with
is_calibrated = false; // no, this is not proper calibration
return HID_SetCalibrationData(&default_calib, 1, SCREEN_WIDTH_BOT, SCREEN_HEIGHT);
}
bool ShowTouchCalibrationDialog(void)
{
static const u32 dot_positions[][2] = {
{16, 16},
{SCREEN_WIDTH_BOT - 16, SCREEN_HEIGHT - 16},
{16, SCREEN_HEIGHT - 16},
{SCREEN_WIDTH_BOT - 16, 16},
};
HID_CalibrationData calibrations[countof(dot_positions)];
for (u32 i = 0; i < countof(dot_positions); i++) {
calibrations[i].screen_x = dot_positions[i][0];
calibrations[i].screen_y = dot_positions[i][1];
}
// clear screen, draw instructions
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
DrawStringCenter(BOT_SCREEN, COLOR_STD_FONT, COLOR_STD_BG, "%s",
STR_TOUCH_CROSSHAIRS_TO_CALIBRATE_TOUCHSCREEN_USE_STYLUS);
// set calibration defaults
SetCalibrationDefaults();
// actual calibration
for (u32 current_dot = 0; current_dot < countof(dot_positions); current_dot++) {
// draw four crosshairs
for (u32 i = 0; i < countof(dot_positions); i++) {
int color_cross = (i < current_dot) ? COLOR_BRIGHTGREEN : (i == current_dot) ? COLOR_RED : COLOR_STD_FONT;
for (u32 r = 2; r < 8; r++) {
DrawPixel(BOT_SCREEN, dot_positions[i][0] + 0, dot_positions[i][1] + r, color_cross);
DrawPixel(BOT_SCREEN, dot_positions[i][0] + r, dot_positions[i][1] + 0, color_cross);
DrawPixel(BOT_SCREEN, dot_positions[i][0] + 0, dot_positions[i][1] - r, color_cross);
DrawPixel(BOT_SCREEN, dot_positions[i][0] - r, dot_positions[i][1] + 0, color_cross);
}
}
// wait for input, store calibration data
while (1) {
u32 pressed = InputWait(0);
if (pressed & BUTTON_B) {
return false;
} else if (pressed & BUTTON_TOUCH) {
calibrations[current_dot].ts_raw = HID_ReadRawTouchState();
break;
}
}
}
is_calibrated = HID_SetCalibrationData(calibrations, countof(dot_positions), SCREEN_WIDTH_BOT, SCREEN_HEIGHT);
if (is_calibrated) { // store calibration data in a file
SaveSupportFile(TOUCH_CALIB_FILENAME, calibrations, sizeof(calibrations));
}
return is_calibrated;
}
bool CalibrateTouchFromSupportFile(void) {
HID_CalibrationData calibrations[10];
size_t size = LoadSupportFile(TOUCH_CALIB_FILENAME, calibrations, sizeof(calibrations));
u32 n_dots = size / sizeof(HID_CalibrationData);
is_calibrated = (n_dots == 0) ? false :
HID_SetCalibrationData(calibrations, n_dots, SCREEN_WIDTH_BOT, SCREEN_HEIGHT);
return is_calibrated;
}
bool CalibrateTouchFromFlash(void) {
HID_CalibrationData data[2];
// set calibration defaults
SetCalibrationDefaults();
// check SPIflash status
if (!spiflash_get_status())
return false;
// check NVRAM console ID
u32 console_id = 0;
if (!spiflash_read(0x001C, 4, (u8*)&console_id))
return false;
if (((console_id >> 8) & 0xFF) != 0x57)
return false; // not a 3DS
// read and check DS fw user settings
// see: https://problemkaputt.de/gbatek.htm#dsfirmwareusersettings
u32 fw_usercfg_buf[0x100 / 0x4];
u8* fw_usercfg = (u8*) fw_usercfg_buf;
if (!spiflash_read(0x1FE00, 0x100, fw_usercfg))
return false;
if (getle16(fw_usercfg + 0x72) != crc16_quick(fw_usercfg, 0x70))
return false;
// get touchscreen calibration data from user settings
u8 *ts_data = fw_usercfg + 0x58;
for (int i = 0; i < 2; i++) {
int base = i * 6;
data[i].ts_raw = ts_data[base + 1] << 24 | ts_data[base + 0] << 16 | ts_data[base + 3] << 8 | ts_data[base + 2];
data[i].screen_x = (((int)ts_data[base + 4]) * SCREEN_WIDTH_BOT) / 256;
data[i].screen_y = (((int)ts_data[base + 5]) * SCREEN_HEIGHT) / 192;
}
is_calibrated = HID_SetCalibrationData(data, 2, SCREEN_WIDTH_BOT, SCREEN_HEIGHT);
return is_calibrated;
}
bool TouchIsCalibrated(void) {
return is_calibrated;
}

View File

@ -0,0 +1,8 @@
#pragma once
#include "common.h"
bool ShowTouchCalibrationDialog(void);
bool CalibrateTouchFromSupportFile(void);
bool CalibrateTouchFromFlash(void);
bool TouchIsCalibrated(void);

1549
arm9/source/common/ui.c Normal file

File diff suppressed because it is too large Load Diff

117
arm9/source/common/ui.h Normal file
View File

@ -0,0 +1,117 @@
// Copyright 2013 Normmatt
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <vram.h>
#include "common.h"
#include "colors.h"
#include "fsdir.h" // only required for ShowFileScrollPrompt
#define BYTES_PER_PIXEL 2
#define SCREEN_HEIGHT 240
#define SCREEN_WIDTH(s) ((s == TOP_SCREEN) ? SCREEN_WIDTH_TOP : SCREEN_WIDTH_BOT)
#define SCREEN_WIDTH_TOP 400
#define SCREEN_WIDTH_BOT 320
#define SCREEN_SIZE(s) ((s == TOP_SCREEN) ? SCREEN_SIZE_TOP : SCREEN_SIZE_BOT)
#define SCREEN_SIZE_TOP (SCREEN_WIDTH_TOP * SCREEN_HEIGHT * BYTES_PER_PIXEL)
#define SCREEN_SIZE_BOT (SCREEN_WIDTH_BOT * SCREEN_HEIGHT * BYTES_PER_PIXEL)
#define FONT_WIDTH_EXT GetFontWidth()
#define FONT_HEIGHT_EXT GetFontHeight()
#define UTF_MAX_BYTES_PER_RUNE 4
#define UTF_BUFFER_BYTESIZE(rune_count) (((rune_count) + 1) * UTF_MAX_BYTES_PER_RUNE)
#define PRINTF_ARGS(n) __attribute__ ((format (printf, (n), (n) + 1)))
#define TOP_SCREEN ((u16*)VRAM_TOP_LA)
#define BOT_SCREEN ((u16*)VRAM_BOT_A)
#ifdef SWITCH_SCREENS
#define MAIN_SCREEN TOP_SCREEN
#define ALT_SCREEN BOT_SCREEN
#define SCREEN_WIDTH_MAIN SCREEN_WIDTH_TOP
#define SCREEN_WIDTH_ALT SCREEN_WIDTH_BOT
#else
#define MAIN_SCREEN BOT_SCREEN
#define ALT_SCREEN TOP_SCREEN
#define SCREEN_WIDTH_MAIN SCREEN_WIDTH_BOT
#define SCREEN_WIDTH_ALT SCREEN_WIDTH_TOP
#endif
#define COLOR_TRANSPARENT COLOR_SUPERFUCHSIA
#ifndef AUTO_UNLOCK
bool PRINTF_ARGS(2) ShowUnlockSequence(u32 seqlvl, const char *format, ...);
#else
#define ShowUnlockSequence ShowPrompt
#endif
const u8* GetFontFromPbm(const void* pbm, const u32 riff_size, u32* w, u32* h);
const u8* GetFontFromRiff(const void* riff, const u32 riff_size, u32* w, u32* h, u16* count);
bool SetFont(const void* font, const u32 font_size);
u16 GetColor(const u16 *screen, int x, int y);
void ClearScreen(u16 *screen, u32 color);
void ClearScreenF(bool clear_main, bool clear_alt, u32 color);
void DrawPixel(u16 *screen, int x, int y, u32 color);
void DrawRectangle(u16 *screen, int x, int y, u32 width, u32 height, u32 color);
void DrawBitmap(u16 *screen, int x, int y, u32 w, u32 h, const u16* bitmap);
void DrawQrCode(u16 *screen, const u8* qrcode);
void DrawCharacter(u16 *screen, u32 character, int x, int y, u32 color, u32 bgcolor);
void DrawString(u16 *screen, const char *str, int x, int y, u32 color, u32 bgcolor);
void PRINTF_ARGS(6) DrawStringF(u16 *screen, int x, int y, u32 color, u32 bgcolor, const char *format, ...);
void PRINTF_ARGS(4) DrawStringCenter(u16 *screen, u32 color, u32 bgcolor, const char *format, ...);
u32 GetCharSize(const char* str);
u32 GetPrevCharSize(const char* str);
u32 GetDrawStringHeight(const char* str);
u32 GetDrawStringWidth(const char* str);
u32 GetFontWidth(void);
u32 GetFontHeight(void);
void MultiLineString(char* dest, const char* orig, int llen, int maxl);
void WordWrapString(char* str, int llen);
void ResizeString(char* dest, const char* orig, int nlength, int tpos, bool align_right);
void TruncateString(char* dest, const char* orig, int nlength, int tpos);
void FormatNumber(char* str, u64 number);
void FormatBytes(char* str, u64 bytes);
void PRINTF_ARGS(1) ShowString(const char *format, ...);
void PRINTF_ARGS(2) ShowStringF(u16* screen, const char *format, ...);
void PRINTF_ARGS(4) ShowIconString(u16* icon, int w, int h, const char *format, ...);
void PRINTF_ARGS(5) ShowIconStringF(u16* screen, u16* icon, int w, int h, const char *format, ...);
bool PRINTF_ARGS(2) ShowPrompt(bool ask, const char *format, ...);
u32 PRINTF_ARGS(3) ShowSelectPrompt(int n, const char** options, const char *format, ...);
u32 PRINTF_ARGS(4) ShowFileScrollPrompt(int n, const DirEntry** entries, bool hide_ext, const char *format, ...);
u32 PRINTF_ARGS(4) ShowHotkeyPrompt(u32 n, const char** options, const u32* keys, const char *format, ...);
bool PRINTF_ARGS(3) ShowStringPrompt(char* inputstr, u32 max_size, const char *format, ...);
u64 PRINTF_ARGS(3) ShowHexPrompt(u64 start_val, u32 n_digits, const char *format, ...);
u64 PRINTF_ARGS(2) ShowNumberPrompt(u64 start_val, const char *format, ...);
bool PRINTF_ARGS(3) ShowDataPrompt(u8* data, u32* size, const char *format, ...);
bool PRINTF_ARGS(2) ShowRtcSetterPrompt(void* time, const char *format, ...);
bool ShowProgress(u64 current, u64 total, const char* opstr);
int ShowBrightnessConfig(int set_brightness);
static inline u16 rgb888_to_rgb565(u32 rgb) {
u8 r, g, b;
r = (rgb >> 16) & 0x1F;
g = (rgb >> 8) & 0x3F;
b = (rgb >> 0) & 0x1F;
return (r << 11) | (g << 5) | b;
}
static inline u16 rgb888_buf_to_rgb565(u8 *rgb) {
u8 r, g, b;
r = (rgb[0] >> 3);
g = (rgb[1] >> 2);
b = (rgb[2] >> 3);
return (r << 11) | (g << 5) | b;
}

View File

@ -0,0 +1,25 @@
#pragma once
#include "common.h"
// see: https://3dbrew.org/wiki/CONFIG11_Registers
#define IS_O3DS (((*(vu16*) 0x10140FFC) & 2) == 0)
// see: https://www.3dbrew.org/wiki/Memory_layout#ARM9_ITCM
// see: https://www.3dbrew.org/wiki/OTP_Registers#Plaintext_OTP
#define IS_DEVKIT ((*(vu8*) (0x01FFB800+0x19)) != 0x0)
// https://www.3dbrew.org/wiki/CONFIG9_Registers
// (actually checks for an unlocked OTP, meaning sighax)
#define IS_UNLOCKED (!((*(vu8*)0x10000000) & 0x2))
// System models
enum SystemModel {
MODEL_OLD_3DS = 0,
MODEL_OLD_3DS_XL,
MODEL_NEW_3DS,
MODEL_OLD_2DS,
MODEL_NEW_3DS_XL,
MODEL_NEW_2DS_XL,
NUM_MODELS
};

272
arm9/source/common/utf.c Normal file
View File

@ -0,0 +1,272 @@
#include "utf.h"
#define UTF_MAX_UNITS 256
#define ASCII_UNKNOWN ((u8) '?')
// most of the code here shamelessly stolen from:
// https://github.com/smealum/ctrulib/tree/bd34fd59dbf0691e2dba76be65f260303d8ccec7/libctru/source/util/utf
int decode_utf8(u32 *out, const u8 *in)
{
u8 code1, code2, code3, code4;
code1 = *in++;
if(code1 < 0x80)
{
/* 1-byte sequence */
*out = code1;
return 1;
}
else if(code1 < 0xC2)
{
return -1;
}
else if(code1 < 0xE0)
{
/* 2-byte sequence */
code2 = *in++;
if((code2 & 0xC0) != 0x80)
{
return -1;
}
*out = (code1 << 6) + code2 - 0x3080;
return 2;
}
else if(code1 < 0xF0)
{
/* 3-byte sequence */
code2 = *in++;
if((code2 & 0xC0) != 0x80)
{
return -1;
}
if(code1 == 0xE0 && code2 < 0xA0)
{
return -1;
}
code3 = *in++;
if((code3 & 0xC0) != 0x80)
{
return -1;
}
*out = (code1 << 12) + (code2 << 6) + code3 - 0xE2080;
return 3;
}
else if(code1 < 0xF5)
{
/* 4-byte sequence */
code2 = *in++;
if((code2 & 0xC0) != 0x80)
{
return -1;
}
if(code1 == 0xF0 && code2 < 0x90)
{
return -1;
}
if(code1 == 0xF4 && code2 >= 0x90)
{
return -1;
}
code3 = *in++;
if((code3 & 0xC0) != 0x80)
{
return -1;
}
code4 = *in++;
if((code4 & 0xC0) != 0x80)
{
return -1;
}
*out = (code1 << 18) + (code2 << 12) + (code3 << 6) + code4 - 0x3C82080;
return 4;
}
return -1;
}
int decode_utf16(u32 *out, const u16 *in)
{
u16 code1, code2;
code1 = *in++;
if(code1 >= 0xD800 && code1 < 0xDC00)
{
/* surrogate pair */
code2 = *in++;
if(code2 >= 0xDC00 && code2 < 0xE000)
{
*out = (code1 << 10) + code2 - 0x35FDC00;
return 2;
}
return -1;
}
*out = code1;
return 1;
}
int encode_utf8(u8 *out, u32 in)
{
if(in < 0x80)
{
if(out != NULL)
*out++ = in;
return 1;
}
else if(in < 0x800)
{
if(out != NULL)
{
*out++ = (in >> 6) + 0xC0;
*out++ = (in & 0x3F) + 0x80;
}
return 2;
}
else if(in < 0x10000)
{
if(out != NULL)
{
*out++ = (in >> 12) + 0xE0;
*out++ = ((in >> 6) & 0x3F) + 0x80;
*out++ = (in & 0x3F) + 0x80;
}
return 3;
}
else if(in < 0x110000)
{
if(out != NULL)
{
*out++ = (in >> 18) + 0xF0;
*out++ = ((in >> 12) & 0x3F) + 0x80;
*out++ = ((in >> 6) & 0x3F) + 0x80;
*out++ = (in & 0x3F) + 0x80;
}
return 4;
}
return -1;
}
int encode_utf16(u16 *out, u32 in)
{
if(in < 0x10000)
{
if(out != NULL)
*out++ = in;
return 1;
}
else if(in < 0x110000)
{
if(out != NULL)
{
*out++ = (in >> 10) + 0xD7C0;
*out++ = (in & 0x3FF) + 0xDC00;
}
return 2;
}
return -1;
}
int utf16_to_utf8(u8 *out, const u16 *in, int len_out, int len_in)
{
int rc = 0;
int units;
u32 code;
u8 encoded[4];
do
{
units = decode_utf16(&code, in);
if(units == -1)
return -1;
if (len_in >= units)
len_in -= units;
else return -1;
if(code > 0)
{
in += units;
units = encode_utf8(encoded, code);
if(units == -1)
return -1;
if(out != NULL)
{
if(rc + units <= len_out)
{
*out++ = encoded[0];
if(units > 1)
*out++ = encoded[1];
if(units > 2)
*out++ = encoded[2];
if(units > 3)
*out++ = encoded[3];
}
}
if(UTF_MAX_UNITS - units >= rc)
rc += units;
else
return -1;
}
} while(code > 0 && len_in > 0);
return rc;
}
int utf8_to_utf16(u16 *out, const u8 *in, int len_out, int len_in)
{
int rc = 0;
int units;
u32 code;
u16 encoded[2];
do
{
units = decode_utf8(&code, in);
if(units == -1)
return -1;
if (len_in >= units)
len_in -= units;
else return -1;
if(code > 0)
{
in += units;
units = encode_utf16(encoded, code);
if(units == -1)
return -1;
if(out != NULL)
{
if(rc + units <= len_out)
{
*out++ = encoded[0];
if(units > 1)
*out++ = encoded[1];
}
}
if(UTF_MAX_UNITS - units >= rc)
rc += units;
else
return -1;
}
} while(code > 0 && len_in > 0);
return rc;
}

8
arm9/source/common/utf.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#include "common.h"
// most of the code here shamelessly stolen from:
// https://github.com/smealum/ctrulib/tree/bd34fd59dbf0691e2dba76be65f260303d8ccec7/libctru/source/util/utf
int utf16_to_utf8(u8 *out, const u16 *in, int len_out, int len_in);
int utf8_to_utf16(u16 *out, const u8 *in, int len_out, int len_in);

408
arm9/source/crypto/aes.c Normal file
View File

@ -0,0 +1,408 @@
/* original version by megazig */
#include "aes.h"
// FIXME some things make assumptions about alignemnts!
// setup_aeskey? and set_ctr do not anymore (c) d0k3
void setup_aeskeyX(uint8_t keyslot, const void* keyx)
{
uint32_t _keyx[4] __attribute__((aligned(32)));
for (uint32_t i = 0; i < 16u; i++)
((uint8_t*)_keyx)[i] = ((uint8_t*)keyx)[i];
*REG_AESCNT = (*REG_AESCNT) | AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER;
*REG_AESKEYCNT = (*REG_AESKEYCNT >> 6 << 6) | keyslot | 0x80;
if (keyslot > 3) {
*REG_AESKEYXFIFO = _keyx[0];
*REG_AESKEYXFIFO = _keyx[1];
*REG_AESKEYXFIFO = _keyx[2];
*REG_AESKEYXFIFO = _keyx[3];
} else {
uint32_t old_aescnt = *REG_AESCNT;
volatile uint32_t* reg_aeskeyx = REG_AESKEY0123 + (((0x30u * keyslot) + 0x10u)/4u);
*REG_AESCNT = (*REG_AESCNT & ~(AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER));
for (uint32_t i = 0; i < 4u; i++)
reg_aeskeyx[i] = _keyx[i];
*REG_AESCNT = old_aescnt;
}
}
void setup_aeskeyY(uint8_t keyslot, const void* keyy)
{
uint32_t _keyy[4] __attribute__((aligned(32)));
for (uint32_t i = 0; i < 16u; i++)
((uint8_t*)_keyy)[i] = ((uint8_t*)keyy)[i];
*REG_AESCNT = (*REG_AESCNT) | AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER;
*REG_AESKEYCNT = (*REG_AESKEYCNT >> 6 << 6) | keyslot | 0x80;
if (keyslot > 3) {
*REG_AESKEYYFIFO = _keyy[0];
*REG_AESKEYYFIFO = _keyy[1];
*REG_AESKEYYFIFO = _keyy[2];
*REG_AESKEYYFIFO = _keyy[3];
} else {
uint32_t old_aescnt = *REG_AESCNT;
volatile uint32_t* reg_aeskeyy = REG_AESKEY0123 + (((0x30u * keyslot) + 0x20u)/4u);
*REG_AESCNT = (*REG_AESCNT & ~(AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER));
for (uint32_t i = 0; i < 4u; i++)
reg_aeskeyy[i] = _keyy[i];
*REG_AESCNT = old_aescnt;
}
}
void setup_aeskey(uint8_t keyslot, const void* key)
{
uint32_t _key[4] __attribute__((aligned(32)));
for (uint32_t i = 0; i < 16u; i++)
((uint8_t*)_key)[i] = ((uint8_t*)key)[i];
*REG_AESCNT = (*REG_AESCNT) | AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER;
*REG_AESKEYCNT = (*REG_AESKEYCNT >> 6 << 6) | keyslot | 0x80;
if (keyslot > 3) {
*REG_AESKEYFIFO = _key[0];
*REG_AESKEYFIFO = _key[1];
*REG_AESKEYFIFO = _key[2];
*REG_AESKEYFIFO = _key[3];
} else {
uint32_t old_aescnt = *REG_AESCNT;
volatile uint32_t* reg_aeskey = REG_AESKEY0123 + ((0x30u * keyslot)/4u);
*REG_AESCNT = (*REG_AESCNT & ~(AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER));
for (uint32_t i = 0; i < 4u; i++)
reg_aeskey[i] = _key[i];
*REG_AESCNT = old_aescnt;
}
}
void use_aeskey(uint32_t keyno)
{
if (keyno > 0x3F)
return;
*REG_AESKEYSEL = keyno;
*REG_AESCNT = *REG_AESCNT | 0x04000000; /* mystery bit */
}
void set_ctr(void* iv)
{
uint32_t _iv[4] __attribute__((aligned(32)));
for (uint32_t i = 0; i < 16u; i++)
((uint8_t*)_iv)[i] = ((uint8_t*)iv)[i];
*REG_AESCNT = (*REG_AESCNT) | AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER;
*(REG_AESCTR + 0) = _iv[3];
*(REG_AESCTR + 1) = _iv[2];
*(REG_AESCTR + 2) = _iv[1];
*(REG_AESCTR + 3) = _iv[0];
}
void add_ctr(void* ctr, uint32_t carry)
{
uint32_t counter[4];
uint8_t *outctr = (uint8_t *) ctr;
uint32_t sum;
int32_t i;
for(i = 0; i < 4; i++) {
//FIXME this assumes alignment...
counter[i] = ((uint32_t)outctr[i*4+0]<<24) | ((uint32_t)outctr[i*4+1]<<16) | ((uint32_t)outctr[i*4+2]<<8) | ((uint32_t)outctr[i*4+3]<<0);
}
for(i=3; i>=0; i--)
{
sum = counter[i] + carry;
if (sum < counter[i]) {
carry = 1;
}
else {
carry = 0;
}
counter[i] = sum;
}
for(i=0; i<4; i++)
{
outctr[i*4+0] = counter[i]>>24;
outctr[i*4+1] = counter[i]>>16;
outctr[i*4+2] = counter[i]>>8;
outctr[i*4+3] = counter[i]>>0;
}
}
void subtract_ctr(void* ctr, uint32_t carry)
{
//ctr is in big endian format, 16 bytes
uint32_t counter[4];
uint8_t *outctr = (uint8_t *) ctr;
//Convert each 4 byte part of ctr to uint32_t equivalents
for(size_t i = 0; i < 4; i++) {
//FIXME this assumes alignment...
counter[i] = ((uint32_t)outctr[i*4+0]<<24) | ((uint32_t)outctr[i*4+1]<<16) | ((uint32_t)outctr[i*4+2]<<8) | ((uint32_t)outctr[i*4+3]<<0);
}
for(size_t i = 0; i < 4; ++i)
{
uint32_t sub;
//using modular arithmetic to handle carry
sub = counter[3-i] - carry;
carry = counter[3-i] < carry;
counter[3-i] = sub;
}
for(size_t i = 0; i < 4; i++)
{
outctr[i*4+0] = counter[i]>>24;
outctr[i*4+1] = counter[i]>>16;
outctr[i*4+2] = counter[i]>>8;
outctr[i*4+3] = counter[i]>>0;
}
}
void ecb_decrypt(void *inbuf, void *outbuf, size_t size, uint32_t mode)
{
aes_decrypt(inbuf, outbuf, size, mode);
}
void cbc_decrypt(void *inbuf, void *outbuf, size_t size, uint32_t mode, uint8_t *ctr)
{
size_t blocks_left = size;
size_t blocks;
uint8_t *in = inbuf;
uint8_t *out = outbuf;
uint32_t i;
while (blocks_left)
{
set_ctr(ctr);
blocks = (blocks_left >= 0xFFFF) ? 0xFFFF : blocks_left;
for (i=0; i<AES_BLOCK_SIZE; i++)
ctr[i] = in[((blocks - 1) * AES_BLOCK_SIZE) + i];
aes_decrypt(in, out, blocks, mode);
in += blocks * AES_BLOCK_SIZE;
out += blocks * AES_BLOCK_SIZE;
blocks_left -= blocks;
}
}
void cbc_encrypt(void *inbuf, void *outbuf, size_t size, uint32_t mode, uint8_t *ctr)
{
size_t blocks_left = size;
size_t blocks;
uint8_t *in = inbuf;
uint8_t *out = outbuf;
uint32_t i;
while (blocks_left)
{
set_ctr(ctr);
blocks = (blocks_left >= 0xFFFF) ? 0xFFFF : blocks_left;
aes_decrypt(in, out, blocks, mode);
for (i=0; i<AES_BLOCK_SIZE; i++)
ctr[i] = in[((blocks - 1) * AES_BLOCK_SIZE) + i];
in += blocks * AES_BLOCK_SIZE;
out += blocks * AES_BLOCK_SIZE;
blocks_left -= blocks;
}
}
void ctr_decrypt_byte(void *inbuf, void *outbuf, size_t size, size_t off, uint32_t mode, uint8_t *ctr)
{
size_t bytes_left = size;
size_t off_fix = off % AES_BLOCK_SIZE;
uint8_t __attribute__((aligned(32))) temp[AES_BLOCK_SIZE];
uint8_t __attribute__((aligned(32))) ctr_local[AES_BLOCK_SIZE];
uint8_t *in = inbuf;
uint8_t *out = outbuf;
uint32_t i;
for (i=0; i<AES_BLOCK_SIZE; i++) // setup local ctr
ctr_local[i] = ctr[i];
add_ctr(ctr_local, off / AES_BLOCK_SIZE);
if (off_fix) // handle misaligned offset (at beginning)
{
size_t last_byte = ((off_fix + bytes_left) >= AES_BLOCK_SIZE) ?
AES_BLOCK_SIZE : off_fix + bytes_left;
for (i=off_fix; i<last_byte; i++)
temp[i] = *(in++);
ctr_decrypt(temp, temp, 1, mode, ctr_local);
for (i=off_fix; i<last_byte; i++)
*(out++) = temp[i];
bytes_left -= last_byte - off_fix;
}
if (bytes_left >= AES_BLOCK_SIZE)
{
size_t blocks = bytes_left / AES_BLOCK_SIZE;
ctr_decrypt(in, out, blocks, mode, ctr_local);
in += AES_BLOCK_SIZE * blocks;
out += AES_BLOCK_SIZE * blocks;
bytes_left -= AES_BLOCK_SIZE * blocks;
}
if (bytes_left) // handle misaligned offset (at end)
{
for (i=0; i<bytes_left; i++)
temp[i] = *(in++);
ctr_decrypt(temp, temp, 1, mode, ctr_local);
for (i=0; i<bytes_left; i++)
*(out++) = temp[i];
bytes_left = 0;
}
}
void ctr_decrypt(void *inbuf, void *outbuf, size_t size, uint32_t mode, uint8_t *ctr)
{
size_t blocks_left = size;
size_t blocks;
uint8_t *in = inbuf;
uint8_t *out = outbuf;
while (blocks_left)
{
set_ctr(ctr);
blocks = (blocks_left >= 0xFFFF) ? 0xFFFF : blocks_left;
aes_decrypt(in, out, blocks, mode);
add_ctr(ctr, blocks);
in += blocks * AES_BLOCK_SIZE;
out += blocks * AES_BLOCK_SIZE;
blocks_left -= blocks;
}
}
void aes_decrypt(void* inbuf, void* outbuf, size_t size, uint32_t mode)
{
uint8_t *in = inbuf;
uint8_t *out = outbuf;
size_t block_count = size;
size_t blocks;
while (block_count != 0)
{
blocks = (block_count >= 0xFFFF) ? 0xFFFF : block_count;
*REG_AESCNT = 0;
*REG_AESBLKCNT = blocks << 16;
*REG_AESCNT = mode |
AES_CNT_START |
AES_CNT_FLUSH_READ |
AES_CNT_FLUSH_WRITE;
aes_fifos((void*)in, (void*)out, blocks);
in += blocks * AES_BLOCK_SIZE;
out += blocks * AES_BLOCK_SIZE;
block_count -= blocks;
}
}
void aes_cmac(void* inbuf, void* outbuf, size_t size)
{
// only works for full blocks
uint32_t zeroes[4] __attribute__((aligned(32))) = { 0 };
uint32_t xorpad[4] __attribute__((aligned(32))) = { 0 };
uint32_t mode = AES_CBC_ENCRYPT_MODE | AES_CNT_INPUT_ORDER | AES_CNT_OUTPUT_ORDER |
AES_CNT_INPUT_ENDIAN | AES_CNT_OUTPUT_ENDIAN;
uint32_t* out = (uint32_t*) outbuf;
uint32_t* in = (uint32_t*) inbuf;
// create xorpad for last block
set_ctr(zeroes);
aes_decrypt(xorpad, xorpad, 1, mode);
char* xorpadb = (void*) xorpad;
char finalxor = (xorpadb[0] & 0x80) ? 0x87 : 0x00;
for (uint32_t i = 0; i < 15; i++) {
xorpadb[i] <<= 1;
xorpadb[i] |= xorpadb[i+1] >> 7;
}
xorpadb[15] <<= 1;
xorpadb[15] ^= finalxor;
// process blocks
for (uint32_t i = 0; i < 4; i++)
out[i] = 0;
while (size-- > 0) {
for (uint32_t i = 0; i < 4; i++)
out[i] ^= *(in++);
if (!size) { // last block
for (uint32_t i = 0; i < 4; i++)
out[i] ^= xorpad[i];
}
set_ctr(zeroes);
aes_decrypt(out, out, 1, mode);
}
}
void aes_fifos(void* inbuf, void* outbuf, size_t blocks)
{
if (!inbuf || !outbuf) return;
uint8_t *in = inbuf;
uint8_t *out = outbuf;
size_t curblock = 0;
while (curblock != blocks)
{
while (aescnt_checkwrite());
size_t blocks_to_read = blocks - curblock > 4 ? 4 : blocks - curblock;
for (size_t wblocks = 0; wblocks < blocks_to_read; ++wblocks)
for (uint8_t *ii = in + AES_BLOCK_SIZE * wblocks; ii != in + (AES_BLOCK_SIZE * (wblocks + 1)); ii += 4)
{
uint32_t data = ii[0];
data |= (uint32_t)(ii[1]) << 8;
data |= (uint32_t)(ii[2]) << 16;
data |= (uint32_t)(ii[3]) << 24;
set_aeswrfifo(data);
}
if (out)
{
for (size_t rblocks = 0; rblocks < blocks_to_read; ++rblocks)
{
while (aescnt_checkread()) ;
for (uint8_t *ii = out + AES_BLOCK_SIZE * rblocks; ii != out + (AES_BLOCK_SIZE * (rblocks + 1)); ii += 4)
{
uint32_t data = read_aesrdfifo();
ii[0] = data;
ii[1] = data >> 8;
ii[2] = data >> 16;
ii[3] = data >> 24;
}
}
}
in += blocks_to_read * AES_BLOCK_SIZE;
out += blocks_to_read * AES_BLOCK_SIZE;
curblock += blocks_to_read;
}
}
void set_aeswrfifo(uint32_t value)
{
*REG_AESWRFIFO = value;
}
uint32_t read_aesrdfifo(void)
{
return *REG_AESRDFIFO;
}
uint32_t aes_getwritecount()
{
return *REG_AESCNT & 0x1F;
}
uint32_t aes_getreadcount()
{
return (*REG_AESCNT >> 5) & 0x1F;
}
uint32_t aescnt_checkwrite()
{
size_t ret = aes_getwritecount();
return (ret > 0xF);
}
uint32_t aescnt_checkread()
{
size_t ret = aes_getreadcount();
return (ret <= 3);
}

74
arm9/source/crypto/aes.h Normal file
View File

@ -0,0 +1,74 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#define AES_BLOCK_SIZE 0x10
#define AES_CCM_DECRYPT_MODE (0u << 27)
#define AES_CCM_ENCRYPT_MODE (1u << 27)
#define AES_CTR_MODE (2u << 27)
#define AES_CBC_DECRYPT_MODE (4u << 27)
#define AES_CBC_ENCRYPT_MODE (5u << 27)
#define AES_ECB_DECRYPT_MODE (6u << 27)
#define AES_ECB_ENCRYPT_MODE (7u << 27)
#define REG_AESCNT ((volatile uint32_t*)0x10009000)
#define REG_AESBLKCNT ((volatile uint32_t*)0x10009004)
#define REG_AESWRFIFO ((volatile uint32_t*)0x10009008)
#define REG_AESRDFIFO ((volatile uint32_t*)0x1000900C)
#define REG_AESKEYSEL ((volatile uint8_t *)0x10009010)
#define REG_AESKEYCNT ((volatile uint8_t *)0x10009011)
#define REG_AESCTR ((volatile uint32_t*)0x10009020)
#define REG_AESKEYFIFO ((volatile uint32_t*)0x10009100)
#define REG_AESKEYXFIFO ((volatile uint32_t*)0x10009104)
#define REG_AESKEYYFIFO ((volatile uint32_t*)0x10009108)
#define REG_AESMAC ((volatile uint32_t*)0x10009030)
// see https://www.3dbrew.org/wiki/AES_Registers#AES_KEY0.2F1.2F2.2F3
#define REG_AESKEY0123 ((volatile uint32_t*)0x10009040)
#define AES_CNT_START 0x80000000u
#define AES_CNT_INPUT_ORDER 0x02000000u
#define AES_CNT_OUTPUT_ORDER 0x01000000u
#define AES_CNT_INPUT_ENDIAN 0x00800000u
#define AES_CNT_OUTPUT_ENDIAN 0x00400000u
#define AES_CNT_FLUSH_READ 0x00000800u
#define AES_CNT_FLUSH_WRITE 0x00000400u
#define AES_CNT_CTRNAND_MODE (AES_CTR_MODE | AES_CNT_INPUT_ORDER | AES_CNT_OUTPUT_ORDER | AES_CNT_INPUT_ENDIAN | AES_CNT_OUTPUT_ENDIAN)
#define AES_CNT_TWLNAND_MODE AES_CTR_MODE
#define AES_CNT_TITLEKEY_DECRYPT_MODE (AES_CBC_DECRYPT_MODE | AES_CNT_INPUT_ORDER | AES_CNT_OUTPUT_ORDER | AES_CNT_INPUT_ENDIAN | AES_CNT_OUTPUT_ENDIAN)
#define AES_CNT_TITLEKEY_ENCRYPT_MODE (AES_CBC_ENCRYPT_MODE | AES_CNT_INPUT_ORDER | AES_CNT_OUTPUT_ORDER | AES_CNT_INPUT_ENDIAN | AES_CNT_OUTPUT_ENDIAN)
#define AES_CNT_ECB_DECRYPT_MODE (AES_ECB_DECRYPT_MODE | AES_CNT_INPUT_ORDER | AES_CNT_OUTPUT_ORDER | AES_CNT_INPUT_ENDIAN | AES_CNT_OUTPUT_ENDIAN)
#define AES_CNT_ECB_ENCRYPT_MODE (AES_ECB_ENCRYPT_MODE | AES_CNT_INPUT_ORDER | AES_CNT_OUTPUT_ORDER | AES_CNT_INPUT_ENDIAN | AES_CNT_OUTPUT_ENDIAN)
void setup_aeskeyX(uint8_t keyslot, const void* keyx);
void setup_aeskeyY(uint8_t keyslot, const void* keyy);
void setup_aeskey(uint8_t keyslot, const void* keyy);
void use_aeskey(uint32_t keyno);
void set_ctr(void* iv);
void add_ctr(void* ctr, uint32_t carry);
void subtract_ctr(void* ctr, uint32_t carry);
void aes_decrypt(void* inbuf, void* outbuf, size_t size, uint32_t mode);
void ctr_decrypt(void* inbuf, void* outbuf, size_t size, uint32_t mode, uint8_t *ctr);
void ctr_decrypt_byte(void *inbuf, void *outbuf, size_t size, size_t off, uint32_t mode, uint8_t *ctr);
void ecb_decrypt(void *inbuf, void *outbuf, size_t size, uint32_t mode);
void cbc_decrypt(void *inbuf, void *outbuf, size_t size, uint32_t mode, uint8_t *ctr);
void cbc_encrypt(void *inbuf, void *outbuf, size_t size, uint32_t mode, uint8_t *ctr);
void aes_cmac(void* inbuf, void* outbuf, size_t size);
void aes_fifos(void* inbuf, void* outbuf, size_t blocks);
void set_aeswrfifo(uint32_t value);
uint32_t read_aesrdfifo(void);
uint32_t aes_getwritecount(void);
uint32_t aes_getreadcount(void);
uint32_t aescnt_checkwrite(void);
uint32_t aescnt_checkread(void);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,26 @@
#include "crc16.h"
#define CRC16_TABVAL \
0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401, \
0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
// see: https://github.com/TASVideos/desmume/blob/master/desmume/src/bios.cpp#L1070tions
u16 crc16_quick(const void* src, u32 len) {
static const u16 tabval[] = { CRC16_TABVAL };
u16* data = (u16*) src;
u16 crc = 0xFFFF;
for (len >>= 1; len; len--) {
u16 curr = *(data++);
for (u32 i = 0; i < 4; i++) {
u16 tval = tabval[crc&0xF];
crc >>= 4;
crc ^= tval;
tval = tabval[(curr >> (4*i))&0xF];
crc ^= tval;
}
}
return crc;
}

View File

@ -0,0 +1,5 @@
#pragma once
#include "common.h"
u16 crc16_quick(const void* src, u32 len);

View File

@ -0,0 +1,90 @@
// C port of byuu's \nall\crc32.hpp, which was released under GPLv3
// https://github.com/eai04191/beat/blob/master/nall/crc32.hpp
// Ported by Hyarion for use with VirtualFatFS
#include "common.h"
#include "crc32.h"
#include "vff.h"
u32 crc32_adjust(u32 crc32, u8 input) {
static const u32 crc32_table[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
return ((crc32 >> 8) & 0x00ffffff) ^ crc32_table[(crc32 ^ input) & 0xff];
}
u32 crc32_calculate(u32 crc32, const u8* data, u32 length) {
for(unsigned i = 0; i < length; i++) {
crc32 = crc32_adjust(crc32, data[i]);
}
return crc32;
}
u32 crc32_calculate_from_file(const char* fileName, u32 offset, u32 length) {
FIL inputFile;
u32 crc32 = ~0;
u32 bufsiz = min(STD_BUFFER_SIZE, length);
u8* buffer = (u8*) malloc(bufsiz);
if (!buffer) return false;
if (fvx_open(&inputFile, fileName, FA_READ) != FR_OK) {
free(buffer);
return crc32;
}
fvx_lseek(&inputFile, offset);
bool ret = true;
for (u64 pos = 0; (pos < length) && ret; pos += bufsiz) {
UINT read_bytes = min(bufsiz, length - pos);
UINT bytes_read = read_bytes;
if ((fvx_read(&inputFile, buffer, read_bytes, &bytes_read) != FR_OK) ||
(read_bytes != bytes_read))
ret = false;
if (ret) crc32 = crc32_calculate(crc32, buffer, read_bytes);
}
fvx_close(&inputFile);
free(buffer);
return ~crc32;
}

View File

@ -0,0 +1,11 @@
// C port of byuu's \nall\crc32.hpp, which was released under GPLv3
// https://github.com/eai04191/beat/blob/master/nall/crc32.hpp
// Ported by Hyarion for use with VirtualFatFS
#pragma once
#include "common.h"
u32 crc32_adjust(u32 crc32, u8 input);
u32 crc32_calculate(u32 crc32, const u8* data, u32 length);
u32 crc32_calculate_from_file(const char* fileName, u32 offset, u32 length);

231
arm9/source/crypto/keydb.c Normal file
View File

@ -0,0 +1,231 @@
#include "keydb.h"
#include "aes.h"
#include "sha.h"
#include "vff.h"
#include "support.h"
typedef struct {
u8 slot; // keyslot, 0x00...0x39
u8 keyUnitType; // 0 for ALL units / 1 for devkit exclusive / 2 for retail exclusive
u8 sample[16]; // sample data, encoded with src = keyY = ctr = { 0 }
} PACKED_STRUCT AesNcchSampleInfo;
static u64 keyState = 0;
static u64 keyXState = 0;
static u64 keyYState = 0;
u32 GetUnitKeysType(void)
{
static u32 keys_type = KEYS_UNKNOWN;
if (keys_type == KEYS_UNKNOWN) {
static const u8 slot0x2CSampleRetail[16] = {
0xBC, 0xC4, 0x16, 0x2C, 0x2A, 0x06, 0x91, 0xEE, 0x47, 0x18, 0x86, 0xB8, 0xEB, 0x2F, 0xB5, 0x48 };
static const u8 slot0x2CSampleDevkit[16] = {
0x29, 0xB5, 0x5D, 0x9F, 0x61, 0xAC, 0xD2, 0x28, 0x22, 0x23, 0xFB, 0x57, 0xDD, 0x50, 0x8A, 0xF5 };
static u8 zeroes[16] = { 0 };
u8 sample[16] = { 0 };
setup_aeskeyY(0x2C, zeroes);
use_aeskey(0x2C);
set_ctr(zeroes);
aes_decrypt(sample, sample, 1, AES_CNT_CTRNAND_MODE);
if (memcmp(sample, slot0x2CSampleRetail, 16) == 0) {
keys_type = KEYS_RETAIL;
} else if (memcmp(sample, slot0x2CSampleDevkit, 16) == 0) {
keys_type = KEYS_DEVKIT;
}
}
return keys_type;
}
void CryptAesKeyInfo(AesKeyInfo* info) {
static const u8 zeros[16] = { 0 };
static const u8 keyY_dev[16] = {
0xA2, 0x32, 0x4A, 0x7E, 0x7C, 0xE6, 0x1A, 0x9A, 0x45, 0x4A, 0x52, 0x19, 0xB3, 0x5B, 0xE9, 0x3B };
const u8* aeskeyY = GetUnitKeysType() == KEYS_DEVKIT ? &keyY_dev[0] : &zeros[0];
u8 ctr[16] = { 0 };
memcpy(ctr, (void*) info, 12); // CTR -> slot + type + id + zeroes
setup_aeskeyY(0x2C, aeskeyY);
use_aeskey(0x2C);
set_ctr(ctr);
aes_decrypt(info->key, info->key, 1, AES_CNT_CTRNAND_MODE);
info->isEncrypted = !info->isEncrypted;
}
u32 CheckKeySlot(u32 keyslot, char type)
{
static const AesNcchSampleInfo keyNcchSamples[] = {
{ 0x18, KEYS_RETAIL, // Retail NCCH Secure3
{ 0x78, 0xBB, 0x84, 0xFA, 0xB3, 0xA2, 0x49, 0x83, 0x9E, 0x4F, 0x50, 0x7B, 0x17, 0xA0, 0xDA, 0x23 } },
{ 0x1B, KEYS_RETAIL, // Retail NCCH Secure4
{ 0xF3, 0x6F, 0x84, 0x7E, 0x59, 0x43, 0x6E, 0xD5, 0xA0, 0x40, 0x4C, 0x71, 0x19, 0xED, 0xF7, 0x0A } },
{ 0x25, KEYS_RETAIL, // Retail NCCH 7x
{ 0x34, 0x7D, 0x07, 0x48, 0xAE, 0x5D, 0xFB, 0xB0, 0xF5, 0x86, 0xD6, 0xB5, 0x14, 0x65, 0xF1, 0xFF } },
{ 0x18, KEYS_DEVKIT, // DevKit NCCH Secure3
{ 0x20, 0x8B, 0xB5, 0x61, 0x94, 0x18, 0x6A, 0x84, 0x91, 0xD6, 0x37, 0x27, 0x91, 0xF3, 0x53, 0xC9 } },
{ 0x1B, KEYS_DEVKIT, // DevKit NCCH Secure4
{ 0xB3, 0x9D, 0xC1, 0xDB, 0x5B, 0x0C, 0xE7, 0x60, 0xBE, 0xAD, 0x5A, 0xBF, 0xD0, 0x86, 0x99, 0x88 } },
{ 0x25, KEYS_DEVKIT, // DevKit NCCH 7x
{ 0xBC, 0x83, 0x7C, 0xC9, 0x99, 0xC8, 0x80, 0x9E, 0x8A, 0xDE, 0x4A, 0xFA, 0xAA, 0x72, 0x08, 0x28 } }
};
u64* state = (type == 'X') ? &keyXState : (type == 'Y') ? &keyYState : (type == 'N') ? &keyState : NULL;
// just to be safe...
if (keyslot >= 0x40)
return 1;
// check if key is already loaded
if ((type != 'I') && ((*state >> keyslot) & 1))
return 0;
// if is not, we may still be able to verify the currently set one (for NCCH keys)
for (u32 p = 0; (type == 'X') && (p < sizeof(keyNcchSamples) / sizeof(AesNcchSampleInfo)); p++) {
if (keyNcchSamples[p].slot != keyslot) // only for keyslots in the keyNcchSamples table!
continue;
if (keyNcchSamples[p].keyUnitType && (keyNcchSamples[p].keyUnitType != GetUnitKeysType()))
continue;
u8 zeroes[16] = { 0 };
u8 sample[16] = { 0 };
setup_aeskeyY(keyslot, zeroes);
use_aeskey(keyslot);
set_ctr(zeroes);
aes_decrypt(sample, sample, 1, AES_CNT_CTRNAND_MODE);
if (memcmp(keyNcchSamples[p].sample, sample, 16) == 0) {
keyXState |= 1ull << keyslot;
return 0;
}
}
// not set up if getting here
return 1;
}
// this function creates dependencies to "vff.h" and "support.h"
// to get rid of these, you may replace this function with anything that works for you
u32 LoadKeyDb(const char* path_db, AesKeyInfo* keydb, u32 bsize) {
UINT fsize = 0;
if (path_db) {
if (fvx_qread (path_db, keydb, 0, bsize, &fsize) != FR_OK) fsize = 0;
} else if (fvx_qread ("S:/" KEYDB_NAME, keydb, 0, bsize, &fsize) != FR_OK) {
fsize = LoadSupportFile(KEYDB_NAME, keydb, bsize); // load key database support file
}
u32 nkeys = 0;
if (fsize && !(fsize % sizeof(AesKeyInfo)))
nkeys = fsize / sizeof(AesKeyInfo);
return nkeys;
}
u32 LoadKeyFromFile(void* key, u32 keyslot, char type, char* id)
{
u8 keystore[16] __attribute__((aligned(32))) = {0};
bool found = false;
// checking the obvious
if ((keyslot >= 0x40) || ((type != 'X') && (type != 'Y') && (type != 'N') && (type != 'I')))
return 1;
// check if already loaded
if (!key && !id && (CheckKeySlot(keyslot, type) == 0)) return 0;
// use keystore if key == NULL
if (!key) key = keystore;
// try to get key from 'aeskeydb.bin' file
AesKeyInfo* keydb = (AesKeyInfo*) malloc(STD_BUFFER_SIZE);
u32 nkeys = (keydb) ? LoadKeyDb(NULL, keydb, STD_BUFFER_SIZE) : 0;
for (u32 i = 0; i < nkeys; i++) {
AesKeyInfo* info = &(keydb[i]);
if (!((info->slot == keyslot) && (info->type == type) &&
((!id && !(info->id[0])) || (id && (strncmp(id, info->id, 10) == 0))) &&
(!info->keyUnitType || (info->keyUnitType == GetUnitKeysType()))))
continue;
found = true;
if (info->isEncrypted)
CryptAesKeyInfo(info);
memcpy(key, info->key, 16);
break;
}
free(keydb);
// load legacy slot0x??Key?.bin file instead
if (!found && (type != 'I')) {
char fname[64];
snprintf(fname, sizeof(fname), "slot0x%02lXKey%s%s.bin", keyslot,
(type == 'X') ? "X" : (type == 'Y') ? "Y" : (type == 'I') ? "IV" : "", (id) ? id : "");
found = (LoadSupportFile(fname, key, 16) == 16);
}
// key still not found (duh)
if (!found) return 1; // out of options here
// done if this is an IV
if (type == 'I') return 0;
// now, setup the key
if (type == 'X') {
setup_aeskeyX(keyslot, key);
keyXState |= 1ull << keyslot;
} else if (type == 'Y') {
setup_aeskeyY(keyslot, key);
keyYState |= 1ull << keyslot;
} else { // normalKey includes keyX & keyY
setup_aeskey(keyslot, key);
keyState |= 1ull << keyslot;
keyXState |= 1ull << keyslot;
keyYState |= 1ull << keyslot;
}
use_aeskey(keyslot);
return 0;
}
u32 InitKeyDb(const char* path)
{
// use this to quickly initialize all applicable keys in aeskeydb.bin
static const u64 keyslot_whitelist = (1ull<<0x02)|(1ull<<0x03)|(1ull<<0x05)|(1ull<<0x18)|(1ull<<0x19)|(1ull<<0x1A)|(1ull<<0x1B)|
(1ull<<0x1C)|(1ull<<0x1D)|(1ull<<0x1E)|(1ull<<0x1F)|(1ull<<0x24)|(1ull<<0x25)|(1ull<<0x2F);
// try to load aeskeydb.bin file
AesKeyInfo* keydb = (AesKeyInfo*) malloc(STD_BUFFER_SIZE);
u32 nkeys = (keydb) ? LoadKeyDb(path, keydb, STD_BUFFER_SIZE) : 0;
// apply all applicable keys
for (u32 i = 0; i < nkeys; i++) {
AesKeyInfo* info = &(keydb[i]);
if ((info->slot >= 0x40) || ((info->type != 'X') && (info->type != 'Y') && (info->type != 'N') && (info->type != 'I'))) {
free(keydb);
return 1; // looks faulty, better stop right here
}
if (!path && !((1ull<<info->slot)&keyslot_whitelist)) continue; // not in keyslot whitelist
if ((info->type == 'I') || (*(info->id)) || (info->keyUnitType && (info->keyUnitType != GetUnitKeysType())) ||
(CheckKeySlot(info->slot, info->type) == 0)) continue; // most likely valid, but not applicable or already set
if (info->isEncrypted) CryptAesKeyInfo(info); // decrypt key
// apply key
u8 key[16] __attribute__((aligned(32))) = {0};
char type = info->type;
u32 keyslot = info->slot;
memcpy(key, info->key, 16);
if (type == 'X') {
setup_aeskeyX(keyslot, key);
keyXState |= 1ull << keyslot;
} else if (type == 'Y') {
setup_aeskeyY(keyslot, key);
keyYState |= 1ull << keyslot;
} else { // normalKey includes keyX & keyY
setup_aeskey(keyslot, key);
keyState |= 1ull << keyslot;
keyXState |= 1ull << keyslot;
keyYState |= 1ull << keyslot;
}
use_aeskey(keyslot);
}
free(keydb);
return (nkeys) ? 0 : 1;
}

View File

@ -0,0 +1,32 @@
#pragma once
#include "common.h"
#define KEYDB_NAME "aeskeydb.bin"
// SHA-256 and size of the recommended aeskeydb.bin file
// equals MD5 A5B28945A7C051D7A0CD18AF0E580D1B / 1024 byte
#define KEYDB_PERFECT_HASH \
0x40, 0x76, 0x54, 0x3D, 0xA3, 0xFF, 0x91, 0x1C, 0xE1, 0xCC, 0x4E, 0xC7, 0x2F, 0x92, 0xE4, 0xB7, \
0x2B, 0x24, 0x00, 0x15, 0xBE, 0x9B, 0xFC, 0xDE, 0x7F, 0xED, 0x95, 0x1D, 0xD5, 0xAB, 0x2D, 0xCB
#define KEYDB_PERFECT_SIZE (32 * sizeof(AesKeyInfo)) // 32 keys contained
#define KEYS_UNKNOWN 0
#define KEYS_DEVKIT 1
#define KEYS_RETAIL 2
typedef struct {
u8 slot; // keyslot, 0x00...0x3F
char type; // type 'X' / 'Y' / 'N' for normalKey / 'I' for IV
char id[10]; // key ID for special keys, all zero for standard keys
u8 reserved[2]; // reserved space
u8 keyUnitType; // 0 for ALL units / 1 for devkit exclusive / 2 for retail exclusive
u8 isEncrypted; // 0 if not / anything else if it is
u8 key[16];
} PACKED_STRUCT __attribute__((aligned(16))) AesKeyInfo;
u32 GetUnitKeysType(void);
void CryptAesKeyInfo(AesKeyInfo* info);
u32 LoadKeyFromFile(void* key, u32 keyslot, char type, char* id);
u32 InitKeyDb(const char* path);

120
arm9/source/crypto/rsa.c Normal file
View File

@ -0,0 +1,120 @@
/*
* This file is part of fastboot 3DS
* Copyright (C) 2017 derrek, profi200
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common.h"
#include "rsa.h"
#include "sha.h"
#include "mmio.h"
//////////////////////////////////
// RSA //
//////////////////////////////////
#define RSA_REGS_BASE (0x10000000 + 0xB000)
#define REG_RSA_CNT *((vu32*)(RSA_REGS_BASE + 0x000))
#define REG_RSA_UNK_F0 *((vu32*)(RSA_REGS_BASE + 0x0F0))
#define REGs_RSA_SLOT0 ((vu32*)(RSA_REGS_BASE + 0x100))
#define REGs_RSA_SLOT1 ((vu32*)(RSA_REGS_BASE + 0x110))
#define REGs_RSA_SLOT2 ((vu32*)(RSA_REGS_BASE + 0x120))
#define REGs_RSA_SLOT3 ((vu32*)(RSA_REGS_BASE + 0x130))
#define rsaSlots ((RsaSlot*)(RSA_REGS_BASE + 0x100))
#define REGs_RSA_EXP ((vu32*)(RSA_REGS_BASE + 0x200))
#define REGs_RSA_MOD ((vu32*)(RSA_REGS_BASE + 0x400))
#define REGs_RSA_TXT ((vu32*)(RSA_REGS_BASE + 0x800))
typedef struct
{
vu32 REG_RSA_SLOTCNT;
vu32 REG_RSA_SLOTSIZE;
vu32 REG_RSA_SLOT_UNK_0x8;
vu32 REG_RSA_SLOT_UNK_0xC;
} RsaSlot;
void RSA_init(void)
{
REG_RSA_UNK_F0 = 0;
}
static void rsaWaitBusy(void)
{
while(REG_RSA_CNT & RSA_ENABLE);
}
void RSA_selectKeyslot(u8 keyslot)
{
rsaWaitBusy();
REG_RSA_CNT = (REG_RSA_CNT & ~RSA_KEYSLOT(0xFu)) | RSA_KEYSLOT(keyslot);
}
bool RSA_setKey2048(u8 keyslot, const u32 *const mod, u32 exp)
{
RsaSlot *slot = &rsaSlots[keyslot];
rsaWaitBusy();
if(slot->REG_RSA_SLOTCNT & RSA_KEY_WR_PROT) return false;
// Unset key if bit 31 is not set. No idea why but boot9 does this.
if(!(slot->REG_RSA_SLOTCNT & RSA_KEY_UNK_BIT31)) slot->REG_RSA_SLOTCNT &= ~RSA_KEY_STAT_SET;
REG_RSA_CNT = RSA_INPUT_NORMAL | RSA_INPUT_BIG | RSA_KEYSLOT(keyslot);
iomemset(REGs_RSA_EXP, 0, 0x100 - 4);
REGs_RSA_EXP[(0x100>>2) - 1] = exp;
if(slot->REG_RSA_SLOTSIZE != RSA_SLOTSIZE_2048) return false;
iomemcpy(REGs_RSA_MOD, mod, 0x100);
return true;
}
bool RSA_decrypt2048(u32 *const decSig, const u32 *const encSig)
{
const u8 keyslot = RSA_GET_KEYSLOT;
rsaWaitBusy();
if(!(rsaSlots[keyslot].REG_RSA_SLOTCNT & RSA_KEY_STAT_SET)) return false;
REG_RSA_CNT |= RSA_INPUT_NORMAL | RSA_INPUT_BIG;
iomemcpy(REGs_RSA_TXT, encSig, 0x100);
REG_RSA_CNT |= RSA_ENABLE;
rsaWaitBusy();
iomemcpy(decSig, REGs_RSA_TXT, 0x100);
return true;
}
bool RSA_verify2048(const u32 *const encSig, const u32 *const data, u32 size)
{
alignas(4) u8 decSig[0x100];
if(!RSA_decrypt2048((u32*)(void*)decSig, encSig)) return false;
if(decSig[0] != 0x00 || decSig[1] != 0x01) return false;
u32 read = 2;
while(read < 0x100)
{
if(decSig[read] != 0xFF) break;
read++;
}
if(read != 0xCC || decSig[read] != 0x00) return false;
// ASN.1 is a clusterfuck so we skip parsing the remaining headers
// and hardcode the hash location.
return sha_cmp(&(decSig[0xE0]), data, size, SHA256_MODE) == 0;
}

91
arm9/source/crypto/rsa.h Normal file
View File

@ -0,0 +1,91 @@
#pragma once
/*
* This file is part of fastboot 3DS
* Copyright (C) 2017 derrek, profi200
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common.h"
//////////////////////////////////
// RSA //
//////////////////////////////////
// REG_RSA_CNT
#define RSA_ENABLE (1u)
#define RSA_UNK_BIT1 (1u<<1)
#define RSA_KEYSLOT(k) ((k)<<4)
#define RSA_GET_KEYSLOT ((REG_RSA_CNT & RSA_KEYSLOT(0xFu))>>4)
#define RSA_INPUT_BIG (1u<<8)
#define RSA_INPUT_LITTLE (0u)
#define RSA_INPUT_NORMAL (1u<<9)
#define RSA_INPUT_REVERSED (0u)
// RSA_SLOTCNT
#define RSA_KEY_STAT_SET (1u)
#define RSA_KEY_WR_PROT (1u<<1)
#define RSA_KEY_UNK_BIT31 (1u<<31)
// RSA_SLOTSIZE
#define RSA_SLOTSIZE_2048 (0x40u)
/**
* @brief Initializes the RSA hardware.
*/
void RSA_init(void);
/**
* @brief Selects the given keyslot for all following RSA operations.
*
* @param[in] keyslot The keyslot to select.
*/
void RSA_selectKeyslot(u8 keyslot);
/**
* @brief Sets a RSA modulus + exponent in the specified keyslot.
*
* @param[in] keyslot The keyslot this key will be set for.
* @param[in] mod Pointer to 2048-bit RSA modulus data.
* @param[in] exp The exponent to set.
*
* @return Returns true on success, false otherwise.
*/
bool RSA_setKey2048(u8 keyslot, const u32 *const mod, u32 exp);
/**
* @brief Decrypts a RSA 2048 signature.
*
* @param decSig Pointer to decrypted destination signature.
* @param[in] encSig Pointer to encrypted source signature.
*
* @return Returns true on success, false otherwise.
*/
bool RSA_decrypt2048(u32 *const decSig, const u32 *const encSig);
/**
* @brief Verifies a RSA 2048 SHA 256 signature.
* @brief Note: This function skips the ASN.1 data and is therefore not safe.
*
* @param[in] encSig Pointer to encrypted source signature.
* @param[in] data Pointer to the data to hash.
* @param[in] size The hash data size.
*
* @return Returns true if the signature is valid, false otherwise.
*/
bool RSA_verify2048(const u32 *const encSig, const u32 *const data, u32 size);

48
arm9/source/crypto/sha.c Normal file
View File

@ -0,0 +1,48 @@
#include "sha.h"
#include "mmio.h"
typedef struct
{
u32 data[16];
} _sha_block;
void sha_init(u32 mode)
{
while(*REG_SHACNT & 1);
*REG_SHACNT = mode | SHA_CNT_OUTPUT_ENDIAN | SHA_NORMAL_ROUND;
}
void sha_update(const void* src, u32 size)
{
const u32* src32 = (const u32*)src;
while(size >= 0x40) {
while(*REG_SHACNT & 1);
*((volatile _sha_block*)REG_SHAINFIFO) = *((const _sha_block*)src32);
src32 += 16;
size -= 0x40;
}
while(*REG_SHACNT & 1);
if(size) iomemcpy((void*)REG_SHAINFIFO, src32, size);
}
void sha_get(void* res) {
u32 hash_size = (*REG_SHACNT&SHA224_MODE) ? (224/8) :
(*REG_SHACNT&SHA1_MODE) ? (160/8) : (256/8);
*REG_SHACNT = (*REG_SHACNT & ~SHA_NORMAL_ROUND) | SHA_FINAL_ROUND;
while(*REG_SHACNT & SHA_FINAL_ROUND);
while(*REG_SHACNT & 1);
if (hash_size) iomemcpy(res, (void*)REG_SHAHASH, hash_size);
}
void sha_quick(void* res, const void* src, u32 size, u32 mode) {
sha_init(mode);
sha_update(src, size);
sha_get(res);
}
int sha_cmp(const void* sha, const void* src, u32 size, u32 mode) {
u8 res[0x20];
sha_quick(res, src, size, mode);
return memcmp(sha, res, 0x20);
}

View File

@ -4,8 +4,8 @@
#define REG_SHACNT ((volatile uint32_t*)0x1000A000)
#define REG_SHABLKCNT ((volatile uint32_t*)0x1000A004)
#define REG_SHAHASH ((volatile uint32_t*)0x1000A040)
#define REG_SHAINFIFO ((volatile uint32_t*)0x1000A080)
#define REG_SHAHASH (( uint32_t*)0x1000A040)
#define REG_SHAINFIFO ( 0x1000A080)
#define SHA_CNT_STATE 0x00000003
#define SHA_CNT_OUTPUT_ENDIAN 0x00000008
@ -25,3 +25,5 @@
void sha_init(u32 mode);
void sha_update(const void* src, u32 size);
void sha_get(void* res);
void sha_quick(void* res, const void* src, u32 size, u32 mode);
int sha_cmp(const void* sha, const void* src, u32 size, u32 mode);

View File

@ -3,73 +3,98 @@
----------------------------------------------------------------------------
R0.00 (February 26, 2006)
Prototype.
R0.01 (April 29, 2006)
First stable version.
The first release.
R0.02 (June 01, 2006)
Added FAT12 support.
Removed unbuffered mode.
Fixed a problem on small (<32M) partition.
R0.02a (June 10, 2006)
Added a configuration option (_FS_MINIMUM).
R0.03 (September 22, 2006)
Added f_rename().
Changed option _FS_MINIMUM to _FS_MINIMIZE.
R0.03a (December 11, 2006)
Improved cluster scan algorithm to write files fast.
Fixed f_mkdir() creates incorrect directory on FAT32.
R0.04 (February 04, 2007)
Added f_mkfs().
Supported multiple drive system.
Changed some interfaces for multiple drive system.
Changed f_mountdrv() to f_mount().
R0.04a (April 01, 2007)
Supported multiple partitions on a physical drive.
Added a capability of extending file size to f_lseek().
Added minimization level 3.
Fixed an endian sensitive code in f_mkfs().
R0.04b (May 05, 2007)
Added a configuration option _USE_NTFLAG.
Added FSINFO support.
Fixed DBCS name can result FR_INVALID_NAME.
Fixed short seek (<= csize) collapses the file object.
R0.05 (August 25, 2007)
Changed arguments of f_read(), f_write() and f_mkfs().
Fixed f_mkfs() on FAT32 creates incorrect FSINFO.
Fixed f_mkdir() on FAT32 creates incorrect directory.
R0.05a (February 03, 2008)
Added f_truncate() and f_utime().
Fixed off by one error at FAT sub-type determination.
Fixed btr in f_read() can be mistruncated.
Fixed cached sector is not flushed when create and close without write.
R0.06 (April 01, 2008)
Added fputc(), fputs(), fprintf() and fgets().
Improved performance of f_lseek() on moving to the same or following cluster.
R0.07 (April 01, 2009)
Merged Tiny-FatFs as a configuration option. (_FS_TINY)
Added long file name feature. (_USE_LFN)
Added multiple code page feature. (_CODE_PAGE)
@ -80,12 +105,16 @@ R0.07 (April 01, 2009)
Renamed string functions to avoid name collision.
R0.07a (April 14, 2009)
Septemberarated out OS dependent code on reentrant cfg.
Added multiple sector size feature.
R0.07c (June 21, 2009)
Fixed f_unlink() can return FR_OK on error.
Fixed wrong cache control in f_lseek().
Added relative path feature.
@ -93,7 +122,9 @@ R0.07c (June 21, 2009)
Added proper case conversion to extended character.
R0.07e (November 03, 2009)
Septemberarated out configuration options from ff.h to ffconf.h.
Fixed f_unlink() fails to remove a sub-directory on _FS_RPATH.
Fixed name matching error on the 13 character boundary.
@ -101,7 +132,9 @@ R0.07e (November 03, 2009)
Changed f_readdir() to return the SFN with always upper case on non-LFN cfg.
R0.08 (May 15, 2010)
Added a memory configuration option. (_USE_LFN = 3)
Added file lock feature. (_FS_SHARE)
Added fast seek feature. (_USE_FASTSEEK)
@ -110,36 +143,48 @@ R0.08 (May 15, 2010)
String functions support UTF-8 encoding files on Unicode cfg.
R0.08a (August 16, 2010)
Added f_getcwd(). (_FS_RPATH = 2)
Added sector erase feature. (_USE_ERASE)
Moved file lock semaphore table from fs object to the bss.
Fixed f_mkfs() creates wrong FAT32 volume.
R0.08b (January 15, 2011)
Fast seek feature is also applied to f_read() and f_write().
f_lseek() reports required table size on creating CLMP.
Extended format syntax of f_printf().
Ignores duplicated directory separators in given path name.
R0.09 (September 06, 2011)
f_mkfs() supports multiple partition to complete the multiple partition feature.
Added f_fdisk().
R0.09a (August 27, 2012)
Changed f_open() and f_opendir() reject null object pointer to avoid crash.
Changed option name _FS_SHARE to _FS_LOCK.
Fixed assertion failure due to OS/2 EA on FAT12/16 volume.
R0.09b (January 24, 2013)
Added f_setlabel() and f_getlabel().
R0.10 (October 02, 2013)
Added selection of character encoding on the file. (_STRF_ENCODE)
Added f_closedir().
Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO)
@ -148,10 +193,12 @@ R0.10 (October 02, 2013)
Improved write throughput of f_puts() and f_printf().
Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write().
Fixed f_write() can be truncated when the file size is close to 4GB.
Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect error code.
Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect value on error.
R0.10a (January 15, 2014)
Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
Added a configuration option of minimum sector size. (_MIN_SS)
2nd argument of f_rename() can have a drive number and it will be ignored.
@ -161,12 +208,16 @@ R0.10a (January 15, 2014)
Fixed creation of an entry with LFN fails on too many SFN collisions. (appeared at R0.07)
R0.10b (May 19, 2014)
Fixed a hard error in the disk I/O layer can collapse the directory entry.
Fixed LFN entry is not deleted on delete/rename an object with lossy converted SFN. (appeared at R0.07)
Fixed LFN entry is not deleted when delete/rename an object with lossy converted SFN. (appeared at R0.07)
R0.10c (November 09, 2014)
Added a configuration option for the platforms without RTC. (_FS_NORTC)
Changed option name _USE_ERASE to _USE_TRIM.
Fixed volume label created by Mac OS X cannot be retrieved with f_getlabel(). (appeared at R0.09b)
@ -174,7 +225,116 @@ R0.10c (November 09, 2014)
Fixed null pointer dereference on attempting to delete the root direcotry. (appeared at R0.08)
R0.11 (February 09, 2015)
Added f_findfirst(), f_findnext() and f_findclose(). (_USE_FIND)
Fixed f_unlink() does not remove cluster chain of the file. (appeared at R0.10c)
Fixed _FS_NORTC option does not work properly. (appeared at R0.10c)
R0.11a (September 05, 2015)
Fixed wrong media change can lead a deadlock at thread-safe configuration.
Added code page 771, 860, 861, 863, 864, 865 and 869. (_CODE_PAGE)
Removed some code pages actually not exist on the standard systems. (_CODE_PAGE)
Fixed errors in the case conversion teble of code page 437 and 850 (ff.c).
Fixed errors in the case conversion teble of Unicode (cc*.c).
R0.12 (April 12, 2016)
Added support for exFAT file system. (_FS_EXFAT)
Added f_expand(). (_USE_EXPAND)
Changed some members in FINFO structure and behavior of f_readdir().
Added an option _USE_CHMOD.
Removed an option _WORD_ACCESS.
Fixed errors in the case conversion table of Unicode (cc*.c).
R0.12a (July 10, 2016)
Added support for creating exFAT volume with some changes of f_mkfs().
Added a file open method FA_OPEN_APPEND. An f_lseek() following f_open() is no longer needed.
f_forward() is available regardless of _FS_TINY.
Fixed f_mkfs() creates wrong volume. (appeared at R0.12)
Fixed wrong memory read in create_name(). (appeared at R0.12)
Fixed compilation fails at some configurations, _USE_FASTSEEK and _USE_FORWARD.
R0.12b (September 04, 2016)
Made f_rename() be able to rename objects with the same name but case.
Fixed an error in the case conversion teble of code page 866. (ff.c)
Fixed writing data is truncated at the file offset 4GiB on the exFAT volume. (appeared at R0.12)
Fixed creating a file in the root directory of exFAT volume can fail. (appeared at R0.12)
Fixed f_mkfs() creating exFAT volume with too small cluster size can collapse unallocated memory. (appeared at R0.12)
Fixed wrong object name can be returned when read directory at Unicode cfg. (appeared at R0.12)
Fixed large file allocation/removing on the exFAT volume collapses allocation bitmap. (appeared at R0.12)
Fixed some internal errors in f_expand() and f_lseek(). (appeared at R0.12)
R0.12c (March 04, 2017)
Improved write throughput at the fragmented file on the exFAT volume.
Made memory usage for exFAT be able to be reduced as decreasing _MAX_LFN.
Fixed successive f_getfree() can return wrong count on the FAT12/16 volume. (appeared at R0.12)
Fixed configuration option _VOLUMES cannot be set 10. (appeared at R0.10c)
R0.13 (May 21, 2017)
Changed heading character of configuration keywords "_" to "FF_".
Removed ASCII-only configuration, FF_CODE_PAGE = 1. Use FF_CODE_PAGE = 437 instead.
Added f_setcp(), run-time code page configuration. (FF_CODE_PAGE = 0)
Improved cluster allocation time on stretch a deep buried cluster chain.
Improved processing time of f_mkdir() with large cluster size by using FF_USE_LFN = 3.
Improved NoFatChain flag of the fragmented file to be set after it is truncated and got contiguous.
Fixed archive attribute is left not set when a file on the exFAT volume is renamed. (appeared at R0.12)
Fixed exFAT FAT entry can be collapsed when write or lseek operation to the existing file is done. (appeared at R0.12c)
Fixed creating a file can fail when a new cluster allocation to the exFAT directory occures. (appeared at R0.12c)
R0.13a (October 14, 2017)
Added support for UTF-8 encoding on the API. (FF_LFN_UNICODE = 2)
Added options for file name output buffer. (FF_LFN_BUF, FF_SFN_BUF).
Added dynamic memory allocation option for working buffer of f_mkfs() and f_fdisk().
Fixed f_fdisk() and f_mkfs() create the partition table with wrong CHS parameters. (appeared at R0.09)
Fixed f_unlink() can cause lost clusters at fragmented file on the exFAT volume. (appeared at R0.12c)
Fixed f_setlabel() rejects some valid characters for exFAT volume. (appeared at R0.12)
R0.13b (April 07, 2018)
Added support for UTF-32 encoding on the API. (FF_LFN_UNICODE = 3)
Added support for Unix style volume ID. (FF_STR_VOLUME_ID = 2)
Fixed accesing any object on the exFAT root directory beyond the cluster boundary can fail. (appeared at R0.12c)
Fixed f_setlabel() does not reject some invalid characters. (appeared at R0.09b)
R0.13c (October 14, 2018)
Supported stdint.h for C99 and later. (integer.h was included in ff.h)
Fixed reading a directory gets infinite loop when the last directory entry is not empty. (appeared at R0.12)
Fixed creating a sub-directory in the fragmented sub-directory on the exFAT volume collapses FAT chain of the parent directory. (appeared at R0.12)
Fixed f_getcwd() cause output buffer overrun when the buffer has a valid drive number. (appeared at R0.13b)
R0.14 (October 14, 2019)
Added support for 64-bit LBA and GUID partition table (FF_LBA64 = 1)
Changed some API functions, f_mkfs() and f_fdisk().
Fixed f_open() function cannot find the file with file name in length of FF_MAX_LFN characters.
Fixed f_readdir() function cannot retrieve long file names in length of FF_MAX_LFN - 1 characters.
Fixed f_readdir() function returns file names with wrong case conversion. (appeared at R0.12)
Fixed f_mkfs() function can fail to create exFAT volume in the second partition. (appeared at R0.12)

View File

@ -0,0 +1,21 @@
FatFs Module Source Files R0.14
FILES
00readme.txt This file.
00history.txt Revision history.
ff.c FatFs module.
ffconf.h Configuration file of FatFs module.
ff.h Common include file for FatFs and application module.
diskio.h Common include file for FatFs and disk I/O module.
diskio.c An example of glue function to attach existing disk I/O module to FatFs.
ffunicode.c Optional Unicode utility functions.
ffsystem.c An example of optional O/S related functions.
Low level disk I/O module is not included in this archive because the FatFs
module is only a generic file system layer and it does not depend on any specific
storage device. You need to provide a low level disk I/O module written to
control the storage device that attached to the target system.

View File

@ -0,0 +1,24 @@
FatFs License
FatFs has being developped as a personal project of the author, ChaN. It is free from the code anyone else wrote at current release. Following code block shows a copy of the FatFs license document that heading the source files.
/*----------------------------------------------------------------------------/
/ FatFs - Generic FAT Filesystem Module Rx.xx /
/-----------------------------------------------------------------------------/
/
/ Copyright (C) 20xx, ChaN, all right reserved.
/
/ FatFs module is an open source software. Redistribution and use of FatFs in
/ source and binary forms, with or without modification, are permitted provided
/ that the following condition is met:
/
/ 1. Redistributions of source code must retain the above copyright notice,
/ this condition and the following disclaimer.
/
/ This software is provided by the copyright holder and contributors "AS IS"
/ and any warranties related to this software are DISCLAIMED.
/ The copyright owner or contributors be NOT LIABLE for any damages caused
/ by use of this software.
/----------------------------------------------------------------------------*/
Therefore FatFs license is one of the BSD-style licenses but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, does not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses including GNU GPL. When you redistribute the FatFs source code with any changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that not conflict with FatFs license.

268
arm9/source/fatfs/diskio.c Normal file
View File

@ -0,0 +1,268 @@
/*-----------------------------------------------------------------------*/
/* Low level disk I/O module skeleton for FatFs (C)ChaN, d0k3, 2019 */
/*-----------------------------------------------------------------------*/
/* If a working storage control module is available, it should be */
/* attached to the FatFs via a glue function rather than modifying it. */
/* This is an example of glue functions to attach various exsisting */
/* storage control modules to the FatFs module with a defined API. */
/*-----------------------------------------------------------------------*/
#include "ff.h" /* Obtains integer types */
#include "diskio.h" /* Declarations of disk functions */
#include "image.h"
#include "ramdrive.h"
#include "nand.h"
#include "sdmmc.h"
#include "rtc.h"
#define FREE_MIN_SECTORS 0x2000 // minimum sectors for the free drive to appear (4MB)
#define FPDRV(pdrv) (((pdrv >= 7) && !imgnand_mode) ? pdrv + 3 : pdrv)
#define PART_INFO(pdrv) (DriveInfo + FPDRV(pdrv))
#define PART_TYPE(pdrv) (DriveInfo[FPDRV(pdrv)].type)
#define TYPE_NONE 0
#define TYPE_SYSNAND NAND_SYSNAND
#define TYPE_EMUNAND NAND_EMUNAND
#define TYPE_IMGNAND NAND_IMGNAND
#define TYPE_SDCARD (1UL<<4)
#define TYPE_IMAGE (1UL<<5)
#define TYPE_RAMDRV (1UL<<6)
#define SUBTYPE_CTRN 0
#define SUBTYPE_CTRN_N 1
#define SUBTYPE_CTRN_NO 2
#define SUBTYPE_TWLN 3
#define SUBTYPE_TWLP 4
#define SUBTYPE_FREE 5
#define SUBTYPE_FREE_N 6
#define SUBTYPE_NONE 7
typedef struct {
BYTE type;
BYTE subtype;
DWORD offset;
DWORD size;
BYTE keyslot;
} FATpartition;
FATpartition DriveInfo[13] = {
{ TYPE_SDCARD, SUBTYPE_NONE, 0, 0, 0xFF }, // 0 - SDCARD
{ TYPE_SYSNAND, SUBTYPE_CTRN, 0, 0, 0xFF }, // 1 - SYSNAND CTRNAND
{ TYPE_SYSNAND, SUBTYPE_TWLN, 0, 0, 0xFF }, // 2 - SYSNAND TWLN
{ TYPE_SYSNAND, SUBTYPE_TWLP, 0, 0, 0xFF }, // 3 - SYSNAND TWLP
{ TYPE_EMUNAND, SUBTYPE_CTRN, 0, 0, 0xFF }, // 4 - EMUNAND CTRNAND
{ TYPE_EMUNAND, SUBTYPE_TWLN, 0, 0, 0xFF }, // 5 - EMUNAND TWLN
{ TYPE_EMUNAND, SUBTYPE_TWLP, 0, 0, 0xFF }, // 6 - EMUNAND TWLP
{ TYPE_IMGNAND, SUBTYPE_CTRN, 0, 0, 0xFF }, // 7 - IMGNAND CTRNAND
{ TYPE_IMGNAND, SUBTYPE_TWLN, 0, 0, 0xFF }, // 8 - IMGNAND TWLN
{ TYPE_IMGNAND, SUBTYPE_TWLP, 0, 0, 0xFF }, // 9 - IMGNAND TWLP
{ TYPE_IMAGE, SUBTYPE_NONE, 0, 0, 0xFF }, // X - IMAGE
{ TYPE_SYSNAND, SUBTYPE_FREE, 0, 0, 0xFF }, // Y - SYSNAND BONUS
{ TYPE_RAMDRV, SUBTYPE_NONE, 0, 0, 0xFF } // Z - RAMDRIVE
};
static BYTE imgnand_mode = 0x00;
/*-----------------------------------------------------------------------*/
/* Get current FAT time */
/*-----------------------------------------------------------------------*/
DWORD get_fattime( void ) {
DsTime dstime;
get_dstime(&dstime);
DWORD fattime =
((DSTIMEGET(&dstime, bcd_s)&0x3F) >> 1 ) |
((DSTIMEGET(&dstime, bcd_m)&0x3F) << 5 ) |
((DSTIMEGET(&dstime, bcd_h)&0x3F) << 11) |
((DSTIMEGET(&dstime, bcd_D)&0x1F) << 16) |
((DSTIMEGET(&dstime, bcd_M)&0x0F) << 21) |
(((DSTIMEGET(&dstime, bcd_Y)+(2000-1980))&0x7F) << 25);
return fattime;
}
/*-----------------------------------------------------------------------*/
/* Get Drive Status */
/*-----------------------------------------------------------------------*/
DSTATUS disk_status (
__attribute__((unused))
BYTE pdrv /* Physical drive number to identify the drive */
)
{
return RES_OK;
}
/*-----------------------------------------------------------------------*/
/* Initialize a Drive */
/*-----------------------------------------------------------------------*/
DSTATUS disk_initialize (
__attribute__((unused))
BYTE pdrv /* Physical drive number to identify the drive */
)
{
imgnand_mode = (GetMountState() & IMG_NAND) ? 0x01 : 0x00;
FATpartition* fat_info = PART_INFO(pdrv);
BYTE type = PART_TYPE(pdrv);
fat_info->offset = fat_info->size = 0;
fat_info->keyslot = 0xFF;
if (type == TYPE_SDCARD) {
if (sdmmc_sdcard_init() != 0) return STA_NOINIT|STA_NODISK;
fat_info->size = getMMCDevice(1)->total_size;
} else if ((type == TYPE_SYSNAND) || (type == TYPE_EMUNAND) || (type == TYPE_IMGNAND)) {
NandPartitionInfo nprt_info;
if ((type == TYPE_EMUNAND) && !GetNandSizeSectors(NAND_EMUNAND)) // size check for EmuNAND
return STA_NOINIT|STA_NODISK;
if ((fat_info->subtype == SUBTYPE_CTRN) &&
(GetNandPartitionInfo(&nprt_info, NP_TYPE_STD, NP_SUBTYPE_CTR, 0, type) != 0) &&
(GetNandPartitionInfo(&nprt_info, NP_TYPE_STD, NP_SUBTYPE_CTR_N, 0, type) != 0)) {
return STA_NOINIT|STA_NODISK;
} else if ((fat_info->subtype == SUBTYPE_TWLN) &&
(GetNandPartitionInfo(&nprt_info, NP_TYPE_FAT, NP_SUBTYPE_TWL, 0, type) != 0)) {
return STA_NOINIT|STA_NODISK;
} else if ((fat_info->subtype == SUBTYPE_TWLP) &&
(GetNandPartitionInfo(&nprt_info, NP_TYPE_FAT, NP_SUBTYPE_TWL, 1, type) != 0)) {
return STA_NOINIT|STA_NODISK;
} else if ((fat_info->subtype == SUBTYPE_FREE) &&
((GetNandPartitionInfo(&nprt_info, NP_TYPE_BONUS, NP_SUBTYPE_CTR, 0, type) != 0) ||
(nprt_info.count < FREE_MIN_SECTORS))) {
return STA_NOINIT|STA_NODISK;
}
fat_info->offset = nprt_info.sector;
fat_info->size = nprt_info.count;
fat_info->keyslot = nprt_info.keyslot;
} else if (type == TYPE_IMAGE) {
if (!(GetMountState() & IMG_FAT)) return STA_NOINIT|STA_NODISK;
fat_info->size = (GetMountSize() + 0x1FF) / 0x200;
} else if (type == TYPE_RAMDRV) {
InitRamDrive();
fat_info->size = (GetRamDriveSize() + 0x1FF) / 0x200;
}
return RES_OK;
}
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
/*-----------------------------------------------------------------------*/
DRESULT disk_read (
__attribute__((unused))
BYTE pdrv, /* Physical drive number to identify the drive */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address in LBA */
UINT count /* Number of sectors to read */
)
{
BYTE type = PART_TYPE(pdrv);
if (type == TYPE_NONE) {
return RES_PARERR;
} else if (type == TYPE_SDCARD) {
if (sdmmc_sdcard_readsectors(sector, count, buff) != 0)
return RES_ERROR;
} else if (type == TYPE_IMAGE) {
if (ReadImageSectors(buff, sector, count) != 0)
return RES_ERROR;
} else if (type == TYPE_RAMDRV) {
if (ReadRamDriveSectors(buff, sector, count) != 0)
return RES_ERROR;
} else {
FATpartition* fat_info = PART_INFO(pdrv);
if (ReadNandSectors(buff, fat_info->offset + sector, count, fat_info->keyslot, type) != 0)
return RES_ERROR;
}
return RES_OK;
}
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/
#if _USE_WRITE
DRESULT disk_write (
__attribute__((unused))
BYTE pdrv, /* Physical drive number to identify the drive */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address in LBA */
UINT count /* Number of sectors to write */
)
{
BYTE type = PART_TYPE(pdrv);
if (type == TYPE_NONE) {
return RES_PARERR;
} else if (type == TYPE_SDCARD) {
if (sdmmc_sdcard_writesectors(sector, count, (BYTE *)buff) != 0)
return RES_ERROR;
} else if (type == TYPE_IMAGE) {
if (WriteImageSectors(buff, sector, count) != 0)
return RES_ERROR;
} else if (type == TYPE_RAMDRV) {
if (WriteRamDriveSectors(buff, sector, count) != 0)
return RES_ERROR;
} else {
FATpartition* fat_info = PART_INFO(pdrv);
if (WriteNandSectors(buff, fat_info->offset + sector, count, fat_info->keyslot, type) != 0)
return RES_ERROR; // unstubbed!
}
return RES_OK;
}
#endif
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
/*-----------------------------------------------------------------------*/
#if _USE_IOCTL
DRESULT disk_ioctl (
__attribute__((unused))
BYTE pdrv, /* Physical drive number (0..) */
__attribute__((unused))
BYTE cmd, /* Control code */
__attribute__((unused))
void *buff /* Buffer to send/receive control data */
)
{
BYTE type = PART_TYPE(pdrv);
FATpartition* fat_info = PART_INFO(pdrv);
switch (cmd) {
case GET_SECTOR_SIZE:
*((DWORD*) buff) = 0x200;
return RES_OK;
case GET_SECTOR_COUNT:
*((DWORD*) buff) = fat_info->size;
return RES_OK;
case GET_BLOCK_SIZE:
*((DWORD*) buff) = ((type == TYPE_IMAGE) || (type == TYPE_RAMDRV)) ? 0x1 : 0x2000;
return RES_OK;
case CTRL_SYNC:
if ((type == TYPE_IMAGE) || (type == TYPE_IMGNAND))
SyncImage();
// nothing else to do here - sdmmc.c handles the rest
return RES_OK;
}
return RES_PARERR;
}
#endif

View File

@ -12,8 +12,6 @@ extern "C" {
#define _USE_WRITE 1 /* 1: Enable disk_write function */
#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */
#include "integer.h"
/* Status of Disk Functions */
typedef BYTE DSTATUS;
@ -32,6 +30,7 @@ typedef enum {
/* Prototypes for disk control functions */
DWORD get_fattime( void ); // not a disk control function, but fits here
DSTATUS disk_initialize (BYTE pdrv);
DSTATUS disk_status (BYTE pdrv);
DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
@ -49,11 +48,11 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
/* Command code for disk_ioctrl fucntion */
/* Generic command (Used by FatFs) */
#define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */
#define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
#define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */
#define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */
/* Generic command (Not used by FatFs) */
#define CTRL_POWER 5 /* Get/Set power status */
@ -67,6 +66,9 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
#define MMC_GET_CID 12 /* Get CID */
#define MMC_GET_OCR 13 /* Get OCR */
#define MMC_GET_SDSTAT 14 /* Get SD status */
#define ISDIO_READ 55 /* Read data form SD iSDIO register */
#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */
/* ATA/CF specific ioctl command */
#define ATA_GET_REV 20 /* Get F/W revision */

6850
arm9/source/fatfs/ff.c Normal file

File diff suppressed because it is too large Load Diff

426
arm9/source/fatfs/ff.h Normal file
View File

@ -0,0 +1,426 @@
/*----------------------------------------------------------------------------/
/ FatFs - Generic FAT Filesystem module R0.14 /
/-----------------------------------------------------------------------------/
/
/ Copyright (C) 2019, ChaN, all right reserved.
/
/ FatFs module is an open source software. Redistribution and use of FatFs in
/ source and binary forms, with or without modification, are permitted provided
/ that the following condition is met:
/ 1. Redistributions of source code must retain the above copyright notice,
/ this condition and the following disclaimer.
/
/ This software is provided by the copyright holder and contributors "AS IS"
/ and any warranties related to this software are DISCLAIMED.
/ The copyright owner or contributors be NOT LIABLE for any damages caused
/ by use of this software.
/
/----------------------------------------------------------------------------*/
#ifndef FF_DEFINED
#define FF_DEFINED 86606 /* Revision ID */
#ifdef __cplusplus
extern "C" {
#endif
#include "ffconf.h" /* FatFs configuration options */
#if FF_DEFINED != FFCONF_DEF
#error Wrong configuration file (ffconf.h).
#endif
/* Integer types used for FatFs API */
#if defined(_WIN32) /* Main development platform */
#define FF_INTDEF 2
#include <windows.h>
typedef unsigned __int64 QWORD;
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) /* C99 or later */
#define FF_INTDEF 2
#include <stdint.h>
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
typedef unsigned char BYTE; /* char must be 8-bit */
typedef uint16_t WORD; /* 16-bit unsigned integer */
typedef uint32_t DWORD; /* 32-bit unsigned integer */
typedef uint64_t QWORD; /* 64-bit unsigned integer */
typedef WORD WCHAR; /* UTF-16 character type */
#else /* Earlier than C99 */
#define FF_INTDEF 1
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
typedef unsigned char BYTE; /* char must be 8-bit */
typedef unsigned short WORD; /* 16-bit unsigned integer */
typedef unsigned long DWORD; /* 32-bit unsigned integer */
typedef WORD WCHAR; /* UTF-16 character type */
#endif
/* Definitions of volume management */
#if FF_MULTI_PARTITION /* Multiple partition configuration */
typedef struct {
BYTE pd; /* Physical drive number */
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
} PARTITION;
extern PARTITION VolToPart[]; /* Volume - Partition mapping table */
#endif
#if FF_STR_VOLUME_ID
#ifndef FF_VOLUME_STRS
extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
#endif
#endif
/* Type of path name strings on FatFs API */
#ifndef _INC_TCHAR
#define _INC_TCHAR
#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */
typedef WCHAR TCHAR;
#define _T(x) L ## x
#define _TEXT(x) L ## x
#elif FF_USE_LFN && FF_LFN_UNICODE == 2 /* Unicode in UTF-8 encoding */
typedef char TCHAR;
#define _T(x) u8 ## x
#define _TEXT(x) u8 ## x
#elif FF_USE_LFN && FF_LFN_UNICODE == 3 /* Unicode in UTF-32 encoding */
typedef DWORD TCHAR;
#define _T(x) U ## x
#define _TEXT(x) U ## x
#elif FF_USE_LFN && (FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3)
#error Wrong FF_LFN_UNICODE setting
#else /* ANSI/OEM code in SBCS/DBCS */
typedef char TCHAR;
#define _T(x) x
#define _TEXT(x) x
#endif
#endif
/* Type of file size and LBA variables */
#if FF_FS_EXFAT
#if FF_INTDEF != 2
#error exFAT feature wants C99 or later
#endif
typedef QWORD FSIZE_t;
#if FF_LBA64
typedef QWORD LBA_t;
#else
typedef DWORD LBA_t;
#endif
#else
#if FF_LBA64
#error exFAT needs to be enabled when enable 64-bit LBA
#endif
typedef DWORD FSIZE_t;
typedef DWORD LBA_t;
#endif
/* Filesystem object structure (FATFS) */
typedef struct {
BYTE fs_type; /* Filesystem type (0:not mounted) */
BYTE pdrv; /* Associated physical drive */
BYTE n_fats; /* Number of FATs (1 or 2) */
BYTE wflag; /* win[] flag (b0:dirty) */
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
WORD id; /* Volume mount ID */
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
WORD csize; /* Cluster size [sectors] */
#if FF_MAX_SS != FF_MIN_SS
WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */
#endif
#if FF_USE_LFN
WCHAR* lfnbuf; /* LFN working buffer */
#endif
#if FF_FS_EXFAT
BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */
#endif
#if FF_FS_REENTRANT
FF_SYNC_t sobj; /* Identifier of sync object */
#endif
#if !FF_FS_READONLY
DWORD last_clst; /* Last allocated cluster */
DWORD free_clst; /* Number of free clusters */
#endif
#if FF_FS_RPATH
DWORD cdir; /* Current directory start cluster (0:root) */
#if FF_FS_EXFAT
DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */
DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */
DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */
#endif
#endif
DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
DWORD fsize; /* Size of an FAT [sectors] */
LBA_t volbase; /* Volume base sector */
LBA_t fatbase; /* FAT base sector */
LBA_t dirbase; /* Root directory base sector/cluster */
LBA_t database; /* Data base sector */
#if FF_FS_EXFAT
LBA_t bitbase; /* Allocation bitmap base sector */
#endif
LBA_t winsect; /* Current sector appearing in the win[] */
BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
} FATFS;
/* Object ID and allocation information (FFOBJID) */
typedef struct {
FATFS* fs; /* Pointer to the hosting volume of this object */
WORD id; /* Hosting volume mount ID */
BYTE attr; /* Object attribute */
BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */
FSIZE_t objsize; /* Object size (valid when sclust != 0) */
#if FF_FS_EXFAT
DWORD n_cont; /* Size of first fragment - 1 (valid when stat == 3) */
DWORD n_frag; /* Size of last fragment needs to be written to FAT (valid when not zero) */
DWORD c_scl; /* Containing directory start cluster (valid when sclust != 0) */
DWORD c_size; /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */
DWORD c_ofs; /* Offset in the containing directory (valid when file object and sclust != 0) */
#endif
#if FF_FS_LOCK
UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
#endif
} FFOBJID;
/* File object structure (FIL) */
typedef struct {
FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */
BYTE flag; /* File status flags */
BYTE err; /* Abort flag (error code) */
FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */
DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */
LBA_t sect; /* Sector number appearing in buf[] (0:invalid) */
#if !FF_FS_READONLY
LBA_t dir_sect; /* Sector number containing the directory entry (not used at exFAT) */
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */
#endif
#if FF_USE_FASTSEEK
DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */
#endif
#if !FF_FS_TINY
BYTE buf[FF_MAX_SS]; /* File private data read/write window */
#endif
} FIL;
/* Directory object structure (DIR) */
typedef struct {
FFOBJID obj; /* Object identifier */
DWORD dptr; /* Current read/write offset */
DWORD clust; /* Current cluster */
LBA_t sect; /* Current sector (0:Read operation has terminated) */
BYTE* dir; /* Pointer to the directory item in the win[] */
BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */
#if FF_USE_LFN
DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */
#endif
#if FF_USE_FIND
const TCHAR* pat; /* Pointer to the name matching pattern */
#endif
} DIR;
/* File information structure (FILINFO) */
typedef struct {
FSIZE_t fsize; /* File size */
WORD fdate; /* Modified date */
WORD ftime; /* Modified time */
BYTE fattrib; /* File attribute */
#if FF_USE_LFN
TCHAR altname[FF_SFN_BUF + 1];/* Altenative file name */
TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */
#else
TCHAR fname[12 + 1]; /* File name */
#endif
} FILINFO;
/* Format parameter structure (MKFS_PARM) */
typedef struct {
BYTE fmt; /* Format option (FM_FAT, FM_FAT32, FM_EXFAT and FM_SFD) */
BYTE n_fat; /* Number of FATs */
UINT align; /* Data area alignment (sector) */
UINT n_root; /* Number of root directory entries */
DWORD au_size; /* Cluster size (byte) */
} MKFS_PARM;
/* File function return code (FRESULT) */
typedef enum {
FR_OK = 0, /* (0) Succeeded */
FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
FR_INT_ERR, /* (2) Assertion failed */
FR_NOT_READY, /* (3) The physical drive cannot work */
FR_NO_FILE, /* (4) Could not find the file */
FR_NO_PATH, /* (5) Could not find the path */
FR_INVALID_NAME, /* (6) The path name format is invalid */
FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
FR_EXIST, /* (8) Access denied due to prohibited access */
FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
FR_NOT_ENABLED, /* (12) The volume has no work area */
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
} FRESULT;
/*--------------------------------------------------------------*/
/* FatFs module application interface */
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
FRESULT f_close (FIL* fp); /* Close an open file object */
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from the file */
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to the file */
FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */
FRESULT f_truncate (FIL* fp); /* Truncate the file */
FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
FRESULT f_closedir (DIR* dp); /* Close an open directory */
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of a file/dir */
FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change timestamp of a file/dir */
FRESULT f_chdir (const TCHAR* path); /* Change current directory */
FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
FRESULT f_expand (FIL* fp, FSIZE_t fsz, BYTE opt); /* Allocate a contiguous block to the file */
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
FRESULT f_mkfs (const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len); /* Create a FAT volume */
FRESULT f_fdisk (BYTE pdrv, const LBA_t ptbl[], void* work); /* Divide a physical drive into some partitions */
FRESULT f_setcp (WORD cp); /* Set current code page */
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
#define f_error(fp) ((fp)->err)
#define f_tell(fp) ((fp)->fptr)
#define f_size(fp) ((fp)->obj.objsize)
#define f_rewind(fp) f_lseek((fp), 0)
#define f_rewinddir(dp) f_readdir((dp), 0)
#define f_rmdir(path) f_unlink(path)
#define f_unmount(path) f_mount(0, path, 0)
#ifndef EOF
#define EOF (-1)
#endif
/*--------------------------------------------------------------*/
/* Additional user defined functions */
/* RTC function */
#if !FF_FS_READONLY && !FF_FS_NORTC
DWORD get_fattime (void);
#endif
/* LFN support functions */
#if FF_USE_LFN >= 1 /* Code conversion (defined in unicode.c) */
WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */
WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */
DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */
#endif
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
void* ff_memalloc (UINT msize); /* Allocate memory block */
void ff_memfree (void* mblock); /* Free memory block */
#endif
/* Sync functions */
#if FF_FS_REENTRANT
int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */
int ff_req_grant (FF_SYNC_t sobj); /* Lock sync object */
void ff_rel_grant (FF_SYNC_t sobj); /* Unlock sync object */
int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */
#endif
/*--------------------------------------------------------------*/
/* Flags and offset address */
/* File access mode and open method flags (3rd argument of f_open) */
#define FA_READ 0x01
#define FA_WRITE 0x02
#define FA_OPEN_EXISTING 0x00
#define FA_CREATE_NEW 0x04
#define FA_CREATE_ALWAYS 0x08
#define FA_OPEN_ALWAYS 0x10
#define FA_OPEN_APPEND 0x30
/* Fast seek controls (2nd argument of f_lseek) */
#define CREATE_LINKMAP ((FSIZE_t)0 - 1)
/* Format options (2nd argument of f_mkfs) */
#define FM_FAT 0x01
#define FM_FAT32 0x02
#define FM_EXFAT 0x04
#define FM_ANY 0x07
#define FM_SFD 0x08
/* Filesystem type (FATFS.fs_type) */
#define FS_FAT12 1
#define FS_FAT16 2
#define FS_FAT32 3
#define FS_EXFAT 4
/* File attribute bits for directory entry (FILINFO.fattrib) */
#define AM_RDO 0x01 /* Read only */
#define AM_HID 0x02 /* Hidden */
#define AM_SYS 0x04 /* System */
#define AM_DIR 0x10 /* Directory */
#define AM_ARC 0x20 /* Archive */
#ifdef __cplusplus
}
#endif
#endif /* FF_DEFINED */

298
arm9/source/fatfs/ffconf.h Normal file
View File

@ -0,0 +1,298 @@
/*---------------------------------------------------------------------------/
/ FatFs Functional Configurations
/---------------------------------------------------------------------------*/
#define FFCONF_DEF 86606 /* Revision ID */
/*---------------------------------------------------------------------------/
/ Function Configurations
/---------------------------------------------------------------------------*/
#define FF_FS_READONLY 0
/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
/ Read-only configuration removes writing API functions, f_write(), f_sync(),
/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
/ and optional writing functions as well. */
#define FF_FS_MINIMIZE 0
/* This option defines minimization level to remove some basic API functions.
/
/ 0: Basic functions are fully enabled.
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()
/ are removed.
/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
/ 3: f_lseek() function is removed in addition to 2. */
#define FF_USE_STRFUNC 0
/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf().
/
/ 0: Disable string functions.
/ 1: Enable without LF-CRLF conversion.
/ 2: Enable with LF-CRLF conversion. */
#define FF_USE_FIND 0
/* This option switches filtered directory read functions, f_findfirst() and
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
#define FF_USE_MKFS 1
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
#define FF_USE_FASTSEEK 0
/* This option switches fast seek function. (0:Disable or 1:Enable) */
#define FF_USE_EXPAND 0
/* This option switches f_expand function. (0:Disable or 1:Enable) */
#define FF_USE_CHMOD 1
/* This option switches attribute manipulation functions, f_chmod() and f_utime().
/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */
#define FF_USE_LABEL 1
/* This option switches volume label functions, f_getlabel() and f_setlabel().
/ (0:Disable or 1:Enable) */
#define FF_USE_FORWARD 0
/* This option switches f_forward() function. (0:Disable or 1:Enable) */
/*---------------------------------------------------------------------------/
/ Locale and Namespace Configurations
/---------------------------------------------------------------------------*/
#define FF_CODE_PAGE 437
/* This option specifies the OEM code page to be used on the target system.
/ Incorrect code page setting can cause a file open failure.
/
/ 437 - U.S.
/ 720 - Arabic
/ 737 - Greek
/ 771 - KBL
/ 775 - Baltic
/ 850 - Latin 1
/ 852 - Latin 2
/ 855 - Cyrillic
/ 857 - Turkish
/ 860 - Portuguese
/ 861 - Icelandic
/ 862 - Hebrew
/ 863 - Canadian French
/ 864 - Arabic
/ 865 - Nordic
/ 866 - Russian
/ 869 - Greek 2
/ 932 - Japanese (DBCS)
/ 936 - Simplified Chinese (DBCS)
/ 949 - Korean (DBCS)
/ 950 - Traditional Chinese (DBCS)
/ 0 - Include all code pages above and configured by f_setcp()
*/
#define FF_USE_LFN 2
#define FF_MAX_LFN 255
/* The FF_USE_LFN switches the support for LFN (long file name).
/
/ 0: Disable LFN. FF_MAX_LFN has no effect.
/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
/ 2: Enable LFN with dynamic working buffer on the STACK.
/ 3: Enable LFN with dynamic working buffer on the HEAP.
/
/ To enable the LFN, ffunicode.c needs to be added to the project. The LFN function
/ requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and
/ additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.
/ The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can
/ be in range of 12 to 255. It is recommended to be set it 255 to fully support LFN
/ specification.
/ When use stack for the working buffer, take care on stack overflow. When use heap
/ memory for the working buffer, memory management functions, ff_memalloc() and
/ ff_memfree() exemplified in ffsystem.c, need to be added to the project. */
#define FF_LFN_UNICODE 2
/* This option switches the character encoding on the API when LFN is enabled.
/
/ 0: ANSI/OEM in current CP (TCHAR = char)
/ 1: Unicode in UTF-16 (TCHAR = WCHAR)
/ 2: Unicode in UTF-8 (TCHAR = char)
/ 3: Unicode in UTF-32 (TCHAR = DWORD)
/
/ Also behavior of string I/O functions will be affected by this option.
/ When LFN is not enabled, this option has no effect. */
#define FF_LFN_BUF 255
#define FF_SFN_BUF 12
/* This set of options defines size of file name members in the FILINFO structure
/ which is used to read out directory items. These values should be suffcient for
/ the file names to read. The maximum possible length of the read file name depends
/ on character encoding. When LFN is not enabled, these options have no effect. */
#define FF_STRF_ENCODE 0
/* When FF_LFN_UNICODE >= 1 with LFN enabled, string I/O functions, f_gets(),
/ f_putc(), f_puts and f_printf() convert the character encoding in it.
/ This option selects assumption of character encoding ON THE FILE to be
/ read/written via those functions.
/
/ 0: ANSI/OEM in current CP
/ 1: Unicode in UTF-16LE
/ 2: Unicode in UTF-16BE
/ 3: Unicode in UTF-8
*/
#define FF_FS_RPATH 0
/* This option configures support for relative path.
/
/ 0: Disable relative path and remove related functions.
/ 1: Enable relative path. f_chdir() and f_chdrive() are available.
/ 2: f_getcwd() function is available in addition to 1.
*/
/*---------------------------------------------------------------------------/
/ Drive/Volume Configurations
/---------------------------------------------------------------------------*/
#define FF_VOLUMES 10
/* Number of volumes (logical drives) to be used. (1-10) */
#define FF_STR_VOLUME_ID 0
#define FF_VOLUME_STRS "sdcard","sysnand","systwln","systwlp","emunand","emutwln","emutwlp","imgnand","imgtwln","imgtwlp"
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
/ number in the path name. FF_VOLUME_STRS defines the volume ID strings for each
/ logical drives. Number of items must not be less than FF_VOLUMES. Valid
/ characters for the volume ID strings are A-Z, a-z and 0-9, however, they are
/ compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is
/ not defined, a user defined volume string table needs to be defined as:
/
/ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",...
*/
#define FF_MULTI_PARTITION 1
/* This option switches support for multiple volumes on the physical drive.
/ By default (0), each logical drive number is bound to the same physical drive
/ number and only an FAT volume found on the physical drive will be mounted.
/ When this function is enabled (1), each logical drive number can be bound to
/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
/ funciton will be available. */
#define FF_MIN_SS 512
#define FF_MAX_SS 512
/* This set of options configures the range of sector size to be supported. (512,
/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
/ harddisk. But a larger value may be required for on-board flash memory and some
/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured
/ for variable sector size mode and disk_ioctl() function needs to implement
/ GET_SECTOR_SIZE command. */
#define FF_LBA64 0
/* This option switches support for 64-bit LBA. (0:Disable or 1:Enable)
/ To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */
#define FF_MIN_GPT 0x100000000
/* Minimum number of sectors to switch GPT format to create partition in f_mkfs and
/ f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */
#define FF_USE_TRIM 0
/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
/ To enable Trim function, also CTRL_TRIM command should be implemented to the
/ disk_ioctl() function. */
/*---------------------------------------------------------------------------/
/ System Configurations
/---------------------------------------------------------------------------*/
#define FF_FS_TINY 0
/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes.
/ Instead of private sector buffer eliminated from the file object, common sector
/ buffer in the filesystem object (FATFS) is used for the file data transfer. */
#define FF_FS_EXFAT 0
/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
#define FF_FS_NORTC 0
#define FF_NORTC_MON 1
#define FF_NORTC_MDAY 1
#define FF_NORTC_YEAR 2019
/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have
/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable
/ the timestamp function. Every object modified by FatFs will have a fixed timestamp
/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time.
/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be
/ added to the project to read current time form real-time clock. FF_NORTC_MON,
/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect.
/ These options have no effect in read-only configuration (FF_FS_READONLY = 1). */
#define FF_FS_NOFSINFO 0
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
/ option, and f_getfree() function at first time after volume mount will force
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
/
/ bit0=0: Use free cluster count in the FSINFO if available.
/ bit0=1: Do not trust free cluster count in the FSINFO.
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
*/
#define FF_FS_LOCK 32
/* The option FF_FS_LOCK switches file lock function to control duplicated file open
/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY
/ is 1.
/
/ 0: Disable file lock function. To avoid volume corruption, application program
/ should avoid illegal open, remove and rename to the open objects.
/ >0: Enable file lock function. The value defines how many files/sub-directories
/ can be opened simultaneously under file lock control. Note that the file
/ lock control is independent of re-entrancy. */
/* #include <somertos.h> // O/S definitions */
#define FF_FS_REENTRANT 0
#define FF_FS_TIMEOUT 1000
#define FF_SYNC_t HANDLE
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
/ module itself. Note that regardless of this option, file access to different
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
/ and f_fdisk() function, are always not re-entrant. Only file/directory access
/ to the same volume is under control of this function.
/
/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect.
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
/ function, must be added to the project. Samples are available in
/ option/syscall.c.
/
/ The FF_FS_TIMEOUT defines timeout period in unit of time tick.
/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be
/ included somewhere in the scope of ff.h. */
/*--- End of configuration options ---*/

View File

@ -0,0 +1,170 @@
/*------------------------------------------------------------------------*/
/* Sample Code of OS Dependent Functions for FatFs */
/* (C)ChaN, 2018 */
/*------------------------------------------------------------------------*/
#include "ff.h"
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
/*------------------------------------------------------------------------*/
/* Allocate a memory block */
/*------------------------------------------------------------------------*/
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
UINT msize /* Number of bytes to allocate */
)
{
return malloc(msize); /* Allocate a new memory block with POSIX API */
}
/*------------------------------------------------------------------------*/
/* Free a memory block */
/*------------------------------------------------------------------------*/
void ff_memfree (
void* mblock /* Pointer to the memory block to free (nothing to do if null) */
)
{
free(mblock); /* Free the memory block with POSIX API */
}
#endif
#if FF_FS_REENTRANT /* Mutal exclusion */
/*------------------------------------------------------------------------*/
/* Create a Synchronization Object */
/*------------------------------------------------------------------------*/
/* This function is called in f_mount() function to create a new
/ synchronization object for the volume, such as semaphore and mutex.
/ When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
*/
//const osMutexDef_t Mutex[FF_VOLUMES]; /* Table of CMSIS-RTOS mutex */
int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
BYTE vol, /* Corresponding volume (logical drive number) */
FF_SYNC_t* sobj /* Pointer to return the created sync object */
)
{
/* Win32 */
*sobj = CreateMutex(NULL, FALSE, NULL);
return (int)(*sobj != INVALID_HANDLE_VALUE);
/* uITRON */
// T_CSEM csem = {TA_TPRI,1,1};
// *sobj = acre_sem(&csem);
// return (int)(*sobj > 0);
/* uC/OS-II */
// OS_ERR err;
// *sobj = OSMutexCreate(0, &err);
// return (int)(err == OS_NO_ERR);
/* FreeRTOS */
// *sobj = xSemaphoreCreateMutex();
// return (int)(*sobj != NULL);
/* CMSIS-RTOS */
// *sobj = osMutexCreate(&Mutex[vol]);
// return (int)(*sobj != NULL);
}
/*------------------------------------------------------------------------*/
/* Delete a Synchronization Object */
/*------------------------------------------------------------------------*/
/* This function is called in f_mount() function to delete a synchronization
/ object that created with ff_cre_syncobj() function. When a 0 is returned,
/ the f_mount() function fails with FR_INT_ERR.
*/
int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */
FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
)
{
/* Win32 */
return (int)CloseHandle(sobj);
/* uITRON */
// return (int)(del_sem(sobj) == E_OK);
/* uC/OS-II */
// OS_ERR err;
// OSMutexDel(sobj, OS_DEL_ALWAYS, &err);
// return (int)(err == OS_NO_ERR);
/* FreeRTOS */
// vSemaphoreDelete(sobj);
// return 1;
/* CMSIS-RTOS */
// return (int)(osMutexDelete(sobj) == osOK);
}
/*------------------------------------------------------------------------*/
/* Request Grant to Access the Volume */
/*------------------------------------------------------------------------*/
/* This function is called on entering file functions to lock the volume.
/ When a 0 is returned, the file function fails with FR_TIMEOUT.
*/
int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
FF_SYNC_t sobj /* Sync object to wait */
)
{
/* Win32 */
return (int)(WaitForSingleObject(sobj, FF_FS_TIMEOUT) == WAIT_OBJECT_0);
/* uITRON */
// return (int)(wai_sem(sobj) == E_OK);
/* uC/OS-II */
// OS_ERR err;
// OSMutexPend(sobj, FF_FS_TIMEOUT, &err));
// return (int)(err == OS_NO_ERR);
/* FreeRTOS */
// return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);
/* CMSIS-RTOS */
// return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);
}
/*------------------------------------------------------------------------*/
/* Release Grant to Access the Volume */
/*------------------------------------------------------------------------*/
/* This function is called on leaving file functions to unlock the volume.
*/
void ff_rel_grant (
FF_SYNC_t sobj /* Sync object to be signaled */
)
{
/* Win32 */
ReleaseMutex(sobj);
/* uITRON */
// sig_sem(sobj);
/* uC/OS-II */
// OSMutexPost(sobj);
/* FreeRTOS */
// xSemaphoreGive(sobj);
/* CMSIS-RTOS */
// osMutexRelease(sobj);
}
#endif

15593
arm9/source/fatfs/ffunicode.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,32 @@
#include "ramdrive.h"
#include "unittype.h"
#include "memmap.h"
static u8* ramdrv_buffer = NULL;
static u32 ramdrv_size = 0;
int ReadRamDriveSectors(void* buffer, u32 sector, u32 count) {
u64 offset = sector * 0x200;
u64 btr = count * 0x200;
if (!ramdrv_buffer) return -1;
if ((offset + btr) > ramdrv_size) return -1;
memcpy(buffer, ramdrv_buffer + offset, btr);
return 0;
}
int WriteRamDriveSectors(const void* buffer, u32 sector, u32 count) {
u64 offset = sector * 0x200;
u64 btw = count * 0x200;
if (!ramdrv_buffer) return -1;
if ((offset + btw) > ramdrv_size) return -1;
memcpy(ramdrv_buffer + offset, buffer, btw);
return 0;
}
u64 GetRamDriveSize(void) {
return ramdrv_size;
}
void InitRamDrive(void) {
ramdrv_buffer = (u8*) __RAMDRV_ADDR;
ramdrv_size = (IS_O3DS ? __RAMDRV_END : __RAMDRV_END_N) - __RAMDRV_ADDR;
}

View File

@ -0,0 +1,8 @@
#pragma once
#include "common.h"
int ReadRamDriveSectors(void* buffer, u32 sector, u32 count);
int WriteRamDriveSectors(const void* buffer, u32 sector, u32 count);
u64 GetRamDriveSize(void);
void InitRamDrive(void);

View File

@ -0,0 +1,32 @@
#include "fatmbr.h"
u32 ValidateMbrHeader(MbrHeader* mbr) {
if (mbr->magic != FATMBR_MAGIC) return 1; // check magic
u32 sector = 1; // check partitions
for (u32 i = 0; i < 4; i++) {
MbrPartitionInfo* partition = mbr->partitions + i;
if (!partition->count && i) continue;
else if (!partition->count) return 1; // first partition can't be empty
if ((partition->type != 0x1) && (partition->type != 0x4) && (partition->type != 0x6) &&
(partition->type != 0xB) && (partition->type != 0xC) && (partition->type != 0xE))
return 1; // bad / unknown filesystem type
if (partition->sector < sector) return 1; // overlapping partitions
sector = partition->sector + partition->count;
}
return 0;
}
u32 ValidateFatHeader(void* fat) {
if (getle16((u8*) fat + 0x1FE) != FATMBR_MAGIC) return 1; // check magic
Fat32Header* fat32 = (Fat32Header*) fat;
if (strncmp(fat32->fs_type, "FAT32 ", 8) == 0)
return 0; // is FAT32 header
Fat16Header* fat16 = (Fat16Header*) fat;
if ((strncmp(fat16->fs_type, "FAT16 ", 8) == 0) ||
(strncmp(fat16->fs_type, "FAT12 ", 8) == 0) ||
(strncmp(fat16->fs_type, "FAT ", 8) == 0))
return 0; // is FAT16 / FAT12 header
if ((getle64(fat16->fs_type) == 0) && (fat16->sct_size == 0x200))
return 0; // special case for public.sav
return 1; // failed, not a FAT header
}

View File

@ -0,0 +1,90 @@
#pragma once
#include "common.h"
#define FATMBR_MAGIC 0xAA55 // little endian!
typedef struct {
u8 status; // 0x80
u8 chs_start[3]; // 0x01 0x01 0x00
u8 type; // 0x0C
u8 chs_end[3]; // 0xFE 0xFF 0xFF
u32 sector; // 0x2000 (4MB offset, 512 byte sectors)
u32 count;
} PACKED_ALIGN(2) MbrPartitionInfo;
typedef struct {
char text[446];
MbrPartitionInfo partitions[4];
u16 magic; // 0xAA55
} PACKED_ALIGN(2) MbrHeader;
typedef struct { // unused
u32 signature0; // 0x41615252
u8 reserved0[480];
u32 signature1; // 0x61417272
u32 clr_free; // 0xFFFFFFFF
u32 clr_next; // 0xFFFFFFFF
u8 reserved1[14];
u16 magic; // 0xAA55
} PACKED_STRUCT FileSystemInfo;
typedef struct {
u8 jmp[3]; // 0x90 0x00 0xEB
char oemname[8]; // "anything"
u16 sct_size; // 0x0200
u8 clr_size; // 0x40 -> 32kB clusters with 512byte sectors
u16 sct_reserved; // 0x20
u8 fat_n; // 0x02
u16 reserved0; // root entry count in FAT16
u16 reserved1; // partition size when <= 32MB
u8 mediatype; // 0xF8
u16 reserved2; // FAT size in sectors in FAT16
u16 sct_track; // 0x3F
u16 sct_heads; // 0xFF
u32 sct_hidden; // same as partition offset in MBR
u32 sct_total; // same as partition size in MBR
u32 fat_size; // roundup((((sct_total - sct_reserved) / clr_size) * 4) / sct_size)
u16 flags; // 0x00
u16 version; // 0x00
u32 clr_root; // 0x02
u16 sct_fsinfo; // 0x01
u16 sct_backup; // 0x06
u8 reserved3[12];
u8 ndrive; // 0x80
u8 head_cur; // 0x00
u8 boot_sig; // 0x29
u32 vol_id; // volume id / 0x00
char vol_label[11]; // "anything "
char fs_type[8]; // "FAT32 "
u8 reserved4[420];
u16 magic; // 0xAA55
} PACKED_STRUCT Fat32Header;
typedef struct { // this struct is not tested enough!
u8 jmp[3]; // 0x90 0x00 0xEB
char oemname[8]; // "anything"
u16 sct_size; // 0x0200
u8 clr_size; // 0x20 (???) -> 16kB clusters with 512byte sectors
u16 sct_reserved; // 0x01
u8 fat_n; // 0x02
u16 root_n; // 0x0200
u16 reserved0; // partition size when <= 32MB
u8 mediatype; // 0xF8
u16 fat_size; // roundup((((sct_total - sct_reserved) / clr_size) * 2) / sct_size)
u16 sct_track; // 0x3F
u16 sct_heads; // 0xFF
u32 sct_hidden; // same as partition offset in MBR
u32 sct_total; // same as partition size in MBR
u8 ndrive; // 0x80
u8 head_cur; // 0x00
u8 boot_sig; // 0x29
u32 vol_id; // volume id / 0x00
char vol_label[11]; // "anything "
char fs_type[8]; // "FAT16 "
u8 reserved4[448];
u16 magic; // 0xAA55
} PACKED_STRUCT Fat16Header;
u32 ValidateMbrHeader(MbrHeader* mbr);
u32 ValidateFatHeader(void* fat);

Some files were not shown because too many files have changed in this diff Show More