nand-loader: add error 002 fix, green-screen fix and date-bug fix (courtesy of wilsoff)

This commit is contained in:
Christopher Roy Bratusek 2012-12-08 21:29:06 +01:00
parent 8efa9318ad
commit 94553f8869
8 changed files with 302 additions and 6353 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,171 +0,0 @@
/********************************************************************************************
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);
// 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) * 2 + \
(coordX) * 2, (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);
// 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))
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,11 +1,13 @@
#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 {
@ -41,6 +43,18 @@ void __Loader_SetLowMem(void)
/* Flush cache */
DCFlushRange((void *)(0x80000000), 0x3F00);
// Set the clock
settime(secs_to_ticks(time(NULL) - 946684800));
// Remove 002 error (set to IOS 53)
*(u16 *)0x80003140 = 0x0035;
*(u16 *)0x80003142 = 0xffff;
*(u16 *)0x80003188 = 0x0035;
*(u16 *)0x8000318A = 0xffff;
DCFlushRange((void*)0x80003140, 4);
DCFlushRange((void*)0x80003188, 4);
}
void __Loader_SetVMode(u64 tid)
@ -115,6 +129,11 @@ void __Loader_SetVMode(u64 tid)
Video_Configure(vmode_ptr);
Video_Clear(COLOR_BLACK);
}
// Anti-green screen fix
VIDEO_SetBlack(TRUE);
VIDEO_Flush();
VIDEO_WaitVSync();
}

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();