revert new nand loader import

This commit is contained in:
Christopher Roy Bratusek 2016-08-14 20:08:54 +02:00
parent 15bd5e5b42
commit da3d029cf6
56 changed files with 4194 additions and 2122 deletions

View File

@ -1,340 +0,0 @@
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.

View File

@ -1,28 +1,134 @@
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
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)
#---------------------------------------------------------------------------------
# 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
# INCLUDES is a list of directories containing extra header files
#---------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
DATA := data
INCLUDES :=
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
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS = -O2 -mrvl -Wall $(MACHDEP) $(INCLUDE)
CXXFLAGS = $(CFLAGS)
LDFLAGS = $(MACHDEP) -Wl,-Map,$(notdir $@).map
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lpng -lmodplay -lasnd -lwiiuse -lbte -logc -lm -lz
#---------------------------------------------------------------------------------
# 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 TOPDIR := $(CURDIR)
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
#---------------------------------------------------------------------------------
# automatically build a list of object files for our project
#---------------------------------------------------------------------------------
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
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)
else
export LD := $(CXX)
endif
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
$(sFILES:.s=.o) $(SFILES:.S=.o)
#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD) \
-I$(LIBOGC_INC)
#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
-L$(LIBOGC_LIB)
export OUTPUT := $(CURDIR)/$(TARGET)
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
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
@echo clean ...
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).bin: $(OUTPUT).elf
$(OUTPUT).elf: $(OFILES)
#---------------------------------------------------------------------------------
%.bin:
$(OBJCOPY) -O binary $^ $@
%.elf:
@echo linking ... $(notdir $@)
$(LD) -T ../rvl.ld $^ $(LDFLAGS) $(LIBPATHS) $(LIBS) -o $@
-include $(DEPENDS)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

View File

@ -1,54 +0,0 @@
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)

View File

@ -1,2 +1,29 @@
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.
+---------------------------------+
| [+] Custom NAND Loader v1.0 |
| developed by Waninkoko |
+---------------------------------+
| wwww.teknoconsolas.es |
+---------------------------------+
[ DESCRIPTION ]:
- This is a custom NAND Loader for Wii channels. It is 100% legal and works
with homebrew and commercial channels.
Also, it allows to configure the loading options for each channel.
[ NOTES ];
- If RESET button is held while booting the channel it will access
the configuration menu.
[ KUDOS ]:
- Team Twiizers and devkitPRO devs.
- crediar.
- WiiGator.
- kwiirk.
- All the betatesters.

View File

@ -0,0 +1 @@
properly building this NAND-Loader does (still) require libogc from 2009

View File

@ -1,131 +0,0 @@
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/

View File

@ -1,62 +0,0 @@
/* 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

View File

@ -1,39 +0,0 @@
/*
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");
}

View File

@ -1,21 +0,0 @@
/*
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

View File

@ -1,163 +0,0 @@
/*
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

BIN
nand-loader/data/background Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

BIN
nand-loader/data/error Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

BIN
nand-loader/data/loading Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@ -1,107 +0,0 @@
#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

@ -1,286 +0,0 @@
/*
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);
}

View File

@ -1,27 +0,0 @@
/*
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

View File

@ -1,167 +0,0 @@
/*
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

@ -1,92 +0,0 @@
/****************************************************************************
* 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.

View File

@ -1,192 +0,0 @@
.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

View File

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

View File

@ -1,35 +0,0 @@
/*
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 = .;
}
}

345
nand-loader/rvl.ld Normal file
View File

@ -0,0 +1,345 @@
/*
* Linkscript for Wii
*/
OUTPUT_FORMAT("elf32-powerpc", "elf32-powerpc", "elf32-powerpc");
OUTPUT_ARCH(powerpc:common);
EXTERN(_stub_start);
ENTRY(_stub_start);
SECTIONS
{
/* DOL header (from TITANIK's GC docs) */
/* default base address */
off = 0;
.header : AT(off)
{
/* 0000-001B Text[0..6] sections File Positions */
LONG(stub_file_start);
LONG(text_file_start);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
/* 001C-0047 Data[0..10] sections File Positions */
LONG(data_file_start);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
/* 0048-0063 Text[0..6] sections Mem Address */
LONG(stub_mem_start);
LONG(text_mem_start);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
/* 0064-008F Data[0..10] sections Mem Address */
LONG(data_mem_start);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
/* 0090-00AB Text[0..6] sections Sizes */
LONG(stub_mem_size);
LONG(text_mem_size);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
/* 00AC-00D7 Data[0..10] sections Sizes */
LONG(data_mem_size);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
/* 00D8 BSS Mem address
00DC BSS Size */
LONG(bss_mem_start);
LONG(bss_mem_size);
/* 00E0 Entry Point */
LONG(ABSOLUTE(_stub_start));
}
. = 0x00003400;
off += 0x100;
stub_mem_start = .;
stub_file_start = off;
.stub : AT(off)
{
KEEP (*(.stub))
. = 0x400;
} = 0
stub_mem_size = . - stub_mem_start;
off += stub_mem_size;
. = 0x81330000;
text_mem_start = .;
text_file_start = off;
.init : AT(off)
{
KEEP (*crt0.o(*.init))
KEEP (*(.init))
}
.text :
{
*(.text)
*(.text.*)
/* .gnu.warning sections are handled specially by elf32.em. */
*(.gnu.warning)
*(.gnu.linkonce.t.*)
. = ALIGN(32); /* REQUIRED. LD is flaky without it. */
}
.fini :
{
KEEP (*(.fini))
. = ALIGN(32); /* REQUIRED. LD is flaky without it. */
}
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
text_mem_size = . - text_mem_start;
off += text_mem_size;
data_mem_start = .;
data_file_start = off;
.data : AT(off)
{
*(.rodata) *(.rodata.*) *(.gnu.linkonce.r.*)
*(.rodata1)
*(.sdata2) *(.sdata2.*) *(.gnu.linkonce.s2.*)
*(.sbss2) *(.sbss2.*) *(.gnu.linkonce.sb2.*)
PROVIDE (__preinit_array_start = .);
*(.preinit_array)
PROVIDE (__preinit_array_end = .);
PROVIDE (__init_array_start = .);
*(.init_array)
PROVIDE (__init_array_end = .);
PROVIDE (__fini_array_start = .);
*(.fini_array)
PROVIDE (__fini_array_end = .);
*(.data)
*(.data.*)
*(.gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
. = ALIGN(32); /* REQUIRED. LD is flaky without it. */
}
.data1 : { *(.data1) }
.tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
.gcc_except_table : { *(.gcc_except_table) }
.fixup : { *(.fixup) }
.got1 : { *(.got1) }
.got2 : { *(.got2) }
.dynamic : { *(.dynamic) }
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
/* We don't want to include the .ctor section from
from the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
. = ALIGN(32); /* REQUIRED. LD is flaky without it. */
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
. = ALIGN(32); /* REQUIRED. LD is flaky without it. */
}
.jcr : { KEEP (*(.jcr)) }
.got : { *(.got.plt) *(.got) }
/* We want the small data sections together, so single-instruction offsets
can access them all, and initialized data all before uninitialized, so
we can shorten the on-disk segment size. */
.sdata :
{
*(.sdata)
*(.sdata.*)
*(.gnu.linkonce.s.*)
. = ALIGN(32); /* REQUIRED. LD is flaky without it. */
}
_edata = .;
PROVIDE (edata = .);
data_mem_size = . - data_mem_start;
off += data_mem_size;
bss_mem_start = .;
bss_file_start = off;
.sbss : AT(off)
{
__sbss_start = .;
PROVIDE (__sbss_start = .);
PROVIDE (___sbss_start = .);
*(.dynsbss)
*(.sbss)
*(.sbss.*)
*(.gnu.linkonce.sb.*)
*(.scommon)
PROVIDE (__sbss_end = .);
PROVIDE (___sbss_end = .);
. = ALIGN(32); /* REQUIRED. LD is flaky without it. */
__sbss_end = .;
}
.bss :
{
__bss_start = .;
PROVIDE (__bss_start = .);
*(.dynbss)
*(.bss)
*(.bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections. */
. = ALIGN(32);
PROVIDE (__bss_end = .);
__bss_end = .;
}
bss_mem_size = . - bss_mem_start;
_end = .;
PROVIDE(end = .);
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* These must appear regardless of . */
}
__isIPL = 0;
__stack_addr = (__bss_start + SIZEOF(.bss) + 0x20000 + 7) & (-8);
__stack_end = (__bss_start + SIZEOF(.bss));
__intrstack_addr = (__stack_addr + 0x4000);
__intrstack_end = (__stack_addr);
__Arena1Lo = (__intrstack_addr + 31) & (-32);
__Arena1Hi = (0x816ffff0);
__Arena2Lo = (0x90002000);
__Arena2Hi = (0x933E0000);
__gxregs = (__Arena1Hi + 31) & (-32);
__ipcbufferLo = (0x933e0000);
__ipcbufferHi = (0x93400000);
/* for backward compatibility with old crt0 */
PROVIDE (__stack = (0x816ffff0));
PROVIDE(__isIPL = __isIPL);
PROVIDE(__text_start = text_mem_start);
PROVIDE(__text_fstart = text_file_start);
PROVIDE(__data_start = data_mem_start);
PROVIDE(__data_fstart = data_file_start);
PROVIDE(__bss_start = bss_mem_start);
PROVIDE(__bss_fstart = bss_file_start);
PROVIDE(__stack_addr = __stack_addr);
PROVIDE(__stack_end = __stack_end);
PROVIDE(__intrstack_addr = __intrstack_addr);
PROVIDE(__intrstack_end = __intrstack_end);
PROVIDE(__Arena1Lo = __Arena1Lo);
PROVIDE(__Arena1Hi = __Arena1Hi);
PROVIDE(__Arena2Lo = __Arena2Lo);
PROVIDE(__Arena2Hi = __Arena2Hi);
PROVIDE(__ipcbufferLo = __ipcbufferLo);
PROVIDE(__ipcbufferHi = __ipcbufferHi);
PROVIDE(__gxregs = __gxregs);

93
nand-loader/source/asm.h Normal file
View File

@ -0,0 +1,93 @@
#ifndef _ASM_H_
#define _ASM_H_
/* Registers */
#define r0 0
#define r1 1
#define r2 2
#define r3 3
#define r4 4
#define r5 5
#define r6 6
#define r7 7
#define r8 8
#define r9 9
#define r10 10
#define r11 11
#define r12 12
#define r13 13
#define r14 14
#define r15 15
#define r16 16
#define r17 17
#define r18 18
#define r19 19
#define r20 20
#define r21 21
#define r22 22
#define r23 23
#define r24 24
#define r25 25
#define r26 26
#define r27 27
#define r28 28
#define r29 29
#define r30 30
#define r31 31
/* BATs */
#define IBAT0U 528
#define IBAT0L 529
#define IBAT1U 530
#define IBAT1L 531
#define IBAT2U 532
#define IBAT2L 533
#define IBAT3U 534
#define IBAT3L 535
#define IBAT4U 560
#define IBAT4L 561
#define IBAT5U 562
#define IBAT5L 563
#define IBAT6U 564
#define IBAT6L 565
#define IBAT7U 566
#define IBAT7L 567
#define DBAT0U 536
#define DBAT0L 537
#define DBAT1U 538
#define DBAT1L 539
#define DBAT2U 540
#define DBAT2L 541
#define DBAT3U 542
#define DBAT3L 543
#define DBAT4U 568
#define DBAT4L 569
#define DBAT5U 570
#define DBAT5L 571
#define DBAT6U 572
#define DBAT6L 573
#define DBAT7U 574
#define DBAT7L 575
/* HIDs */
#define HID0 1008
#define HID1 1009
#define HID2 920
#define HID4 1011
/* MSRs */
#define MSR_RI 0x00000002
#define MSR_DR 0x00000010
#define MSR_IR 0x00000020
#define MSR_IP 0x00000040
#define MSR_SE 0x00000400
#define MSR_ME 0x00001000
#define MSR_FP 0x00002000
#define MSR_POW 0x00004000
#define MSR_EE 0x00008000
#endif

220
nand-loader/source/config.c Normal file
View File

@ -0,0 +1,220 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ogcsys.h>
#include "config.h"
#include "title.h"
#include "video.h"
#include "wpad.h"
/* 'Menu' structure */
struct menu {
/* Entry name */
char *name;
/* Entry value */
bool *value;
};
/* NANDLoader configuration */
struct config loaderCfg ATTRIBUTE_ALIGN(32) = { 0 };
/* Config entries */
struct menu entryList[] = {
{ "Force PAL50", &loaderCfg.forcePal50 },
{ "Force PAL60", &loaderCfg.forcePal60 },
{ "Force NTSC", &loaderCfg.forceNtsc },
{ "Force HDTV", &loaderCfg.forceHdtv },
{ "Patch Video Mode", &loaderCfg.patchVmode },
{ "Show Splash", &loaderCfg.showSplash },
};
/* Macros */
#define NB_ENTRIES (sizeof(entryList) / sizeof(struct menu))
void __Config_Credits(void)
{
/* Clear console */
Con_Clear();
/* Write credits */
printf("[+] Custom NAND Loader for Wii\n\n");
printf(" developed by Waninkoko\n");
printf(" www.teknoconsolas.es\n\n\n");
printf("[+] Thanks to all my betatesters:\n");
printf(" - linkinworm\n");
printf(" - hectorscasa\n");
printf(" - SoraK05\n");
printf(" - And the rest... ;-)\n\n");
printf("[+] Also kudos to:\n\n");
printf(" - Team Twiizers\n");
printf(" - SoftMii Team\n");
printf(" - crediar\n");
printf(" - WiiGator and kwiirk\n");
printf(" - Teknoconsolas.es community\n\n");
printf("\n");
printf("[+] Press any button to continue...\n");
/* Wait for any button */
Wpad_WaitButtons();
}
s32 __Config_GetFilePath(char *outbuf)
{
static char nandpath[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32);
u64 tid;
s32 ret;
/* Get title ID */
ret = ES_GetTitleID(&tid);
if (ret < 0)
return ret;
/* Get data directory */
ret = ES_GetDataDir(tid, nandpath);
if (ret < 0)
return ret;
/* Generate filepath */
sprintf(outbuf, "%s/nand.cfg", nandpath);
return 0;
}
s32 Config_Read(void)
{
char filepath[ISFS_MAXPATH];
s32 fd, ret;
/* Get config filepath */
ret = __Config_GetFilePath(filepath);
if (ret < 0)
return ret;
/* Open config file */
fd = IOS_Open(filepath, ISFS_OPEN_READ);
if (fd < 0)
return fd;
/* Read config */
ret = IOS_Read(fd, &loaderCfg, sizeof(loaderCfg));
/* Close config file */
IOS_Close(fd);
return ret;
}
s32 Config_Write(void)
{
char filepath[ISFS_MAXPATH];
s32 fd, ret;
/* Get config filepath */
ret = __Config_GetFilePath(filepath);
if (ret < 0)
return ret;
/* Create config file */
ISFS_CreateFile(filepath, 0, ISFS_OPEN_RW, ISFS_OPEN_READ, ISFS_OPEN_READ);
/* Open config file */
fd = IOS_Open(filepath, ISFS_OPEN_WRITE);
if (fd < 0)
return fd;
/* Write config */
ret = IOS_Write(fd, &loaderCfg, sizeof(loaderCfg));
/* Close config file */
IOS_Close(fd);
return ret;
}
void Config_Menu(void)
{
u32 var = 0;
s32 selected = 0;
for (;;) {
u32 cnt;
/* Clear console */
Con_Clear();
for (cnt = 0; cnt < NB_ENTRIES; cnt++) {
struct menu *entry = &entryList[cnt];
/* Print entry */
printf("\t%2s %-16s : %s\n", (selected == cnt) ? ">>" : " ", entry->name, (*entry->value) ? "Yes" : "No");
}
printf("\n");
printf("[+] Press UP/DOWN to move cursor.\n");
printf(" Press LEFT/RIGHT to toggle option.\n\n");
printf(" Press A button to save and continue...\n");
u32 buttons = Wpad_WaitButtons();
/* UP/DOWN buttons */
if (buttons & WPAD_BUTTON_UP) {
if ((--selected) <= -1)
selected = (NB_ENTRIES - 1);
}
if (buttons & WPAD_BUTTON_DOWN) {
if ((++selected) >= NB_ENTRIES)
selected = 0;
}
/* LEFT/RIGHT buttons */
if (buttons & (WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT))
*entryList[selected].value ^= 1;
/* A button */
if (buttons & WPAD_BUTTON_A)
break;
/* Easter Egg */
if (buttons & WPAD_BUTTON_1) {
switch (var) {
case 0:
var++;
break;
case 3:
/* Show credits screen */
__Config_Credits();
var = 0;
break;
default:
var = 0;
}
}
if (buttons & WPAD_BUTTON_2) {
switch (var) {
case 1:
case 2:
var++;
break;
default:
var = 0;
}
}
}
/* Write configuration */
Config_Write();
}

View File

@ -0,0 +1,28 @@
#ifndef _CONFIG_H_
#define _CONFIG_H_
/* 'Config' structure */
struct config {
/* Video modes */
bool forcePal50;
bool forcePal60;
bool forceNtsc;
bool forceHdtv;
/* Video mode patching */
bool patchVmode;
/* Splash screen */
bool showSplash;
};
/* NANDLoader configuration */
extern struct config loaderCfg;
/* Prototypes */
s32 Config_Read(void);
s32 Config_Write(void);
void Config_Menu(void);
#endif

87
nand-loader/source/gui.c Normal file
View File

@ -0,0 +1,87 @@
#include <stdio.h>
#include <stdlib.h>
#include <ogcsys.h>
#include "video.h"
/* Constants */
#define CONSOLE_XCOORD 20
#define CONSOLE_YCOORD 100
#define CONSOLE_WIDTH 350
#define CONSOLE_HEIGHT 300
#define MSG_XCOORD 180
#define MSG_YCOORD 190
s32 __Gui_DrawPng(void *img, u32 x, u32 y)
{
IMGCTX ctx = NULL;
PNGUPROP imgProp;
s32 ret;
/* Select PNG data */
ctx = PNGU_SelectImageFromBuffer(img);
if (!ctx) {
ret = -1;
goto out;
}
/* Get image properties */
ret = PNGU_GetImageProperties(ctx, &imgProp);
if (ret != PNGU_OK) {
ret = -1;
goto out;
}
/* Draw image */
Video_DrawPng(ctx, imgProp, x, y);
/* Success */
ret = 0;
out:
/* Free memory */
if (ctx)
PNGU_ReleaseImageContext(ctx);
return ret;
}
void Gui_InitConsole(void)
{
/* Initialize console */
Con_Init(CONSOLE_XCOORD, CONSOLE_YCOORD, CONSOLE_WIDTH, CONSOLE_HEIGHT);
}
void Gui_DrawBackground(void)
{
extern char bgData[];
/* Draw background */
__Gui_DrawPng(bgData, 0, 0);
}
void Gui_DrawLoading(void)
{
extern char loadingImg[];
/* Clear screen */
Video_Clear(COLOR_BLACK);
/* Draw loading image */
__Gui_DrawPng(loadingImg, MSG_XCOORD, MSG_YCOORD);
}
void Gui_DrawError(void)
{
extern char errorImg[];
/* Clear screen */
Video_Clear(COLOR_BLACK);
/* Draw error image */
__Gui_DrawPng(errorImg, MSG_XCOORD, MSG_YCOORD);
}

10
nand-loader/source/gui.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef _GUI_H_
#define _GUI_H_
/* Prototypes */
void Gui_InitConsole(void);
void Gui_DrawBackground(void);
void Gui_DrawLoading(void);
void Gui_DrawError(void);
#endif

265
nand-loader/source/loader.c Normal file
View File

@ -0,0 +1,265 @@
#include <stdio.h>
#include <string.h>
#include <ogcsys.h>
#include <ogc/lwp_watchdog.h>
#include "config.h"
#include "patches.h"
#include "video.h"
#include "wpad.h"
#include "tools.h"
/* DOL header structure */
typedef struct {
u32 textoff[7];
u32 dataoff[11];
u8 *textmem[7];
u8 *datamem[11];
u32 textsize[7];
u32 datasize[11];
u8 *bssmem;
u32 bsssize;
u32 entry;
u32 unused[7];
} dolheader;
/* Entry pointer */
typedef void (*dolentry)(void);
/* Constants */
#define DOL_INDEX 1
void __Loader_SetLowMem(void)
{
/* Setup low memory */
*(vu32*)0x800000F8 = 0x0E7BE2C0;
*(vu32*)0x800000FC = 0x2B73A840;
/* Flush cache */
DCFlushRange((void *)(0x800000F8), 0xFF);
// Set the clock
settime(secs_to_ticks(time(NULL) - 946684800));
// Remove 002 error
*(u16 *)0x80003140 = 0x0038;
*(u16 *)0x80003142 = 0xffff;
*(u16 *)0x80003188 = 0x0038;
*(u16 *)0x8000318A = 0xffff;
DCFlushRange((void*)0x80003140, 4);
DCFlushRange((void*)0x80003188, 4);
}
void __Loader_SetVMode(u64 tid)
{
GXRModeObj *vmode_ptr = NULL;
u32 vmode_reg;
u32 progressive, tvmode;
/* Get video mode configuration */
progressive = (CONF_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable();
tvmode = CONF_GetVideo();
/* Select video mode */
switch(tid & 0xFF) {
/* PAL */
case 'P':
vmode_reg = (CONF_GetEuRGB60() > 0) ? 5 : 1;
if (tvmode != CONF_VIDEO_PAL) {
vmode_reg = 5;
vmode_ptr = &TVNtsc480IntDf;
}
break;
/* NTSC or unknown */
case 'E':
case 'J':
vmode_reg = 0;
if (tvmode != CONF_VIDEO_NTSC)
vmode_ptr = &TVEurgb60Hz480IntDf;
break;
default:
vmode_reg = 0;
}
/* Override video mode */
if (loaderCfg.forcePal50) {
vmode_reg = 1;
vmode_ptr = &TVPal528IntDf;
}
if (loaderCfg.forcePal60) {
vmode_reg = 5;
vmode_ptr = &TVEurgb60Hz480IntDf;
}
if (loaderCfg.forceNtsc) {
vmode_reg = 0;
vmode_ptr = &TVNtsc480IntDf;
}
if (loaderCfg.forceHdtv) {
vmode_reg = 0;
vmode_ptr = &TVNtsc480Prog;
}
/* Set video mode register */
*(vu32 *)0x800000CC = vmode_reg;
/* Set video mode */
if (vmode_ptr) {
/* If progressive available, use it */
if (progressive)
vmode_ptr = &TVNtsc480Prog;
Video_Configure(vmode_ptr);
Video_Clear(COLOR_BLACK);
}
// Anti-green screen fix
VIDEO_SetBlack(TRUE);
VIDEO_Flush();
VIDEO_WaitVSync();
}
void __Loader_PatchDol(u8 *buffer, u32 len)
{
struct config *cfg = &loaderCfg;
/* Video mode patching */
if (cfg->patchVmode)
Patch_VideoMode(buffer, len);
}
s32 __Loader_ReadDol(dolentry *p_entry)
{
static dolheader dol ATTRIBUTE_ALIGN(32);
u32 cnt;
s32 cfd = -1, ret;
/* Open DOL file */
cfd = ES_OpenContent(DOL_INDEX);
if (cfd < 0)
return cfd;
/* Read DOL header */
ret = ES_ReadContent(cfd, (u8 *)&dol, sizeof(dol));
if (ret < 0)
goto out;
/* Clear BSS */
memset(dol.bssmem, 0, dol.bsssize);
/* Read TEXT section */
for (cnt = 0; cnt < 7; cnt++) {
u32 offset = dol.textoff[cnt];
if (offset >= sizeof(dol)) {
u8 *buffer = (u8 *)dol.textmem[cnt];
u32 len = dol.textsize[cnt];
/* Seek */
ES_SeekContent(cfd, offset, 0);
/* Read */
ret = ES_ReadContent(cfd, buffer, len);
if (ret < 0)
goto out;
/* Patch */
__Loader_PatchDol(buffer, len);
}
}
/* Read DATA section */
for (cnt = 0; cnt < 11; cnt++) {
u32 offset = dol.dataoff[cnt];
if (offset >= sizeof(dol)) {
u8 *buffer = (u8 *)dol.datamem[cnt];
u32 len = dol.datasize[cnt];
/* Seek */
ES_SeekContent(cfd, offset, 0);
/* Read */
ret = ES_ReadContent(cfd, buffer, len);
if (ret < 0)
goto out;
/* Patch */
__Loader_PatchDol(buffer, len);
}
}
/* Set entry point */
*p_entry = (dolentry)dol.entry;
out:
/* Close DOL file */
if (cfd >= 0)
ES_CloseContent(cfd);
return ret;
}
void __Loader_Shutdown(void)
{
/* Deinitialize ISFS */
ISFS_Deinitialize();
/* Shutdown IOS subsystems */
SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
}
s32 Loader_Execute(void)
{
dolentry p_entry = NULL;
u64 tid;
s32 ret;
/* Get title ID */
ret = ES_GetTitleID(&tid);
if (ret < 0)
return ret;
/* Load DOL */
ret = __Loader_ReadDol(&p_entry);
if (ret < 0)
return ret;
/* Set low memory */
__Loader_SetLowMem();
/* Set video mode */
__Loader_SetVMode(tid);
/* Shutdown subsystems */
__Loader_Shutdown();
/* Clear screen */
Video_Clear(COLOR_BLACK);
/* Jump to the entry point */
p_entry();
return 0;
}

View File

@ -0,0 +1,8 @@
#ifndef _LOADER_H_
#define _LOADER_H_
/* Prototypes */
s32 Loader_Execute(void);
#endif

View File

@ -0,0 +1,79 @@
#include <stdio.h>
#include <unistd.h>
#include <ogcsys.h>
#include "config.h"
#include "gui.h"
#include "loader.h"
#include "sys.h"
#include "video.h"
#include "wpad.h"
/* Constans */
#define RESTART_SECONDS 4
/* Override IOS_LoadStartupIOS */
s32 __IOS_LoadStartupIOS() { return 0; }
void Menu(void)
{
/* Initialize Wiimote */
Wpad_Init();
/* Draw background */
Gui_DrawBackground();
/* Initialize console */
Gui_InitConsole();
/* Configuration menu */
Config_Menu();
/* Destroy console */
Con_Destroy();
/* Disconnect Wiimote */
Wpad_Disconnect();
}
int main(int argc, char **argv)
{
s32 ret;
/* Initialize subsystems */
Sys_Init();
/* Set video mode */
Video_SetMode();
/* Initialize ISFS */
ISFS_Initialize();
/* Read config */
Config_Read();
/* Config menu */
ret = SYS_ResetButtonDown();
if (ret)
Menu();
/* Draw loading image */
if(loaderCfg.showSplash)
Gui_DrawLoading();
/* Execute application */
Loader_Execute();
/* Draw error image */
Gui_DrawError();
/* Sleep */
sleep(RESTART_SECONDS);
/* Load System Menu */
Sys_LoadMenu();
return 0;
}

View File

@ -0,0 +1,126 @@
#include <stdio.h>
#include <string.h>
#include <ogcsys.h>
#include "config.h"
GXRModeObj *PAL2NTSC[] = {
&TVMpal480IntDf, &TVNtsc480IntDf,
&TVPal264Ds, &TVNtsc240Ds,
&TVPal264DsAa, &TVNtsc240DsAa,
&TVPal264Int, &TVNtsc240Int,
&TVPal264IntAa, &TVNtsc240IntAa,
&TVPal524IntAa, &TVNtsc480IntAa,
&TVPal528Int, &TVNtsc480IntAa,
&TVPal528IntDf, &TVNtsc480IntDf,
&TVPal574IntDfScale, &TVNtsc480IntDf,
&TVEurgb60Hz240Ds, &TVNtsc240Ds,
&TVEurgb60Hz240DsAa, &TVNtsc240DsAa,
&TVEurgb60Hz240Int, &TVNtsc240Int,
&TVEurgb60Hz240IntAa, &TVNtsc240IntAa,
&TVEurgb60Hz480Int, &TVNtsc480IntAa,
&TVEurgb60Hz480IntDf, &TVNtsc480IntDf,
&TVEurgb60Hz480IntAa, &TVNtsc480IntAa,
&TVEurgb60Hz480Prog, &TVNtsc480Prog,
&TVEurgb60Hz480ProgSoft,&TVNtsc480Prog,
&TVEurgb60Hz480ProgAa, &TVNtsc480Prog,
NULL, NULL
};
GXRModeObj *NTSC2PAL[] = {
&TVNtsc240Ds, &TVPal264Ds,
&TVNtsc240DsAa, &TVPal264DsAa,
&TVNtsc240Int, &TVPal264Int,
&TVNtsc240IntAa, &TVPal264IntAa,
&TVNtsc480IntDf, &TVPal528IntDf,
&TVNtsc480IntAa, &TVPal524IntAa,
&TVNtsc480Prog, &TVPal528IntDf,
NULL, NULL
};
GXRModeObj *NTSC2PAL60[]={
&TVNtsc240Ds, &TVEurgb60Hz240Ds,
&TVNtsc240DsAa, &TVEurgb60Hz240DsAa,
&TVNtsc240Int, &TVEurgb60Hz240Int,
&TVNtsc240IntAa, &TVEurgb60Hz240IntAa,
&TVNtsc480IntDf, &TVEurgb60Hz480IntDf,
&TVNtsc480IntAa, &TVEurgb60Hz480IntAa,
&TVNtsc480Prog, &TVEurgb60Hz480Prog,
NULL, NULL
};
void Patch_VideoMode(u8 *buffer, u32 len)
{
GXRModeObj **table = NULL;
u32 cnt, idx;
/* Select conversion table */
if (loaderCfg.forcePal50)
table = NTSC2PAL;
if (loaderCfg.forcePal60)
table = NTSC2PAL60;
if (loaderCfg.forceNtsc)
table = PAL2NTSC;
/* No table selected */
if (!table)
return;
for (cnt = 0; cnt < len; cnt += 4) {
u8 *ptr = buffer + cnt;
/* Search for video modes */
for (idx = 0; table[idx]; idx += 2) {
/* Patch video mode */
if (!memcmp(ptr, table[idx], sizeof(GXRModeObj)))
memcpy(ptr, table[idx+1], sizeof(GXRModeObj));
}
}
}
// void __Patch_VideoMode(u8 *buffer, u32 len)
// {
// const u8 pattern[] = { 0x54, 0x00, 0xFF, 0xFE };
//
// u64 tid;
// u32 cnt;
//
// /* Get title ID */
// ES_GetTitleID(&tid);
//
// for (cnt = 0; cnt < len; cnt += 4) {
// u32 *ptr = (u32 *)(buffer + cnt);
//
// /* Pattern found */
// if (!memcmp(ptr, pattern, sizeof(pattern))) {
// u8 region = tid & 0xFF;
//
// /* USA region */
// if (region == 'E')
// *ptr = 0x38000001;
// /* JAP region */
// if (region == 'J')
// *ptr = 0x38000000;
//
// break;
// }
// }
// }
//
//
// void Patch_VideoMode(u8 *buffer, u32 len)
// {
// const u8 pattern[] = { 0x41, 0x82, 0x00, 0x0C, 0x41, 0x80, 0x00, 0x1C, 0x48, 0x00, 0x00, 0x18 };
//
// u32 cnt;
//
// for (cnt = 0; cnt < len; cnt += 4) {
// u8 *ptr = buffer + cnt;
//
// /* Pattern found */
// if (!memcmp(ptr, pattern, sizeof(pattern)))
// __Patch_VideoMode(ptr, len - cnt);
// }
// }

View File

@ -0,0 +1,7 @@
#ifndef _PATCHES_H_
#define _PATCHES_H_
/* Prototypes */
void Patch_VideoMode(u8 *, u32);
#endif

1561
nand-loader/source/pngu.c Normal file

File diff suppressed because it is too large Load Diff

181
nand-loader/source/pngu.h Normal file
View File

@ -0,0 +1,181 @@
/********************************************************************************************
PNGU Version : 0.2a
Coder : frontier
More info : http://frontier-dev.net
********************************************************************************************/
#ifndef __PNGU__
#define __PNGU__
// Return codes
#define PNGU_OK 0
#define PNGU_ODD_WIDTH 1
#define PNGU_ODD_STRIDE 2
#define PNGU_INVALID_WIDTH_OR_HEIGHT 3
#define PNGU_FILE_IS_NOT_PNG 4
#define PNGU_UNSUPPORTED_COLOR_TYPE 5
#define PNGU_NO_FILE_SELECTED 6
#define PNGU_CANT_OPEN_FILE 7
#define PNGU_CANT_READ_FILE 8
#define PNGU_LIB_ERROR 9
// Color types
#define PNGU_COLOR_TYPE_GRAY 1
#define PNGU_COLOR_TYPE_GRAY_ALPHA 2
#define PNGU_COLOR_TYPE_PALETTE 3
#define PNGU_COLOR_TYPE_RGB 4
#define PNGU_COLOR_TYPE_RGB_ALPHA 5
#define PNGU_COLOR_TYPE_UNKNOWN 6
#ifdef __cplusplus
extern "C" {
#endif
// Types
typedef unsigned char PNGU_u8;
typedef unsigned short PNGU_u16;
typedef unsigned int PNGU_u32;
typedef unsigned long long PNGU_u64;
typedef struct
{
PNGU_u8 r;
PNGU_u8 g;
PNGU_u8 b;
} PNGUCOLOR;
typedef struct
{
PNGU_u32 imgWidth; // In pixels
PNGU_u32 imgHeight; // In pixels
PNGU_u32 imgBitDepth; // In bitx
PNGU_u32 imgColorType; // PNGU_COLOR_TYPE_*
PNGU_u32 validBckgrnd; // Non zero if there is a background color
PNGUCOLOR bckgrnd; // Backgroun color
PNGU_u32 numTrans; // Number of transparent colors
PNGUCOLOR *trans; // Transparent colors
} PNGUPROP;
// Image context, always initialize with SelectImageFrom* and free with ReleaseImageContext
struct _IMGCTX;
typedef struct _IMGCTX *IMGCTX;
/****************************************************************************
* Pixel conversion *
****************************************************************************/
// Macro to convert RGB8 values to RGB565
#define PNGU_RGB8_TO_RGB565(r,g,b) ( ((((PNGU_u16) r) & 0xF8U) << 8) | ((((PNGU_u16) g) & 0xFCU) << 3) | (((PNGU_u16) b) >> 3) )
// Macro to convert RGBA8 values to RGB5A3
#define PNGU_RGB8_TO_RGB5A3(r,g,b,a) (PNGU_u16) (((a & 0xE0U) == 0xE0U) ? \
(0x8000U | ((((PNGU_u16) r) & 0xF8U) << 7) | ((((PNGU_u16) g) & 0xF8U) << 2) | (((PNGU_u16) b) >> 3)) : \
(((((PNGU_u16) a) & 0xE0U) << 7) | ((((PNGU_u16) r) & 0xF0U) << 4) | (((PNGU_u16) g) & 0xF0U) | ((((PNGU_u16) b) & 0xF0U) >> 4)))
// Function to convert two RGB8 values to YCbYCr
PNGU_u32 PNGU_RGB8_TO_YCbYCr (PNGU_u8 r1, PNGU_u8 g1, PNGU_u8 b1, PNGU_u8 r2, PNGU_u8 g2, PNGU_u8 b2);
// Function to convert an YCbYCr to two RGB8 values.
void PNGU_YCbYCr_TO_RGB8 (PNGU_u32 ycbycr, PNGU_u8 *r1, PNGU_u8 *g1, PNGU_u8 *b1, PNGU_u8 *r2, PNGU_u8 *g2, PNGU_u8 *b2);
/****************************************************************************
* Image context handling *
****************************************************************************/
// Selects a PNG file, previosly loaded into a buffer, and creates an image context for subsequent procesing.
IMGCTX PNGU_SelectImageFromBuffer (const void *buffer);
IMGCTX PNGU_SelectImageFromBufferX (const void *buffer, int size);
// Selects a PNG file, from any devoptab device, and creates an image context for subsequent procesing.
IMGCTX PNGU_SelectImageFromDevice (const char *filename);
// Frees resources associated with an image context. Always call this function when you no longer need the IMGCTX.
void PNGU_ReleaseImageContext (IMGCTX ctx);
/****************************************************************************
* Miscelaneous *
****************************************************************************/
// Retrieves info from selected PNG file, including image dimensions, color format, background and transparency colors.
int PNGU_GetImageProperties (IMGCTX ctx, PNGUPROP *fileproperties);
/****************************************************************************
* Image conversion *
****************************************************************************/
// Expands selected image into an YCbYCr buffer. You need to specify context, image dimensions,
// destination address and stride in pixels (stride = buffer width - image width).
int PNGU_DecodeToYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
// Macro for decoding an image inside a buffer at given coordinates.
#define PNGU_DECODE_TO_COORDS_YCbYCr(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \
\
PNGU_DecodeToYCbYCr (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
(coordX) * 2, (bufferWidth) - (imgWidth))
// Expands selected image into a linear RGB565 buffer. You need to specify context, image dimensions,
// destination address and stride in pixels (stride = buffer width - image width).
int PNGU_DecodeToRGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
// Macro for decoding an image inside a buffer at given coordinates.
#define PNGU_DECODE_TO_COORDS_RGB565(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \
\
PNGU_DecodeToRGB565 (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
(coordX) * 2, (bufferWidth) - (imgWidth))
// Expands selected image into a linear RGBA8 buffer. You need to specify context, image dimensions,
// destination address, stride in pixels and default alpha value, which is used if the source image
// doesn't have an alpha channel.
int PNGU_DecodeToRGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride, PNGU_u8 default_alpha);
// Macro for decoding an image inside a buffer at given coordinates.
#define PNGU_DECODE_TO_COORDS_RGBA8(ctx,coordX,coordY,imgWidth,imgHeight,default_alpha,bufferWidth,bufferHeight,buffer) \
\
PNGU_DecodeToRGBA8 (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 4 + \
(coordX) * 4, (bufferWidth) - (imgWidth), default_alpha)
// Expands selected image into a 4x4 tiled RGB565 buffer. You need to specify context, image dimensions
// and destination address.
int PNGU_DecodeTo4x4RGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer);
// Compressed version (DXT1/CMPR)
int PNGU_DecodeToCMPR_Trim(IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer);
int PNGU_DecodeToCMPR_Pad(IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer);
int PNGU_4x4RGBA8_To_CMPR(void *buf_rgb, PNGU_u32 width, PNGU_u32 height, void *buf_cmpr);
int PNGU_RGBA8_To_CMPR(void *buf_rgb, PNGU_u32 width, PNGU_u32 height, void *buf_cmpr);
// Expands selected image into a 4x4 tiled RGB5A3 buffer. You need to specify context, image dimensions,
// destination address and default alpha value, which is used if the source image doesn't have an alpha channel.
int PNGU_DecodeTo4x4RGB5A3 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha);
// Expands selected image into a 4x4 tiled RGBA8 buffer. You need to specify context, image dimensions,
// destination address and default alpha value, which is used if the source image doesn't have an alpha channel.
int PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha);
// Encodes an YCbYCr image in PNG format and stores it in the selected device or memory buffer. You need to
// specify context, image dimensions, destination address and stride in pixels (stride = buffer width - image width).
int PNGU_EncodeFromYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
// Macro for encoding an image stored into an YCbYCr buffer at given coordinates.
#define PNGU_ENCODE_TO_COORDS_YCbYCr(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \
\
PNGU_EncodeFromYCbYCr (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
(coordX) * 2, (bufferWidth) - (imgWidth))
PNGU_u8 * PNGU_DecodeTo4x4RGBA8_EX (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, int * dstWidth, int * dstHeight, PNGU_u8 *dstPtr);
int PNGU_EncodeFromEFB (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stride);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,42 @@
#ifndef __PNGU_I__
#define __PNGU_I__
#include "png.h"
// Constants
#define PNGU_SOURCE_BUFFER 1
#define PNGU_SOURCE_DEVICE 2
// Prototypes of helper functions
int pngu_info (IMGCTX ctx);
int pngu_decode (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stripAlpha);
int pngu_decode_add_alpha (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stripAlpha, int force32bit);
void pngu_free_info (IMGCTX ctx);
void pngu_read_data_from_buffer (png_structp png_ptr, png_bytep data, png_size_t length);
void pngu_write_data_to_buffer (png_structp png_ptr, png_bytep data, png_size_t length);
void pngu_flush_data_to_buffer (png_structp png_ptr);
int pngu_clamp (int value, int min, int max);
// PNGU Image context struct
struct _IMGCTX
{
int source;
void *buffer;
char *filename;
PNGU_u32 cursor;
PNGU_u32 buf_size; // buffer size
PNGU_u32 propRead;
PNGUPROP prop;
PNGU_u32 infoRead;
png_structp png_ptr;
png_infop info_ptr;
FILE *fd;
png_bytep *row_pointers;
png_bytep img_data;
};
#endif

118
nand-loader/source/stub.S Normal file
View File

@ -0,0 +1,118 @@
.rodata
.globl bgData
bgData:
.incbin "../data/background"
.globl loadingImg
loadingImg:
.incbin "../data/loading"
.globl errorImg
errorImg:
.incbin "../data/error"
#include "asm.h"
.text
.section .stub
.extern _start
.globl _stub_start
_stub_start:
lis r3, 0x0011
ori r3, r3, 0x0C64
mtspr HID0, r3
isync
li r4, 0x2000
mtmsr r4
ori r3, r3, 0xC000
mtspr HID0, r3
isync
li r0, 0
mtspr IBAT0U, r0
mtspr IBAT1U, r0
mtspr IBAT2U, r0
mtspr IBAT3U, r0
mtspr IBAT4U, r0
mtspr IBAT5U, r0
mtspr DBAT0U, r0
mtspr DBAT1U, r0
mtspr DBAT2U, r0
mtspr DBAT3U, r0
mtspr DBAT4U, r0
mtspr DBAT5U, 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
lis r4, 0x8000
ori r4, r4, 0x1FFF
mtspr DBAT0L, r3
mtspr DBAT0U, r4
isync
mtspr IBAT0L, r3
mtspr IBAT0U, r4
isync
addis r3, r3, 0x1000
addis r4, r4, 0x1000
mtspr DBAT4L, r3
mtspr DBAT4U, r4
isync
mtspr IBAT4L, r3
mtspr IBAT4U, r4
isync
li r3, 0x2A
lis r4, 0xC000
ori r4, r4, 0x1FFF
mtspr DBAT1L, r3
mtspr DBAT1U, r4
isync
mtspr IBAT1L, r3
mtspr IBAT1U, r4
isync
addis r3, r3, 0x1000
addis r4, r4, 0x1000
mtspr DBAT2L, r3
mtspr DBAT2U, r4
isync
mtspr IBAT2L, r3
mtspr IBAT2U, r4
isync
li r3, 0
mfmsr r3
ori r3, r3, MSR_DR|MSR_IR
mtsrr1 r3
lis r3, _start@h
ori r3, r3, _start@l
mtsrr0 r3
rfi

48
nand-loader/source/sys.c Normal file
View File

@ -0,0 +1,48 @@
#include <stdio.h>
#include <stdlib.h>
#include <ogcsys.h>
/* Constants */
#define CERTS_LEN 0x280
/* Variables */
static const char certs_fs[] ATTRIBUTE_ALIGN(32) = "/sys/cert.sys";
void Sys_Init(void)
{
/* Initialize video subsytem */
VIDEO_Init();
}
void Sys_LoadMenu(void)
{
/* Return to the Wii system menu */
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
}
s32 Sys_GetCerts(signed_blob **certs, u32 *len)
{
static signed_blob certificates[CERTS_LEN] ATTRIBUTE_ALIGN(32);
s32 fd, ret;
/* Open certificates file */
fd = IOS_Open(certs_fs, 1);
if (fd < 0)
return fd;
/* Read certificates */
ret = IOS_Read(fd, certificates, sizeof(certificates));
/* Close file */
IOS_Close(fd);
/* Set values */
if (ret > 0) {
*certs = certificates;
*len = sizeof(certificates);
}
return ret;
}

9
nand-loader/source/sys.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef _SYS_H_
#define _SYS_H_
/* Prototypes */
void Sys_Init(void);
void Sys_LoadMenu(void);
s32 Sys_GetCerts(signed_blob **, u32 *);
#endif

256
nand-loader/source/title.c Normal file
View File

@ -0,0 +1,256 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <ogcsys.h>
#include "utils.h"
s32 Title_GetList(u64 **outbuf, u32 *outlen)
{
u64 *titles = NULL;
u32 len, nb_titles;
s32 ret;
/* Get number of titles */
ret = ES_GetNumTitles(&nb_titles);
if (ret < 0)
return ret;
/* Calculate buffer lenght */
len = round_up(sizeof(u64) * nb_titles, 32);
/* Allocate memory */
titles = memalign(32, len);
if (!titles)
return -1;
/* Get titles */
ret = ES_GetTitles(titles, nb_titles);
if (ret < 0)
goto err;
/* Set values */
*outbuf = titles;
*outlen = nb_titles;
return 0;
err:
/* Free memory */
if (titles)
free(titles);
return ret;
}
s32 Title_GetTicketViews(u64 tid, tikview **outbuf, u32 *outlen)
{
tikview *views = NULL;
u32 nb_views;
s32 ret;
/* Get number of ticket views */
ret = ES_GetNumTicketViews(tid, &nb_views);
if (ret < 0)
return ret;
/* Allocate memory */
views = (tikview *)memalign(32, sizeof(tikview) * nb_views);
if (!views)
return -1;
/* Get ticket views */
ret = ES_GetTicketViews(tid, views, nb_views);
if (ret < 0)
goto err;
/* Set values */
*outbuf = views;
*outlen = nb_views;
return 0;
err:
/* Free memory */
if (views)
free(views);
return ret;
}
s32 Title_GetTMD(u64 tid, signed_blob **outbuf, u32 *outlen)
{
void *p_tmd = NULL;
u32 len;
s32 ret;
/* Get TMD size */
ret = ES_GetStoredTMDSize(tid, &len);
if (ret < 0)
return ret;
/* Allocate memory */
p_tmd = memalign(32, round_up(len, 32));
if (!p_tmd)
return -1;
/* Read TMD */
ret = ES_GetStoredTMD(tid, p_tmd, len);
if (ret < 0)
goto err;
/* Set values */
*outbuf = p_tmd;
*outlen = len;
return 0;
err:
/* Free memory */
if (p_tmd)
free(p_tmd);
return ret;
}
s32 Title_GetVersion(u64 tid, u16 *outbuf)
{
signed_blob *p_tmd = NULL;
tmd *tmd_data = NULL;
u32 len;
s32 ret;
/* Get title TMD */
ret = Title_GetTMD(tid, &p_tmd, &len);
if (ret < 0)
return ret;
/* Retrieve TMD info */
tmd_data = (tmd *)SIGNATURE_PAYLOAD(p_tmd);
/* Set values */
*outbuf = tmd_data->title_version;
/* Free memory */
free(p_tmd);
return 0;
}
s32 Title_GetSysVersion(u64 tid, u64 *outbuf)
{
signed_blob *p_tmd = NULL;
tmd *tmd_data = NULL;
u32 len;
s32 ret;
/* Get title TMD */
ret = Title_GetTMD(tid, &p_tmd, &len);
if (ret < 0)
return ret;
/* Retrieve TMD info */
tmd_data = (tmd *)SIGNATURE_PAYLOAD(p_tmd);
/* Set values */
*outbuf = tmd_data->sys_version;
/* Free memory */
free(p_tmd);
return 0;
}
s32 Title_GetSize(u64 tid, u32 *outbuf)
{
signed_blob *p_tmd = NULL;
tmd *tmd_data = NULL;
u32 cnt, len, size = 0;
s32 ret;
/* Get title TMD */
ret = Title_GetTMD(tid, &p_tmd, &len);
if (ret < 0)
return ret;
/* Retrieve TMD info */
tmd_data = (tmd *)SIGNATURE_PAYLOAD(p_tmd);
/* Calculate title size */
for (cnt = 0; cnt < tmd_data->num_contents; cnt++) {
tmd_content *content = &tmd_data->contents[cnt];
/* Add content size */
size += content->size;
}
/* Set values */
*outbuf = size;
/* Free memory */
free(p_tmd);
return 0;
}
s32 Title_GetIOSVersions(u8 **outbuf, u32 *outlen)
{
u8 *buffer = NULL;
u64 *list = NULL;
u32 count, cnt, idx;
s32 ret;
/* Get title list */
ret = Title_GetList(&list, &count);
if (ret < 0)
return ret;
/* Count IOS */
for (cnt = idx = 0; idx < count; idx++) {
u32 tidh = (list[idx] >> 32);
u32 tidl = (list[idx] & 0xFFFFFFFF);
/* Title is IOS */
if ((tidh == 0x1) && (tidl >= 3) && (tidl <= 255))
cnt++;
}
/* Allocate memory */
buffer = (u8 *)memalign(32, cnt);
if (!buffer) {
ret = -1;
goto out;
}
/* Copy IOS */
for (cnt = idx = 0; idx < count; idx++) {
u32 tidh = (list[idx] >> 32);
u32 tidl = (list[idx] & 0xFFFFFFFF);
/* Title is IOS */
if ((tidh == 0x1) && (tidl >= 3) && (tidl <= 255))
buffer[cnt++] = (u8)(tidl & 0xFF);
}
/* Set values */
*outbuf = buffer;
*outlen = cnt;
goto out;
out:
/* Free memory */
if (list)
free(list);
return ret;
}

View File

@ -0,0 +1,16 @@
#ifndef _TITLE_H_
#define _TITLE_H_
/* Constants */
#define BLOCK_SIZE 1024
/* Prototypes */
s32 Title_GetList(u64 **, u32 *);
s32 Title_GetTicketViews(u64, tikview **, u32 *);
s32 Title_GetTMD(u64, signed_blob **, u32 *);
s32 Title_GetVersion(u64, u16 *);
s32 Title_GetSysVersion(u64, u64 *);
s32 Title_GetSize(u64, u32 *);
s32 Title_GetIOSVersions(u8 **, u32 *);
#endif

252
nand-loader/source/tools.c Normal file
View File

@ -0,0 +1,252 @@
/*******************************************************************************
* tools.c
*
* Copyright (c) 2009 The Lemon Man
* Copyright (c) 2009 Nicksasa
* Copyright (c) 2009 WiiPower
*
* Distributed under the terms of the GNU General Public License (v2)
* See http://www.gnu.org/licenses/gpl-2.0.txt for more info.
*
* Description:
* -----------
*
******************************************************************************/
#include <gccore.h>
#include <malloc.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <wiiuse/wpad.h>
#include "tools.h"
void printheadline()
{
int rows, cols;
CON_GetMetrics(&cols, &rows);
printf("TriiForce beta 7");
char buf[64];
sprintf(buf, "IOS%u (Rev %u)\n", IOS_GetVersion(), IOS_GetRevision());
printf("\x1B[%d;%dH", 0, cols-strlen(buf)-1);
printf(buf);
}
void set_highlight(bool highlight)
{
if (highlight)
{
printf("\x1b[%u;%um", 47, false);
printf("\x1b[%u;%um", 30, false);
} else
{
printf("\x1b[%u;%um", 37, false);
printf("\x1b[%u;%um", 40, false);
}
}
void *allocate_memory(u32 size)
{
return memalign(32, (size+31)&(~31) );
}
void Verify_Flags()
{
if (Power_Flag)
{
WPAD_Shutdown();
STM_ShutdownToStandby();
}
if (Reset_Flag)
{
WPAD_Shutdown();
STM_RebootSystem();
}
}
void waitforbuttonpress(u32 *out, u32 *outGC)
{
u32 pressed = 0;
u32 pressedGC = 0;
while (true)
{
Verify_Flags();
WPAD_ScanPads();
pressed = WPAD_ButtonsDown(0);
PAD_ScanPads();
pressedGC = PAD_ButtonsDown(0);
if(pressed || pressedGC)
{
if (pressedGC)
{
// Without waiting you can't select anything
usleep (20000);
}
if (out) *out = pressed;
if (outGC) *outGC = pressedGC;
return;
}
}
}
s32 read_file(char *filepath, u8 **buffer, u32 *filesize)
{
s32 Fd;
int ret;
if (buffer == NULL)
{
printf("NULL Pointer\n");
return -1;
}
Fd = ISFS_Open(filepath, ISFS_OPEN_READ);
if (Fd < 0)
{
printf("ISFS_Open %s failed %d\n", filepath, Fd);
return Fd;
}
fstats *status;
status = allocate_memory(sizeof(fstats));
if (status == NULL)
{
printf("Out of memory for status\n");
return -1;
}
ret = ISFS_GetFileStats(Fd, status);
if (ret < 0)
{
printf("ISFS_GetFileStats failed %d\n", ret);
ISFS_Close(Fd);
free(status);
return -1;
}
*buffer = allocate_memory(status->file_length);
if (*buffer == NULL)
{
printf("Out of memory for buffer\n");
ISFS_Close(Fd);
free(status);
return -1;
}
ret = ISFS_Read(Fd, *buffer, status->file_length);
if (ret < 0)
{
printf("ISFS_Read failed %d\n", ret);
ISFS_Close(Fd);
free(status);
free(*buffer);
return ret;
}
ISFS_Close(Fd);
*filesize = status->file_length;
free(status);
return 0;
}
s32 identify(u64 titleid, u32 *ios)
{
char filepath[ISFS_MAXPATH] ATTRIBUTE_ALIGN(0x20);
u8 *tmdBuffer = NULL;
u32 tmdSize;
u8 *tikBuffer = NULL;
u32 tikSize;
u8 *certBuffer = NULL;
u32 certSize;
int ret;
printf("Reading TMD...");
fflush(stdout);
sprintf(filepath, "/title/%08x/%08x/content/title.tmd", TITLE_UPPER(titleid), TITLE_LOWER(titleid));
ret = read_file(filepath, &tmdBuffer, &tmdSize);
if (ret < 0)
{
printf("Reading TMD failed\n");
return ret;
}
printf("done\n");
*ios = (u32)(tmdBuffer[0x18b]);
printf("Reading ticket...");
fflush(stdout);
sprintf(filepath, "/ticket/%08x/%08x.tik", TITLE_UPPER(titleid), TITLE_LOWER(titleid));
ret = read_file(filepath, &tikBuffer, &tikSize);
if (ret < 0)
{
printf("Reading ticket failed\n");
free(tmdBuffer);
return ret;
}
printf("done\n");
printf("Reading certs...");
fflush(stdout);
sprintf(filepath, "/sys/cert.sys");
ret = read_file(filepath, &certBuffer, &certSize);
if (ret < 0)
{
printf("Reading certs failed\n");
free(tmdBuffer);
free(tikBuffer);
return ret;
}
printf("done\n");
printf("ES_Identify...");
fflush(stdout);
ret = ES_Identify((signed_blob*)certBuffer, certSize, (signed_blob*)tmdBuffer, tmdSize, (signed_blob*)tikBuffer, tikSize, NULL);
if (ret < 0)
{
switch(ret)
{
case ES_EINVAL:
printf("Error! ES_Identify (ret = %d;) Data invalid!\n", ret);
break;
case ES_EALIGN:
printf("Error! ES_Identify (ret = %d;) Data not aligned!\n", ret);
break;
case ES_ENOTINIT:
printf("Error! ES_Identify (ret = %d;) ES not initialized!\n", ret);
break;
case ES_ENOMEM:
printf("Error! ES_Identify (ret = %d;) No memory!\n", ret);
break;
default:
printf("Error! ES_Identify (ret = %d)\n", ret);
break;
}
free(tmdBuffer);
free(tikBuffer);
free(certBuffer);
return ret;
}
printf("done\n");
free(tmdBuffer);
free(tikBuffer);
free(certBuffer);
return 0;
}

View File

@ -0,0 +1,31 @@
/*******************************************************************************
* tools.h
*
* Copyright (c) 2009 The Lemon Man
* Copyright (c) 2009 Nicksasa
* Copyright (c) 2009 WiiPower
*
* Distributed under the terms of the GNU General Public License (v2)
* See http://www.gnu.org/licenses/gpl-2.0.txt for more info.
*
* Description:
* -----------
*
******************************************************************************/
#define TITLE_UPPER(x) ((u32)((x) >> 32))
#define TITLE_LOWER(x) ((u32)(x))
#define TITLE_ID(x,y) (((u64)(x) << 32) | (y))
bool Power_Flag;
bool Reset_Flag;
void *allocate_memory(u32 size);
s32 read_file(char *filepath, u8 **buffer, u32 *filesize);
s32 identify(u64 titleid, u32 *ios);
void set_highlight(bool highlight);
void waitforbuttonpress(u32 *out, u32 *outGC);
void printheadline();

View File

@ -0,0 +1,15 @@
#ifndef _UTILS_H_
#define _UTILS_H_
/* Constants */
#define KB_SIZE 1024.0
#define MB_SIZE 1048576.0
#define GB_SIZE 1073741824.0
/* Macros */
#define round_up(x,n) (-(-(x) & -(n)))
/* Prototypes */
u32 swap32(u32);
#endif

147
nand-loader/source/video.c Normal file
View File

@ -0,0 +1,147 @@
#include <stdio.h>
#include <ogcsys.h>
#include "sys.h"
#include "video.h"
/* Video variables */
static void *framebuffer = NULL;
static GXRModeObj *vmode = NULL;
void Con_Init(u32 x, u32 y, u32 w, u32 h)
{
/* Create console in the framebuffer */
CON_InitEx(vmode, x, y, w, h);
}
void Con_Destroy(void)
{
/* Destroy console */
VIDEO_SetPostRetraceCallback(NULL);
}
void Con_Clear(void)
{
/* Clear console */
printf("\x1b[2J");
fflush(stdout);
}
void Con_ClearLine(void)
{
s32 cols, rows;
u32 cnt;
printf("\r");
fflush(stdout);
/* Get console metrics */
CON_GetMetrics(&cols, &rows);
/* Erase line */
for (cnt = 1; cnt < cols; cnt++) {
printf(" ");
fflush(stdout);
}
printf("\r");
fflush(stdout);
}
void Con_FgColor(u32 color, u8 bold)
{
/* Set foreground color */
printf("\x1b[%u;%um", color + 30, bold);
fflush(stdout);
}
void Con_BgColor(u32 color, u8 bold)
{
/* Set background color */
printf("\x1b[%u;%um", color + 40, bold);
fflush(stdout);
}
void Con_FillRow(u32 row, u32 color, u8 bold)
{
s32 cols, rows;
u32 cnt;
/* Set color */
printf("\x1b[%u;%um", color + 40, bold);
fflush(stdout);
/* Get console metrics */
CON_GetMetrics(&cols, &rows);
/* Save current row and col */
printf("\x1b[s");
fflush(stdout);
/* Move to specified row */
printf("\x1b[%u;0H", row);
fflush(stdout);
/* Fill row */
for (cnt = 0; cnt < cols; cnt++) {
printf(" ");
fflush(stdout);
}
/* Load saved row and col */
printf("\x1b[u");
fflush(stdout);
/* Set default color */
Con_BgColor(0, 0);
Con_FgColor(7, 1);
}
void Video_Configure(GXRModeObj *rmode)
{
/* Configure the video subsystem */
VIDEO_Configure(rmode);
/* Setup video */
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
VIDEO_WaitVSync();
if (rmode->viTVMode & VI_NON_INTERLACE)
VIDEO_WaitVSync();
}
void Video_SetMode(void)
{
/* Select preferred video mode */
vmode = VIDEO_GetPreferredMode(NULL);
/* Allocate memory for the framebuffer */
framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode));
/* Configure the video subsystem */
VIDEO_Configure(vmode);
/* Setup video */
VIDEO_SetNextFramebuffer(framebuffer);
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
VIDEO_WaitVSync();
if (vmode->viTVMode & VI_NON_INTERLACE)
VIDEO_WaitVSync();
/* Clear the screen */
Video_Clear(COLOR_BLACK);
}
void Video_Clear(s32 color)
{
VIDEO_ClearFrameBuffer(vmode, framebuffer, color);
}
void Video_DrawPng(IMGCTX ctx, PNGUPROP imgProp, u16 x, u16 y)
{
PNGU_DECODE_TO_COORDS_YCbYCr(ctx, x, y, imgProp.imgWidth, imgProp.imgHeight, vmode->fbWidth, vmode->xfbHeight, framebuffer);
}

View File

@ -0,0 +1,20 @@
#ifndef _VIDEO_H_
#define _VIDEO_H_
#include "pngu.h"
/* Prototypes */
void Con_Init(u32, u32, u32, u32);
void Con_Destroy(void);
void Con_Clear(void);
void Con_ClearLine(void);
void Con_FgColor(u32, u8);
void Con_BgColor(u32, u8);
void Con_FillRow(u32, u32, u8);
void Video_Configure(GXRModeObj *);
void Video_SetMode(void);
void Video_Clear(s32);
void Video_DrawPng(IMGCTX, PNGUPROP, u16, u16);
#endif

60
nand-loader/source/wpad.c Normal file
View File

@ -0,0 +1,60 @@
#include <stdio.h>
#include <ogcsys.h>
#include "sys.h"
#include "wpad.h"
/* Constants */
#define MAX_WIIMOTES 4
s32 Wpad_Init(void)
{
s32 ret;
/* Initialize Wiimote subsystem */
ret = WPAD_Init();
if (ret < 0)
return ret;
return ret;
}
void Wpad_Disconnect(void)
{
u32 cnt;
/* Disconnect Wiimotes */
for (cnt = 0; cnt < MAX_WIIMOTES; cnt++)
WPAD_Disconnect(cnt);
/* Shutdown Wiimote subsystem */
WPAD_Shutdown();
}
u32 Wpad_GetButtons(void)
{
u32 buttons = 0, cnt;
/* Scan pads */
WPAD_ScanPads();
/* Get pressed buttons */
for (cnt = 0; cnt < MAX_WIIMOTES; cnt++)
buttons |= WPAD_ButtonsDown(cnt);
return buttons;
}
u32 Wpad_WaitButtons(void)
{
u32 buttons = 0;
/* Wait for button pressing */
while (!buttons) {
buttons = Wpad_GetButtons();
VIDEO_WaitVSync();
}
return buttons;
}

12
nand-loader/source/wpad.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef _WPAD_H_
#define _WPAD_H_
#include <wiiuse/wpad.h>
/* Prototypes */
s32 Wpad_Init(void);
void Wpad_Disconnect(void);
u32 Wpad_GetButtons(void);
u32 Wpad_WaitButtons(void);
#endif

View File

@ -1,42 +0,0 @@
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)

View File

@ -1,123 +0,0 @@
/*
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

View File

@ -1,107 +0,0 @@
#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

@ -1,19 +0,0 @@
/*
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
}

View File

@ -1,32 +0,0 @@
/*
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

View File

@ -1,33 +0,0 @@
/*
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)) ;
}

View File

@ -1,17 +0,0 @@
/*
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