add fix94's (this time not as a sub module)

This commit is contained in:
Christopher Roy Bratusek 2016-08-14 19:14:42 +02:00
parent 0ed9b302bd
commit 4ce8dc5a39
28 changed files with 2128 additions and 4 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "nand-loader"]
path = nand-loader
url = https://github.com/FIX94/tiny-vwii-nand-loader

@ -1 +0,0 @@
Subproject commit 9400de2d11c8ea0bcafd07cf4fe8cc44b6cbabfb

View File

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) 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
this service 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 make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. 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.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
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
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the 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 a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE 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.
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
convey 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 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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision 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, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This 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.

28
nand-loader/Makefile Normal file
View File

@ -0,0 +1,28 @@
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
endif
include $(DEVKITPPC)/wii_rules
.PHONY = all clean
CURDIR_TMP := $(CURDIR)
all:
@echo Make Stub
@$(MAKE) --no-print-directory -C $(CURDIR_TMP)/stub \
-f $(CURDIR_TMP)/stub/Makefile
@mv -u $(CURDIR_TMP)/stub/stub.bin \
$(CURDIR_TMP)/make_app/stub.bin
@echo Make NAND Loader
@$(MAKE) --no-print-directory -C $(CURDIR_TMP) \
-f $(CURDIR_TMP)/Makefile.loader
@mv -u $(CURDIR_TMP)/loader.bin \
$(CURDIR_TMP)/make_app/loader.bin
clean:
@$(MAKE) --no-print-directory -C $(CURDIR_TMP)/stub \
-f $(CURDIR_TMP)/stub/Makefile clean
@$(MAKE) --no-print-directory -C $(CURDIR_TMP) \
-f $(CURDIR_TMP)/Makefile.loader clean
rm -rf $(CURDIR_TMP)/make_app/stub.bin
rm -rf $(CURDIR_TMP)/make_app/loader.bin
rm -rf $(CURDIR_TMP)/make_app/00000001.app

View File

@ -0,0 +1,54 @@
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
endif
include $(DEVKITPPC)/wii_rules
PREFIX = powerpc-eabi-
AR = $(PREFIX)ar
AS = $(PREFIX)as
CC = $(PREFIX)gcc
CXX = $(PREFIX)g++
LD = $(PREFIX)ld
OBJCOPY = $(PREFIX)objcopy
RANLIB = $(PREFIX)ranlib
STRIP = $(PREFIX)strip
MACHDEP = -mcpu=750 -mno-eabi -mhard-float
CFLAGS = $(MACHDEP) -O1 -Werror -Wall -pipe -ffunction-sections -finline-functions-called-once -mno-sdata
LDFLAGS = $(MACHDEP) -n -nostartfiles -nostdlib -Wl,-T,openstub.ld -L.
ASFLAGS = -D_LANGUAGE_ASSEMBLY -DHW_RVL
TARGET_LINKED = boot.elf
TARGET = loader.bin
CFILES = ios.c utils.c cache.c main.c
OBJS = app_booter.o crt0.o memory.o ios.o utils.o cache.o main.o
DEPDIR = .deps
all: $(TARGET)
%.o: %.s
@echo " ASSEMBLE $<"
@$(CC) $(CFLAGS) $(DEFINES) $(ASFLAGS) -c $< -o $@
%.o: %.S
@echo " ASSEMBLE $<"
@$(CC) $(CFLAGS) $(DEFINES) $(ASFLAGS) -c $< -o $@
%.o: %.c
@echo " COMPILE $<"
@$(CC) $(CFLAGS) $(DEFINES) -c $< -o $@
$(TARGET_LINKED): $(OBJS)
@echo " LINK $@"
@$(CC) -g -o $@ $(LDFLAGS) $(OBJS) $(LIBS)
$(TARGET): $(TARGET_LINKED)
@echo " OBJCOPY $@"
@$(OBJCOPY) -O binary $< $@
clean:
rm -rf $(TARGET_LINKED) $(TARGET) $(OBJS) $(DEPDIR)

2
nand-loader/README Normal file
View File

@ -0,0 +1,2 @@
This Project is based on megazigs stub, tinyload and dimoks app loader.
With this NAND Loader you can update existing forwarders to work in WiiU vWii Mode, just unpack your wad file, replace the app file with the one in the binary folder, repack the wad and its ready to use.

131
nand-loader/README.tinyload Normal file
View File

@ -0,0 +1,131 @@
TinyLoad v0.2
A Wii disc game loader in 4096 bytes
====================================
What?
=====
TinyLoad is a simple original Wii game launcher. You run it, it launches
whatever's inserted into the drive. Simple. It ignores game regions, so it's
region-free. It won't install updates. It won't load burned copies. There are no
controls or settings.
The user interface shows two things: progress, and error status. A white bar
across the bottom of the screen shows the current (rough) progress. If an error
is detected, a portion of the top of the screen will turn red. It will then
attempt to launch The Homebrew Channel (only applies to recent versions with the
JODI Title ID). If this fails then it will simply hang.
If the launcher freezes with the progress bar visible and no red error box, then
you've probably hit a bug. Try the debug version if you have a USB Gecko.
If it freezes with a black screen after the progress bar has reached its
endpoint and disappeared, then the game itself is freezing.
I obviously have only tested this with a few games. Chances are it doesn't work
with every Wii game out there.
The debug version requires a USB Gecko and shows debug messages over it.
Notes:
- TinyLoad sets the PPC timebase correctly according to your Wii's RTC. This
fixes date/time issues in games.
- The video code makes lots of assumptions. It will only work if VI was left
configured in a "standard" mode, with a 640x480-640x574 framebuffer. VI should
be blanked; if it isn't, then TinyLoad will not blank it before launching
the game so your screen will blink green for a split second as the game
initializes VI. It has been tested to work correctly when launched by the
Homebrew Channel in at least NTSC 480p and PAL interlaced modes. If these
assumptions don't hold then the progress bar display will not work properly,
but the rest of the loader should work fine.
- TinyLoad does not perform _any_ patching of games. The lowmem video mode
setting follows whatever video mode was left set by the application used to
launch TinyLoad, except that PAL games are forced to PAL if NTSC is detected.
This does not patch the game, it's merely the informative value in low memory;
games are free to read SYSCONF/setting.txt and ignore it. I don't really care
because I use 480p mode anyway. If you need more advanced options, just use
Gecko OS.
- Normally, game audio will not work correctly if launched via a loader that
was initially launched via BootMii-boot2. This is a bug in libogc (it doesn't
know how to initialize the DSP for the first time and leaves it in a broken
state), and it affects anything running after the Wii was booted first into
a libogc application, including the System Menu's loader. In other words,
BootMii-boot2 -> HBC -> System Menu (or Gecko OS) -> Game may cause distorted
audio. TinyLoad _does_ work, by resetting the audio hardware to let the game
reinitialize it properly. So, BootMii-boot2 -> HBC -> TinyLoad -> Game will
work fine. This ought to be worked around in a future release of HBC, at
least. I'd suggest fixing libogc, but I know shagkur is just going to rip the
proper code from the SDK again. Anyway, launching using TinyLoad will work
fine as it contains the workaround.
- TinyLoad will load the correct IOS as specified in the partition TMD. It does
not support loading any other IOS.
- TinyLoad will not install updates. Not having the right IOS for the game will
probably result in a red error and reset about halfway through.
Broken stuff:
- I don't think online games work. Not sure why (I do copy the TitleID to the
proper spot, I think). If it works for you, let me know. Likewise, if you know
what the problem is or you can fix it, please let me know.
Who?
====
Program:
Copyright 2008-2009 Hector Martin (marcan) <marcan@marcansoft.com>
Supporting code:
Copyright 2008-2009 Segher Boessenkool <segher@kernel.crashing.org>
Copyright 2008-2009 Andre Heider (dhewg) <dhewg@wiibrew.org>
Copyright 2008 Nuke <wiinuke@gmail.com>
Awesome icon:
Copyright 2009 Freddy Leitner (drmr)
This code is licensed to you under the terms of the GNU GPL, version 2;
see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
The icon is licensed under CC-BY-NC-SA 3.0:
http://creativecommons.org/licenses/by-nc-sa/3.0/
Why?
====
Because:
- System Menu 4.2 forever broke region free via modchips
- I have a USA Wii which I regularly use with EUR games
- Gecko OS is somewhat annoying and recent versions are unstable (for me anyway)
- I refuse to perform retarded firmware mods.
- I autoboot HBC via BootMii-boot2 and using the System Menu takes longer
anyway.
I also think that low-level apps that tightly hug the hardware are very
educational, so why not. And hey, the code is pretty short, so you ought to be
able to read it completely and learn how all this crazy Wii stuff *actually*
works :-)
How?
====
TinyLoad is not compressed. The 4 kilobytes are raw code and data, plus the ELF
header. The original loader was fit in 4 kilobytes by avoiding bloated libraries
like libogc and instead using a small codebase pieced together from bits of the
Twilight Hack and of HBC's reload stub. Extra features (SYSCONF reading, RTC
reading, proper lowmem settings, VI stuff, progress bar, etc) were added by
making space via a combination of increasingly complex compiler options, manual
tweaks, and micro-optimization.
Nonetheless, there is almost no assembly code and the C code, though compact and
odd at times, should be moderately readable. Just keep in mind that I
deliberately leave old values floating around and/or use odd initializations in
order to simplify the code. Also, I haven't commented most of it. If you're
really interested, give me a shout and I'll see what I can do to make it more
acceptable.
If you want some *real* fun, load the ELF in IDA. The function inlining and tail
call goodness ought to provide tons of entertainment.
Where?
======
http://wiibrew.org/TinyLoad
http://marcansoft.com/blog/

62
nand-loader/app_booter.s Normal file
View File

@ -0,0 +1,62 @@
/* Generated by BIN2S - please don't edit directly */
.section .rodata
.balign 4
.global app_booter_bin_size
.global app_booter_bin
app_booter_bin:
.byte 124, 96, 0,166, 84, 99, 4, 94, 96, 99, 32, 0,124, 96, 1, 36
.byte 76, 0, 1, 44, 60, 32,147, 1, 56, 33,131, 64, 56, 0, 0, 0
.byte 148, 1,255,192, 60, 96,147, 0, 56, 99, 3, 32, 56,128, 0, 0
.byte 60,160,147, 0, 56,165, 3, 32,124,163, 40, 80, 72, 0, 2,105
.byte 72, 0, 1,212,148, 33,255,224,124, 8, 2,166,191,129, 0, 16
.byte 124,125, 27,121,144, 1, 0, 36, 56, 96, 0, 0, 65,130, 0,152
.byte 127,190,235,120,127,191,235,120, 59,128, 0, 0,128,191, 0,144
.byte 47,133, 0, 0, 65,158, 0, 40,128,127, 0, 72, 43,131, 0,255
.byte 64,189, 0, 28,128,159, 0, 0,124,157, 34, 20, 72, 0, 2, 57
.byte 128,127, 0, 72,128,159, 0,144, 72, 0, 2, 81, 47,156, 0, 6
.byte 59,255, 0, 4, 59,156, 0, 1, 64,158,255,196, 59,224, 0, 0
.byte 128,190, 0,172, 47,133, 0, 0, 65,158, 0, 40,128,126, 0,100
.byte 43,131, 0,255, 64,189, 0, 28,128,158, 0, 28,124,157, 34, 20
.byte 72, 0, 1,245,128,126, 0,100,128,158, 0,172, 72, 0, 2, 13
.byte 47,159, 0, 10, 59,222, 0, 4, 59,255, 0, 1, 64,158,255,196
.byte 128,125, 0,224,128, 1, 0, 36,187,129, 0, 16, 56, 33, 0, 32
.byte 124, 8, 3,166, 78,128, 0, 32,129, 35, 0, 0, 60, 0,127, 69
.byte 96, 0, 76, 70,127,137, 0, 0, 57, 32, 0, 0, 64,190, 0, 36
.byte 160, 3, 0, 16, 47,128, 0, 2, 64,158, 0, 20,160, 3, 0, 18
.byte 57, 32, 0, 1, 47,128, 0, 20, 65,190, 0, 8, 57, 32,255,255
.byte 125, 35, 75,120, 78,128, 0, 32,124, 8, 2,166,148, 33,255,224
.byte 191,161, 0, 20,124,126, 27,120,144, 1, 0, 36,129, 35, 0, 28
.byte 47,137, 0, 0, 65,158, 0,152,160, 3, 0, 44, 47,128, 0, 0
.byte 65,158, 0,140,160, 3, 0, 42,127,227, 74, 20, 59,160, 0, 0
.byte 47,128, 0, 32, 65,158, 0, 88, 72, 0, 0,116,128, 31, 0, 0
.byte 47,128, 0, 1, 64,190, 0, 68,128,191, 0, 16,128, 31, 0, 20
.byte 129, 63, 0, 12, 47, 5, 0, 0,127,133, 0, 64, 85, 41, 0,190
.byte 101, 35,128, 0,144,127, 0, 12, 65,157, 0, 68, 65,186, 0, 28
.byte 128,159, 0, 4,124,158, 34, 20, 72, 0, 0,253,128,127, 0, 12
.byte 128,159, 0, 20, 72, 0, 1, 21, 59,255, 0, 32,160, 30, 0, 44
.byte 127,157, 0, 0, 59,189, 0, 1, 65,156,255,164,128, 30, 0, 24
.byte 84, 0, 0,190,100, 3,128, 0, 72, 0, 0, 8, 56, 96, 0, 0
.byte 128, 1, 0, 36,187,161, 0, 20, 56, 33, 0, 32,124, 8, 3,166
.byte 78,128, 0, 32,124, 8, 2,166,148, 33,255,224, 60, 96,145, 0
.byte 191,161, 0, 20,144, 1, 0, 36, 75,255,254,225, 47,131, 0, 1
.byte 64,190, 0, 16, 60, 96,145, 0, 75,255,255, 17, 72, 0, 0, 12
.byte 60, 96,145, 0, 75,255,254, 1, 47,131, 0, 0,124,127, 27,120
.byte 65,158, 0, 64, 61, 32,147, 32,129, 41, 0, 0,109, 32, 95, 97
.byte 47,128,114,103, 64,158, 0, 36, 59,163, 0, 8, 60,128,147, 32
.byte 127,163,235,120, 56,160, 0, 24, 72, 0, 0, 77,127,163,235,120
.byte 56,128, 0, 24, 72, 0, 0,101,127,233, 3,166, 78,128, 4, 33
.byte 128, 1, 0, 36,187,161, 0, 20, 56, 33, 0, 32,124, 8, 3,166
.byte 78,128, 0, 32, 56,165, 0, 1, 57, 32, 0, 0,124,169, 3,166
.byte 72, 0, 0, 12,124,137, 25,174, 57, 41, 0, 1, 66, 0,255,248
.byte 78,128, 0, 32, 56,165, 0, 1, 57, 32, 0, 0,124,169, 3,166
.byte 72, 0, 0, 16,124, 9, 32,174,124, 9, 25,174, 57, 41, 0, 1
.byte 66, 0,255,244, 78,128, 0, 32, 56,132, 0, 31,124,132, 26, 20
.byte 84, 99, 0, 52, 84,132, 0, 52, 72, 0, 0, 20,124, 0, 24,108
.byte 124, 0, 4,172,124, 0, 31,172, 56, 99, 0, 32,127,131, 32, 64
.byte 65,156,255,236,124, 0, 4,172, 76, 0, 1, 44, 78,128, 0, 32
.global app_booter_bin_end
app_booter_bin_end:
.align
app_booter_bin_size: .int 800

Binary file not shown.

39
nand-loader/cache.c Normal file
View File

@ -0,0 +1,39 @@
/*
TinyLoad - a simple region free (original) game launcher in 4k
# This code is licensed to you under the terms of the GNU GPL, version 2;
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
/* This code comes from the Twilight Hack */
// Copyright 2008-2009 Segher Boessenkool <segher@kernel.crashing.org>
// Copyright 2008-2009 Hector Martin <marcan@marcansoft.com>
#include "types.h"
void sync_before_read(void *p, u32 len)
{
u32 a, b;
a = (u32)p & ~0x1f;
b = ((u32)p + len + 0x1f) & ~0x1f;
for ( ; a < b; a += 32)
asm("dcbi 0,%0" : : "b"(a) : "memory");
asm("sync ; isync");
}
void sync_after_write(const void *p, u32 len)
{
u32 a, b;
a = (u32)p & ~0x1f;
b = ((u32)p + len + 0x1f) & ~0x1f;
for ( ; a < b; a += 32)
asm("dcbf 0,%0" : : "b"(a));
asm("sync ; isync");
}

21
nand-loader/cache.h Normal file
View File

@ -0,0 +1,21 @@
/*
TinyLoad - a simple region free (original) game launcher in 4k
# This code is licensed to you under the terms of the GNU GPL, version 2;
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
/* This code comes from the Twilight Hack */
// Copyright 2008-2009 Segher Boessenkool <segher@kernel.crashing.org>
// Copyright 2008-2009 Hector Martin <marcan@marcansoft.com>
#ifndef __CACHE_H__
#define __CACHE_H__
#include "types.h"
void sync_before_read(void *p, u32 len);
void sync_after_write(const void *p, u32 len);
#endif

163
nand-loader/crt0.S Normal file
View File

@ -0,0 +1,163 @@
/*
TinyLoad - a simple region free (original) game launcher in 4k
# This code is licensed to you under the terms of the GNU GPL, version 2;
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
# This code comes from the Twilight Hack
# Copyright 2008-2009 Segher Boessenkool <segher@kernel.crashing.org>
# Slightly modified to imitate the homebrew channel stub
*/
.set r0,0; .set r1,1; .set r2,2; .set r3,3; .set r4,4;
.set r5,5; .set r6,6; .set r7,7; .set r8,8; .set r9,9;
.set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14;
.set r15,15; .set r16,16; .set r17,17; .set r18,18; .set r19,19;
.set r20,20; .set r21,21; .set r22,22; .set r23,23; .set r24,24;
.set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29;
.set r30,30; .set r31,31;
#include "hw.h"
.extern _main
#TODO - fixup memset
.globl _start
_start:
bl __init_registers
bl __init_memory
bl __init_syscall
bl __init_sprs
lis r3,__bss_start@h
ori r3,r3,__bss_start@l
li r4,0
lis r5,__bss_end@h
ori r5,r5,__bss_end@l
subf r5,r3,r5
bl _memset
lis r3,__stack_end@h
ori r3,r3,__stack_end@l
li r4,0
lis r5,__stack_top@h
ori r5,r5,__stack_top@l
subf r5,r3,r5
bl _memset
bl _main
0:
b 0b
__init_registers:
li r0,0
li r3,0
li r4,0
li r5,0
li r6,0
li r7,0
li r8,0
li r9,0
li r10,0
li r11,0
li r12,0
li r14,0
li r15,0
li r16,0
li r17,0
li r18,0
li r19,0
li r20,0
li r21,0
li r22,0
li r23,0
li r24,0
li r25,0
li r26,0
li r27,0
li r28,0
li r29,0
li r30,0
li r31,0
lis r1,__stack_top@h
ori r1,r1,__stack_top@l
addi r1,r1,-4
stw r0,0(r1)
stwu r1,-0x38(r1)
lis r2,0
ori r2,r2,0x8000
lis r13,0
ori r13,r13,0x8000
blr
_memset:
clrlwi. r6,r5,29
rlwinm r5,r5,30,2,31
addi r3,r3,-4
mtctr r5
0:
stwu r4,4(r3)
bdnz+ 0b
cmplwi r6,0
beq- 2f
1:
stbu r4,1(r3)
addic. r6,r6,-1
bne+ 1b
2:
blr
__init_memory:
mflr r0
stw r0, 0x04(r1)
stwu r1,-0x10(r1)
stw r31,0x0C(r1)
mfspr r3,rHID0
rlwinm r0,r3,0,16,16 #HID0[ICE]
cmplwi r0,0
bne- 0f
bl ICacheEnable
0:
mfspr r3,rHID0
rlwinm r0,r3,0,17,17 #HID0[DCE]
cmplwi r0,0
bne- 1f
bl DCacheEnable
1:
mfl2cr r3
rlwinm r0,r3,0,0,0 #L2CR[L2E]
cmplwi r0,0
bne- 2f
bl L2_Init
bl L2_Enable
2:
lwz r0, 0x14(r1)
lwz r31,0x0C(r1)
addi r1,r1,0x10
mtlr r0
blr
__init_sprs:
mflr r0
stw r0, 0x04(r1)
stwu r1,-0x18(r1)
stw r31,0x14(r1)
stw r30,0x10(r1)
stw r29,0x0C(r1)
li r3,0
mtmmcr0 r3
mtmmcr1 r3
mtpmc1 r3
mtpmc2 r3
mtpmc3 r3
mtpmc4 r3
mfspr r3,rHID0
ori r3,r3,HID0_SPD #HID0[SPD]
mtspr rHID0,r3
mfspr r3,rHID2
rlwinm r3,r3,0,2,0 #HID2[WPE]
mtspr rHID2,r3
lwz r0, 0x1C(r1)
lwz r31,0x14(r1)
lwz r30,0x10(r1)
lwz r29,0x0C(r1)
addi r1,r1,0x18
mtlr r0
blr

107
nand-loader/hw.h Normal file
View File

@ -0,0 +1,107 @@
#ifndef __HW_H__
#define __HW_H__
#define MSR_POW (1<<18)
#define MSR_ILE (1<<16)
#define MSR_EE (1<<15)
#define MSR_PR (1<<14)
#define MSR_FP (1<<13)
#define MSR_ME (1<<12)
#define MSR_FE0 (1<<11)
#define MSR_SE (1<<10)
#define MSR_BE (1<< 9)
#define MSR_FE1 (1<< 8)
#define MSR_IP (1<< 6)
#define MSR_IR (1<< 5)
#define MSR_DR (1<< 4)
#define MSR_RI (1<< 1)
#define MSR_LE (1<< 0)
#define HID0_EMCP (1<<31)
#define HID0_DBP (1<<30)
#define HID0_EBA (1<<29)
#define HID0_EBD (1<<28)
#define HID0_BCLK (1<<27)
#define HID0_ECLK (1<<25)
#define HID0_PAR (1<<24)
#define HID0_DOZE (1<<23)
#define HID0_NAP (1<<22)
#define HID0_SLEEP (1<<21)
#define HID0_DPM (1<<20)
#define HID0_NHR (1<<16)
#define HID0_ICE (1<<15)
#define HID0_DCE (1<<14)
#define HID0_ILOCK (1<<13)
#define HID0_DLOCK (1<<12)
#define HID0_ICFI (1<<11)
#define HID0_DCFI (1<<10)
#define HID0_SPD (1<< 9)
#define HID0_IFEM (1<< 8)
#define HID0_SGE (1<< 7)
#define HID0_DCFA (1<< 6)
#define HID0_BTIC (1<< 5)
#define HID0_ABE (1<< 3)
#define HID0_BHT (1<< 2)
#define HID0_NOOPTI (1<< 0)
#define HID2_LSQE (1<<31)
#define HID2_WPE (1<<30)
#define HID2_PSE (1<<29)
#define HID2_LCE (1<<28)
#define L2CR_L2E (1<<31)
#define L2CR_L2CE (1<<30)
#define L2CR_L2DO (1<<22)
#define L2CR_L2I (1<<21)
#define L2CR_L2WT (1<<19)
#define L2CR_L2TS (1<<18)
#define L2CR_L2IP (1<< 0)
#define DMAU_MEM_ADDR_MASK 0xFFFFFFE0
#define DMAU_LENU(x) (x & 0x1F)
#define DMAL_LC_ADDR_MASK 0xFFFFFFE0
#define DMAL_LD (1<< 4)
#define DMAL_LENL(x) (x & 0xC)
#define DMAL_T (1<< 1)
#define DMAL_F (1<< 0)
#define BATU_BEPI_MASK 0xFFFC0000
#define BATU_BL(x) (x & 0x00001FFC)
#define BATU_VS (1<< 1)
#define BATU_VP (1<< 0)
#define BATL_BRPN_MASK 0xFFFC0000
#define BATL_WIMG_MASK 0x78
#define BATL_PP (1<< 0)
// BATU - 0x80001FFF == 256Mbytes
// 1000 0000 000x xxx0 0001 1111 1111 11xx
// 0x80000000|256Mbytes|VS|VP
// BATL - 0x00000002
// 0000 0000 0000 000x xxxx xxxx x000 0x10
// PP=b10
//
// BATU - 0xC0001FFF == 256Mbytes
// BATL - 0x0000002a
// 0000 0000 0000 000x xxxx xxxx x010 1x10
// WIMG=b0101|PP=b10
//
#define rHID2 920
#define rDMAU 922
#define rDMAL 923
#define rHID0 1008
#define rHID1 1009
#define rHID4 1011
/*
* Upper PTE
* 0|1-24|25|26-31
* V|VSID|H |API
*
* Lower PTE
* 0-19|20-22|23|24|25-28|29|30-31
* RPN |000 |R |C |WIMG |0 |PP
*/
#endif

286
nand-loader/ios.c Normal file
View File

@ -0,0 +1,286 @@
/*
TinyLoad - a simple region free (original) game launcher in 4k
# This code is licensed to you under the terms of the GNU GPL, version 2;
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
/* This code comes from HBC's stub which was based on the Twilight Hack code */
// Copyright 2008-2009 Segher Boessenkool <segher@kernel.crashing.org>
// Copyright 2008-2009 Andre Heider <dhewg@wiibrew.org>
// Copyright 2008-2009 Hector Martin <marcan@marcansoft.com>
#include "ios.h"
#include "cache.h"
#include "utils.h"
#define virt_to_phys(x) ((u32*)(((u32)(x))&0x3FFFFFFF))
#define phys_to_virt(x) ((u32*)(((u32)(x))|0x80000000))
// Low-level IPC access.
static inline u32
iread32(u32 addr)
{
u32 x;
asm volatile("lwz %0,0(%1) ; sync ; isync" : "=r"(x) : "b"(0xc0000000 | addr));
return x;
}
static inline void
iwrite32(u32 addr, u32 x)
{
asm volatile("stw %0,0(%1) ; eieio" : : "r"(x), "b"(0xc0000000 | addr));
}
static u32 _ipc_read(u32 reg) __attribute__((noinline));
static void _ipc_write(u32 reg, u32 value) __attribute__((noinline));
static void ipc_bell(u32 w) __attribute__((noinline));
// inline the 4*, don't inline the 0x0d0 stuff. yes, this saves a few bytes.
static u32
_ipc_read(u32 reg)
{
return iread32(0x0d000000 + reg);
}
static void
_ipc_write(u32 reg, u32 value)
{
iwrite32(0x0d000000 + reg, value);
}
static inline u32
ipc_read(u32 reg)
{
return _ipc_read(4*reg);
}
static inline void
ipc_write(u32 reg, u32 value)
{
_ipc_write(4*reg, value);
}
static void
ipc_bell(u32 w)
{
ipc_write(1, w);
}
static void ios_delay(void) __attribute__((noinline));
static void
ios_delay(void)
{
usleep(500);
}
static void
ipc_wait_ack(void)
{
while(!(ipc_read(1) & 0x2))
;
ios_delay();
}
static void
ipc_wait_reply(void)
{
while(!(ipc_read(1) & 0x4))
;
ios_delay();
}
static u32
ipc_wait(void)
{
u32 ret;
while(!((ret = ipc_read(1)) & 0x6))
;
ios_delay();
return ret;
}
// Mid-level IPC access.
struct ipc {
u32 cmd;
int result;
int fd;
u32 arg[5];
u32 user[8];
};
static struct ipc ipc ALIGNED(64);
static void
ipc_send_request(void)
{
sync_after_write(&ipc, 0x40);
ipc_write(0, (u32)virt_to_phys(&ipc));
ipc_bell(1);
ipc_wait_ack();
ipc_bell(2);
}
static int
ipc_send_twoack(void)
{
sync_after_write(&ipc, 0x40);
ios_delay();
ipc_write(0, (u32)virt_to_phys(&ipc));
ipc_bell(1);
if(ipc_wait() & 4)
return 0;
ipc_bell(2);
if(ipc_wait() & 4)
return 0;
ipc_bell(2);
ipc_bell(8);
return 1;
}
static void
ipc_recv_reply(void)
{
for (;;)
{
u32 reply;
ipc_wait_reply();
reply = ipc_read(2);
ipc_bell(4);
ipc_bell(8);
if (((u32*)reply) == virt_to_phys(&ipc))
break;
}
sync_before_read(&ipc, 0x40);
}
// High-level IPC access.
int
ios_open(const char *filename, u32 mode)
{
sync_after_write((void*)filename, 0x20);
ipc.cmd = 1;
ipc.fd = 0;
ipc.arg[0] = (u32)virt_to_phys(filename);
ipc.arg[1] = mode;
ipc_send_request();
ipc_recv_reply();
return ipc.result;
}
int
ios_close(int fd)
{
ipc.cmd = 2;
ipc.fd = fd;
ipc_send_request();
ipc_recv_reply();
return ipc.result;
}
static void
ios_std(int fd, int cmd)
{
ipc.cmd = cmd;
ipc.fd = fd;
ipc_send_request();
ipc_recv_reply();
}
int
ios_read(int fd, void *buf, u32 size)
{
ipc.arg[0] = (u32)virt_to_phys(buf);
ipc.arg[1] = size;
ios_std(fd, 3);
sync_before_read(buf, size);
return ipc.result;
}
int
_ios_ioctlv(int fd, u32 n, u32 in_count, u32 out_count, struct ioctlv *vec, int reboot)
{
u32 i;
for (i = 0; i < in_count + out_count; i++)
{
if (vec[i].data)
{
sync_after_write(vec[i].data, vec[i].len);
vec[i].data = (void *)virt_to_phys(vec[i].data);
}
}
sync_after_write(vec, (in_count + out_count) * sizeof *vec);
ipc.cmd = 7;
ipc.fd = fd;
ipc.arg[0] = n;
ipc.arg[1] = in_count;
ipc.arg[2] = out_count;
ipc.arg[3] = (u32)virt_to_phys(vec);
if(reboot)
{
if(ipc_send_twoack())
return 0;
}
else
ipc_send_request();
ipc_recv_reply();
for(i = in_count; i < in_count + out_count; i++)
{
if (vec[i].data)
{
vec[i].data = phys_to_virt((u32)vec[i].data);
sync_before_read(vec[i].data, vec[i].len);
}
}
if(reboot && (ipc.result >= 0))
return -100;
return ipc.result;
}
int
ios_ioctlv(int fd, u32 n, u32 in_count, u32 out_count, struct ioctlv *vec)
{
return _ios_ioctlv(fd, n, in_count, out_count, vec, 0);
}
int
ios_ioctlvreboot(int fd, u32 n, u32 in_count, u32 out_count, struct ioctlv *vec)
{
return _ios_ioctlv(fd, n, in_count, out_count, vec, 1);
}

27
nand-loader/ios.h Normal file
View File

@ -0,0 +1,27 @@
/*
TinyLoad - a simple region free (original) game launcher in 4k
# This code is licensed to you under the terms of the GNU GPL, version 2;
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
#ifndef __IOS_H__
#define __IOS_H__
// Copyright 2008-2009 Hector Martin <marcan@marcansoft.com>
#include "types.h"
struct ioctlv {
void *data;
u32 len;
};
int ios_open(const char *filename, u32 mode);
int ios_close(int fd);
int ios_ioctlv(int fd, u32 n, u32 in_count, u32 out_count, struct ioctlv *vec);
int ios_ioctlvreboot(int fd, u32 n, u32 in_count, u32 out_count, struct ioctlv *vec);
int ios_read(int fd, void *buf, u32 size);
#endif

167
nand-loader/main.c Normal file
View File

@ -0,0 +1,167 @@
/*
TinyLoad - a simple region free (original) game launcher in 4k
# This code is licensed to you under the terms of the GNU GPL, version 2;
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
/* This code comes from HBC's stub which was based on dhewg's geckoloader stub */
// Copyright 2008-2009 Andre Heider <dhewg@wiibrew.org>
// Copyright 2008-2009 Hector Martin <marcan@marcansoft.com>
#include "utils.h"
#include "ios.h"
#include "cache.h"
#include "memory.h"
#define IOCTL_ES_LAUNCH 0x08
#define IOCTL_ES_OPENCONTENT 0x09
#define IOCTL_ES_READCONTENT 0x0A
#define IOCTL_ES_CLOSECONTENT 0x0B
#define IOCTL_ES_GETVIEWCNT 0x12
#define IOCTL_ES_GETVIEWS 0x13
#define IOCTL_ES_GETTITLEID 0x20
#define IOCTL_ES_SEEKCONTENT 0x23
#define TITLE_ID(x,y) (((u64)(x) << 32) | (y))
extern const u8 app_booter_bin[];
extern const u32 app_booter_bin_size;
static struct ioctlv vecs[16] ALIGNED(64);
s32 cfd ALIGNED(32);
int es_fd = -1;
typedef void (*entry)(void);
static int es_init(void)
{
es_fd = ios_open("/dev/es", 0);
return es_fd;
}
static void es_close(void)
{
if(es_fd >= 0)
ios_close(es_fd);
es_fd = -1;
}
static int es_launchtitle(u64 titleID)
{
static u64 xtitleID __attribute__((aligned(32)));
static u32 cntviews __attribute__((aligned(32)));
static u8 tikviews[0xd8*4] __attribute__((aligned(32)));
xtitleID = titleID;
vecs[0].data = &xtitleID;
vecs[0].len = 8;
vecs[1].data = &cntviews;
vecs[1].len = 4;
int ret = ios_ioctlv(es_fd, IOCTL_ES_GETVIEWCNT, 1, 1, vecs);
if(ret<0) return ret;
if(cntviews>4) return -1;
vecs[2].data = tikviews;
vecs[2].len = 0xd8*cntviews;
ret = ios_ioctlv(es_fd, IOCTL_ES_GETVIEWS, 2, 1, vecs);
if(ret<0) return ret;
vecs[1].data = tikviews;
vecs[1].len = 0xd8;
ret = ios_ioctlvreboot(es_fd, IOCTL_ES_LAUNCH, 2, 0, vecs);
return ret;
}
static int es_opencontent(u32 content_num)
{
vecs[0].data = &content_num;
vecs[0].len = 4;
cfd = ios_ioctlv(es_fd, IOCTL_ES_OPENCONTENT, 1, 0, vecs);
return cfd;
}
static int es_seekcontent(s32 place, s32 from)
{
vecs[0].data = &cfd;
vecs[0].len = 4;
vecs[1].data = &place;
vecs[1].len = 4;
vecs[2].data = &from;
vecs[2].len = 4;
return ios_ioctlv(es_fd, IOCTL_ES_SEEKCONTENT, 3, 0, vecs);
}
static int es_readcontent(void *data, u32 size)
{
vecs[0].data = &cfd;
vecs[0].len = 4;
vecs[1].data = data;
vecs[1].len = size;
return ios_ioctlv(es_fd, IOCTL_ES_READCONTENT, 1, 1, vecs);
}
static int es_closecontent()
{
vecs[0].data = &cfd;
vecs[0].len = 4;
return ios_ioctlv(es_fd, IOCTL_ES_CLOSECONTENT, 1, 0, vecs);
}
void memoryset(u8 *dst, const u8 value, u32 size)
{
u32 i;
for(i = 0; i < size; ++i)
dst[i] = value;
}
void memorycopy(u8 *dst, const u8 *src, u32 size)
{
u32 i;
for(i = 0; i < size; ++i)
dst[i] = src[i];
}
static void *dol_data = (void*)0x91000000; /* 32MB Max */
static void *appbooter_entry = (void*)0x93000000;
void _main(void)
{
u32 size = 0;
es_init();
/* load up dol */
es_opencontent(2); //stub is 1, real dol is 2
if(cfd < 0) goto fail;
size = es_seekcontent(0, 2);
es_seekcontent(0, 0);
es_readcontent(dol_data, size);
sync_after_write(dol_data, size);
es_closecontent();
if(size == 0) goto fail;
es_close();
/* Boot our good old appbooter stuff */
memorycopy(appbooter_entry, app_booter_bin, app_booter_bin_size);
sync_after_write(appbooter_entry, app_booter_bin_size);
entry EntryPoint = (entry)appbooter_entry;
EntryPoint();
fail:
es_launchtitle(TITLE_ID(1,2));
while(1) usleep(500);
}
#define SYSCALL_VECTOR ((u8*)0x80000C00)
void __init_syscall()
{
u8* sc_vector = SYSCALL_VECTOR;
u32 bytes = (u32)DCFlashInvalidate - (u32)__temp_abe;
u8* from = (u8*)__temp_abe;
for ( ; bytes != 0 ; --bytes )
{
*sc_vector = *from;
sc_vector++;
from++;
}
sync_after_write(SYSCALL_VECTOR, 0x100);
ICInvalidateRange(SYSCALL_VECTOR, 0x100);
}

View File

@ -0,0 +1,92 @@
/****************************************************************************
* Copyright (C) 2012 FIX94
*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <cmath>
#include <x86intrin.h>
unsigned char dol_header[0x100];
#define ALIGN32(x) (((x) + 31) & ~31)
int main()
{
char nullBuf[1];
nullBuf[0] = 0x00;
memset(&dol_header, 0, 0x100);
/* Read in shit */
FILE *f = fopen("loader.bin", "rb");
if(f == NULL)
{
printf("no loader\n");
return -1;
}
fseek(f, 0, SEEK_END);
unsigned int size = ftell(f);
rewind(f);
unsigned char *buf = (unsigned char*)malloc(size);
fread(buf, size, 1, f);
fclose(f);
f = fopen("stub.bin", "rb");
if(f == NULL)
{
printf("no stub\n");
free(buf);
return -2;
}
fseek(f, 0, SEEK_END);
unsigned int stub_size = ftell(f);
rewind(f);
unsigned char *stub_buf = (unsigned char*)malloc(stub_size);
fread(stub_buf, stub_size, 1, f);
fclose(f);
/* Add stub text */
((unsigned int*)dol_header)[0] = _bswap(0x100); /* Header size */
((unsigned int*)dol_header)[18] = _bswap(0x80003400);
((unsigned int*)dol_header)[36] = _bswap(ALIGN32(stub_size));
/* Add NAND Loader text */
((unsigned int*)dol_header)[1] = _bswap(0x100 + ALIGN32(stub_size));
((unsigned int*)dol_header)[19] = _bswap(0x80004000);
((unsigned int*)dol_header)[37] = _bswap(ALIGN32(size));
/* Set our entry to the NAND Loader */
((unsigned int*)dol_header)[56] = _bswap(0x80004000);
/* Write it to a new file */
f = fopen("00000001.app", "wb");
fwrite(dol_header, 0x100, 1, f); /* Write header first */
fwrite(stub_buf, stub_size, 1, f); /* Then stub */
if(ALIGN32(stub_size) > stub_size)
{
for(int i = 0; i < (ALIGN32(stub_size) - stub_size); ++i)
fwrite(nullBuf, 1, 1, f);
}
fwrite(buf, size, 1, f); /* and last nand loader */
if(ALIGN32(size) > size)
{
for(int i = 0; i < (ALIGN32(size) - size); ++i)
fwrite(nullBuf, 1, 1, f);
}
fclose(f);
free(buf);
free(stub_buf);
printf("done\n");
return 0;
}

Binary file not shown.

192
nand-loader/memory.S Normal file
View File

@ -0,0 +1,192 @@
.set r0,0; .set r1,1; .set r2,2; .set r3,3; .set r4,4;
.set r5,5; .set r6,6; .set r7,7; .set r8,8; .set r9,9;
.set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14;
.set r15,15; .set r16,16; .set r17,17; .set r18,18; .set r19,19;
.set r20,20; .set r21,21; .set r22,22; .set r23,23; .set r24,24;
.set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29;
.set r30,30; .set r31,31;
#include "hw.h"
.global __temp_abe
__temp_abe:
mfspr r3,rHID0
ori r4,r3,HID0_ABE #HID0[ABE]
mtspr rHID0,r4
isync
sync
mtspr rHID0,r3
rfi
.global DCFlashInvalidate
DCFlashInvalidate:
nop
mfspr r3,rHID0
ori r3,r3,HID0_DCFI #HID0[DCFI]
mtspr rHID0,r3
blr
.global DCacheEnable
DCacheEnable:
sync
mfspr r3,rHID0
ori r3,r3,HID0_DCE #HID0[DCE]
mtspr rHID0,r3
blr
.global DCBlockInvalidate
DCBlockInvalidate:
cmplwi r4,0
blelr
clrlwi. r5,r3,27
beq- 0f
addi r4,r4,0x20
0:
addi r4,r4,0x1F
rlwinm r4,r4,27,5,31
mtctr r4
1:
dcbi r0,r3
addi r3,r3,0x20
bdnz+ 1b
blr
DCBlockFlushSc:
cmplwi r4,0
blelr
clrlwi. r5,r3,27
beq- 0f
addi r4,r4,0x20
0:
addi r4,r4,0x1F
rlwinm r4,r4,27,5,31
mtctr r4
1:
dcbf r0,r3
addi r3,r3,0x20
bdnz+ 1b
sc
blr
DCBlockFlush:
cmplwi r4,0
blelr
clrlwi. r5,r3,27
beq- 0f
addi r4,r4,0x20
0:
addi r4,r4,0x1F
rlwinm r4,r4,27,5,31
mtctr r4
1:
dcbf r0,r3
addi r3,r3,0x20
bdnz+ 1b
blr
.global ICInvalidateRange
ICInvalidateRange:
cmplwi r4,0
blelr
clrlwi. r5,r3,27
beq- 0f
addi r4,r4,0x20
0:
addi r4,r4,0x1F
rlwinm r4,r4,27,5,31
mtctr r4
1:
icbi r0,r3
addi r3,r3,0x20
bdnz+ 1b
sync
isync
blr
ICFlashInvalidate:
mfspr r3,rHID0
ori r3,r3,HID0_ICFI #HID0[ICFI]
mtspr rHID0,r3
blr
.global ICacheEnable
ICacheEnable:
isync
mfspr r3,rHID0
ori r3,r3,HID0_ICE #HID0[ICE]
mtspr rHID0,r3
blr
ICacheDisable:
isync
mfspr r3,rHID0
rlwinm r3,r3,0,17,15 #HID0[ICE]
mtspr rHID0,r3
blr
ISync:
isync
blr
.global L2_Init
L2_Init:
mflr r0
stw r0, 0x04(r1)
stwu r1,-0x10(r1)
stw r31,0x0C(r1)
mfmsr r3
mr r31,r3
sync
li r3,MSR_IR|MSR_DR #MSR[IR|DR]
mtmsr r3
sync
bl L2_Disable
bl L2_Invalidate
mr r3,r31
mtmsr r3
lwz r0, 0x14(r1)
lwz r31,0x0C(r1)
mtlr r0
blr
.global L2_Enable
L2_Enable:
mfl2cr r3
oris r0,r3,0x8000 #L2CR[L2E]
rlwinm r3,r0,0,11,9 #L2CR[L2I]
mtl2cr r3
blr
L2_Disable:
sync
mfl2cr r3
clrlwi r3,r3,1 #L2CR[L2E]
mtl2cr r3
sync
blr
L2_Invalidate:
mflr r0
stw r0, 0x04(r1)
stwu r1,-0x08(r1)
bl L2_Disable
mfl2cr r3
oris r3,r3,0x200 #L2CR[L2I]
mtl2cr r3
0:
mfl2cr r3
clrlwi r0,r3,31 #L2CR[L2IP]
cmplwi r0,0
bne+ 0b
mfl2cr r3
rlwinm r3,r3,0,11,9 #L2CR[L2I]
mtl2cr r3
1:
mfl2cr r3
clrlwi r0,r3,31 #L2CR[L2IP]
cmplwi r0,0
bne+ 1b
lwz r0,0x0C(r1)
addi r1,r1,0x08
mtlr r0
blr

9
nand-loader/memory.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef __MEMORY_H__
#define __MEMORY_H__
void __temp_abe(void);
void ICInvalidateRange(void *, int);
void DCFlashInvalidate(void *, int);
#endif

35
nand-loader/openstub.ld Normal file
View File

@ -0,0 +1,35 @@
/*
TinyLoad - a simple region free (original) game launcher in 4k
# This code is licensed to you under the terms of the GNU GPL, version 2;
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
OUTPUT_FORMAT("elf32-powerpc")
OUTPUT_ARCH(powerpc:common)
ENTRY(_start)
PHDRS {
app PT_LOAD FLAGS(7);
}
SECTIONS {
. = 0x80004000;
.text : { *(.text) *(.text.*) } :app
.data : { *(.data) *(.data.*) }
.rodata : { *(.rodata) *(.rodata.*) }
__bss_start = .;
.bss : { *(.bss) *(.bss.*) }
__bss_end = .;
. = ALIGN(64);
__stack_end = .;
.stack : {
. += 0x8000;
__stack_top = .;
}
}

42
nand-loader/stub/Makefile Normal file
View File

@ -0,0 +1,42 @@
PREFIX = powerpc-eabi-
AR = $(PREFIX)ar
AS = $(PREFIX)as
CC = $(PREFIX)gcc
CXX = $(PREFIX)g++
LD = $(PREFIX)ld
OBJCOPY = $(PREFIX)objcopy
RANLIB = $(PREFIX)ranlib
STRIP = $(PREFIX)strip
MACHDEP = -mcpu=750 -mno-eabi -mhard-float
LDFLAGS = $(MACHDEP) -n -nostartfiles -nostdlib -Wl,-T,openstub.ld -L.
ASFLAGS = -D_LANGUAGE_ASSEMBLY -DHW_RVL
TARGET_LINKED = stub.elf
TARGET = stub.bin
OBJS = crt0.o
DEPDIR = .deps
all: $(TARGET)
%.o: %.s
@echo " ASSEMBLE $<"
@$(CC) $(ASFLAGS) -c $< -o $@
%.o: %.S
@echo " ASSEMBLE $<"
@$(CC) $(ASFLAGS) -c $< -o $@
$(TARGET_LINKED): $(OBJS)
@echo " LINK $@"
@$(CC) -g -o $@ $(LDFLAGS) $(OBJS)
$(TARGET): $(TARGET_LINKED)
@echo " OBJCOPY $@"
@$(OBJCOPY) -O binary $< $@
clean:
rm -rf $(TARGET_LINKED) $(TARGET) $(OBJS) $(DEPDIR)

123
nand-loader/stub/crt0.S Normal file
View File

@ -0,0 +1,123 @@
/*
TinyLoad - a simple region free (original) game launcher in 4k
# This code is licensed to you under the terms of the GNU GPL, version 2;
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
# This code comes from the Twilight Hack
# Copyright 2008-2009 Segher Boessenkool <segher@kernel.crashing.org>
# Slightly modified to imitate the homebrew channel stub
*/
.set r0,0; .set r1,1; .set r2,2; .set r3,3; .set r4,4;
.set r5,5; .set r6,6; .set r7,7; .set r8,8; .set r9,9;
.set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14;
.set r15,15; .set r16,16; .set r17,17; .set r18,18; .set r19,19;
.set r20,20; .set r21,21; .set r22,22; .set r23,23; .set r24,24;
.set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29;
.set r30,30; .set r31,31;
#include "hw.h"
.globl _start
_start:
mfmsr r3
rlwinm r4,r3,0,17,15 # MSR_EE
rlwinm r4,r4,0,26,24 # MSR_IP
mtmsr r4
isync
lis r3,_setup@h
ori r3,r3,_setup@l
clrlwi r3,r3,2
mtsrr0 r3
mfmsr r3
li r4,MSR_IR|MSR_DR
andc r3,r3,r4
mtsrr1 r3
rfi
#0001 0001 0000 1100 0110 0100
#BHT,BTIC,DCFA,DCFI,ICFI,NHR,DPM
_setup:
lis r3,0x11
ori r3,r3,0xC64 #0x110C64
mtspr rHID0,r3
isync
li r4,MSR_FP
mtmsr r4
ori r3,r3,HID0_ICE|HID0_DCE
mtspr rHID0,r3
isync
li r0,0
mtibatu 0,r0
mtibatu 1,r0
mtibatu 2,r0
mtibatu 3,r0
mtdbatu 0,r0
mtdbatu 1,r0
mtdbatu 2,r0
mtdbatu 3,r0
#mtibatl 0,r0
mtspr 560,r0
mtspr 562,r0
mtspr 564,r0
mtspr 566,r0
mtspr 568,r0
mtspr 570,r0
mtspr 572,r0
mtspr 574,r0
isync
lis r0,0x8000
mtsr 0,r0
mtsr 1,r0
mtsr 2,r0
mtsr 3,r0
mtsr 4,r0
mtsr 5,r0
mtsr 6,r0
mtsr 7,r0
mtsr 8,r0
mtsr 9,r0
mtsr 10,r0
mtsr 11,r0
mtsr 12,r0
mtsr 13,r0
mtsr 14,r0
mtsr 15,r0
isync
li r3,2 #0x00000000|PP=2
lis r4,0x8000
ori r4,r4,0x1FFF #0x80000000|256Mbytes|VS|VP
mtibatl 0,r3
mtibatu 0,r4
mtdbatl 0,r3
mtdbatu 0,r4
isync
addis r3,r3,0x1000 #0x10000000|PP=2
addis r4,r4,0x1000 #0x90000000|256Mbytes|VS|VP
mtspr 561,r3
mtspr 560,r4
mtspr 569,r3
mtspr 568,r4
isync
li r3,0x2A #0x00000000|I|G|PP=2
lis r4,0xC000
ori r4,r4,0x1FFF #0xC0000000|256Mbytes|VS|VP
mtdbatu 1,r3
mtdbatu 1,r4
isync
addis r3,r3,0x1000 #0x10000000|I|G|PP=2
addis r4,r4,0x1000 #0xD0000000|256Mbytes|VS|VP
mtspr 571,r3
mtspr 570,r4
isync
lis r3,0x8200
mtspr 1011,r3
lis r3,0x8000
ori r3,r3,0x4000
mtsrr0 r3
mfmsr r3
ori r3,r3,MSR_DR|MSR_IR
mtsrr1 r3
rfi

107
nand-loader/stub/hw.h Normal file
View File

@ -0,0 +1,107 @@
#ifndef __HW_H__
#define __HW_H__
#define MSR_POW (1<<18)
#define MSR_ILE (1<<16)
#define MSR_EE (1<<15)
#define MSR_PR (1<<14)
#define MSR_FP (1<<13)
#define MSR_ME (1<<12)
#define MSR_FE0 (1<<11)
#define MSR_SE (1<<10)
#define MSR_BE (1<< 9)
#define MSR_FE1 (1<< 8)
#define MSR_IP (1<< 6)
#define MSR_IR (1<< 5)
#define MSR_DR (1<< 4)
#define MSR_RI (1<< 1)
#define MSR_LE (1<< 0)
#define HID0_EMCP (1<<31)
#define HID0_DBP (1<<30)
#define HID0_EBA (1<<29)
#define HID0_EBD (1<<28)
#define HID0_BCLK (1<<27)
#define HID0_ECLK (1<<25)
#define HID0_PAR (1<<24)
#define HID0_DOZE (1<<23)
#define HID0_NAP (1<<22)
#define HID0_SLEEP (1<<21)
#define HID0_DPM (1<<20)
#define HID0_NHR (1<<16)
#define HID0_ICE (1<<15)
#define HID0_DCE (1<<14)
#define HID0_ILOCK (1<<13)
#define HID0_DLOCK (1<<12)
#define HID0_ICFI (1<<11)
#define HID0_DCFI (1<<10)
#define HID0_SPD (1<< 9)
#define HID0_IFEM (1<< 8)
#define HID0_SGE (1<< 7)
#define HID0_DCFA (1<< 6)
#define HID0_BTIC (1<< 5)
#define HID0_ABE (1<< 3)
#define HID0_BHT (1<< 2)
#define HID0_NOOPTI (1<< 0)
#define HID2_LSQE (1<<31)
#define HID2_WPE (1<<30)
#define HID2_PSE (1<<29)
#define HID2_LCE (1<<28)
#define L2CR_L2E (1<<31)
#define L2CR_L2CE (1<<30)
#define L2CR_L2DO (1<<22)
#define L2CR_L2I (1<<21)
#define L2CR_L2WT (1<<19)
#define L2CR_L2TS (1<<18)
#define L2CR_L2IP (1<< 0)
#define DMAU_MEM_ADDR_MASK 0xFFFFFFE0
#define DMAU_LENU(x) (x & 0x1F)
#define DMAL_LC_ADDR_MASK 0xFFFFFFE0
#define DMAL_LD (1<< 4)
#define DMAL_LENL(x) (x & 0xC)
#define DMAL_T (1<< 1)
#define DMAL_F (1<< 0)
#define BATU_BEPI_MASK 0xFFFC0000
#define BATU_BL(x) (x & 0x00001FFC)
#define BATU_VS (1<< 1)
#define BATU_VP (1<< 0)
#define BATL_BRPN_MASK 0xFFFC0000
#define BATL_WIMG_MASK 0x78
#define BATL_PP (1<< 0)
// BATU - 0x80001FFF == 256Mbytes
// 1000 0000 000x xxx0 0001 1111 1111 11xx
// 0x80000000|256Mbytes|VS|VP
// BATL - 0x00000002
// 0000 0000 0000 000x xxxx xxxx x000 0x10
// PP=b10
//
// BATU - 0xC0001FFF == 256Mbytes
// BATL - 0x0000002a
// 0000 0000 0000 000x xxxx xxxx x010 1x10
// WIMG=b0101|PP=b10
//
#define rHID2 920
#define rDMAU 922
#define rDMAL 923
#define rHID0 1008
#define rHID1 1009
#define rHID4 1011
/*
* Upper PTE
* 0|1-24|25|26-31
* V|VSID|H |API
*
* Lower PTE
* 0-19|20-22|23|24|25-28|29|30-31
* RPN |000 |R |C |WIMG |0 |PP
*/
#endif

View File

@ -0,0 +1,19 @@
/*
TinyLoad - a simple region free (original) game launcher in 4k
# This code is licensed to you under the terms of the GNU GPL, version 2;
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
OUTPUT_FORMAT("elf32-powerpc")
OUTPUT_ARCH(powerpc:common)
ENTRY(_start)
PHDRS {
app PT_LOAD FLAGS(7);
}
SECTIONS {
.text : { *(.text) *(.text.*) } :app
}

32
nand-loader/types.h Normal file
View File

@ -0,0 +1,32 @@
/*
TinyLoad - a simple region free (original) game launcher in 4k
# This code is licensed to you under the terms of the GNU GPL, version 2;
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
// Copyright 2008-2009 Hector Martin <marcan@marcansoft.com>
#ifndef __TYPES_H__
#define __TYPES_H__
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long long u64;
typedef char s8;
typedef short s16;
typedef int s32;
typedef long long s64;
typedef volatile unsigned char vu8;
typedef volatile unsigned short vu16;
typedef volatile unsigned int vu32;
typedef volatile unsigned long long vu64;
#define NULL ((void *)0)
#define ALIGNED(n) __attribute__((aligned(n)))
#endif

33
nand-loader/utils.c Normal file
View File

@ -0,0 +1,33 @@
/*
TinyLoad - a simple region free (original) game launcher in 4k
# This code is licensed to you under the terms of the GNU GPL, version 2;
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
/* This code comes from HBC's stub which was based on geckoloader and the Twilight Hack code */
/* Some of these routines are from public domain sources */
// Copyright 2008-2009 Segher Boessenkool <segher@kernel.crashing.org>
// Copyright 2008-2009 Andre Heider <dhewg@wiibrew.org>
// Copyright 2008-2009 Hector Martin <marcan@marcansoft.com>
#include "types.h"
#include "utils.h"
static u32
get_time(void)
{
u32 x;
asm volatile("mftb %0" : "=r"(x));
return x;
}
void
usleep(u32 us)
{
u32 _start = get_time();
while ((get_time() - _start) < (91*us)) ;
}

17
nand-loader/utils.h Normal file
View File

@ -0,0 +1,17 @@
/*
TinyLoad - a simple region free (original) game launcher in 4k
# This code is licensed to you under the terms of the GNU GPL, version 2;
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
// Copyright 2008-2009 Hector Martin <marcan@marcansoft.com>
#ifndef __UTILS_H__
#define __UTILS_H__
#include "types.h"
void usleep(u32 us);
#endif