Exemplo n.º 1
0
void FirmLoader(){
	char firm_path[256];

	if (!FileExplorerMain(firm_path, sizeof(firm_path)))
	{
		UINT fsz;
		if (loadFirm(firm_path, &fsz))
		{
			ConsoleInit();
			ConsoleSetTitle(strings[STR_LOAD], strings[STR_FIRMWARE_FILE]);
			print(strings[STR_WRONG], "", strings[STR_FIRMWARE_FILE]);
			print(strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_A], strings[STR_CONTINUE]);
			ConsoleShow();
			WaitForButton(BUTTON_A);
			return;
		}

		if (loadExecReboot())
		{
			ConsoleInit();
			ConsoleSetTitle(strings[STR_LOAD], strings[STR_FIRMWARE_FILE]);
			print(strings[STR_ERROR_LAUNCHING], strings[STR_FIRMWARE_FILE]);
			print(strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_A], strings[STR_CONTINUE]);
			ConsoleShow();
			WaitForButton(BUTTON_A);
			return;
		}
	}
}
Exemplo n.º 2
0
void firmware() {
    display_init();
    gfx_init_ctxt(&gfx_ctxt, display_init_framebuffer(), 720, 1280, 768);
    gfx_clear_color(&gfx_ctxt, 0xFF000000);
    gfx_con_init(&gfx_con, &gfx_ctxt);
    gfx_con_setcol(&gfx_con, DEFAULT_TEXT_COL, 0, 0);

    while (!sdMount()) {
        error("Failed to init SD card!\n");
        print("Press POWER to power off, any other key to retry\n");
        if (btn_wait() & BTN_POWER)
            i2c_send_byte(I2C_5, 0x3C, MAX77620_REG_ONOFFCNFG1, MAX77620_ONOFFCNFG1_PWR_OFF);
        btn_wait();
    }
    
    if(PMC(APBDEV_PMC_SCRATCH49) != 69 && fopen("/ReiNX.bin", "rb")) {
        fread((void*)PAYLOAD_ADDR, fsize(), 1);
        fclose();
        sdUnmount();
        display_end();
        CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_V) |= 0x400; // Enable AHUB clock.
        CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_Y) |= 0x40;  // Enable APE clock.
        PMC(APBDEV_PMC_SCRATCH49) = 69;
        ((void (*)())PAYLOAD_ADDR)();
    }
    SYSREG(AHB_AHB_SPARE_REG) = (volatile vu32)0xFFFFFF9F;
	PMC(APBDEV_PMC_SCRATCH49) = 0;
    
    print("Welcome to ReiNX %s!\n", VERSION);
    loadFirm();
    drawSplash();
    launch();
}
Exemplo n.º 3
0
void main(void){
    mountSD();
    setupCFW();
    loadFirm();
    patchFirm();
    launchFirm();
}
Exemplo n.º 4
0
int main(){
    mountSD();
    loadSplash();
    loadFirm();
    patchFirm();
    launchFirm();
    return 0;
}
Exemplo n.º 5
0
u32 main(){
    mountSD();
    loadSplash();
    setupCFW();
    if(!loadFirm()) return 0;
    if(!patchFirm()) return 0;
    launchFirm();
    return 1;
}
Exemplo n.º 6
0
Arquivo: main.c Projeto: meowy/ReiNand
int main(){
    mountSD();
    #if !defined BOOT_EMU && !defined BOOT_SYS
    loadSplash();
    while(1){
        if(((~*(unsigned *)0x10146000) & 0xFFF) == (1 << 3)) break;
        else if(((~*(unsigned *)0x10146000) & 0xFFF) == ((1 << 3) | (1 << 1))) {mode = 0; break;}
    } //Start = emu; Start+B = sys
    #endif
    loadFirm(mode);
    patchFirm();
    launchFirm();
    return 0;
}
Exemplo n.º 7
0
void FirmLoader(TCHAR firm_path[]){

	UINT fsz;
	if (loadFirm(firm_path, &fsz))
	{
		ConsoleInit();
		ConsoleSetTitle(strings[STR_LOAD], strings[STR_FIRMWARE_FILE]);
		print(strings[STR_WRONG], L"", strings[STR_FIRMWARE_FILE]);
		print(strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_A], strings[STR_CONTINUE]);
		ConsoleShow();
		WaitForButton(BUTTON_A);
		return;
	}
		if (loadExecReboot())
	{
		ConsoleInit();
		ConsoleSetTitle(strings[STR_LOAD], strings[STR_FIRMWARE_FILE]);
		print(strings[STR_ERROR_LAUNCHING], strings[STR_FIRMWARE_FILE]);
		print(strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_A], strings[STR_CONTINUE]);
		ConsoleShow();
		WaitForButton(BUTTON_A);
		return;
	}
}
Exemplo n.º 8
0
int rxMode(int emu)
{
	if (!checkEmuNAND() && emu)
	{
		ConsoleInit();
		ConsoleSetTitle(L"EMUNAND NOT FOUND!");
		print(L"The emunand was not found on\n");
		print(L"your SDCard. \n");
		print(L"\n");
		print(L"Press A to boot SYSNAND\n");
		ConsoleShow();
		WaitForButton(BUTTON_A);
		emu = 0;
		char s[32];
		sprintf(s, "/rxTools/Theme/%u/boot.bin", cfgs[CFG_THEME].val.i);
		DrawBottomSplash(s);
	}

	static const char patchNandPrefix[] = ".patch.p9.nand";
	unsigned int cur, offset, shstrSize;
	char path[64], shstrtab[512], *sh_name;
	const char *platformDir;
	const wchar_t *msg;
	int r, sector;
	void *p;
	Elf32_Ehdr ehdr;
	Elf32_Shdr shdr;
	FIL fd, keyxFd;
	UINT br, fsz;

	setAgbBios();

	getFirmPath(path, getMpInfo() == MPINFO_KTR ?
		TID_KTR_NATIVE_FIRM : TID_CTR_NATIVE_FIRM);
    strcpy(path + strlen(path) - 4, "orig.bin");
	r = loadFirm(path, &fsz);
	if (r) {
		msg = L"Failed to load NATIVE_FIRM: %d\n"
			L"Reboot rxTools and try again.\n";
		goto fail;
	}

	r = getMpInfo();
	switch (r) {
		case MPINFO_KTR:
			platformDir = "ktr";
			break;

		case MPINFO_CTR:
			platformDir = "ctr";
			break;

		default:
			msg = L"Unknown Platform: %d";
			goto fail;
	}

	sprintf(path, SYS_PATH "/patches/%s/native_firm.elf", platformDir);
	r = f_open(&fd, path, FA_READ);
	if (r != FR_OK)
		goto patchFail;

	r = f_read(&fd, &ehdr, sizeof(ehdr), &br);
	if (r != FR_OK)
		goto patchFail;

	r = f_lseek(&fd, ehdr.e_shoff + ehdr.e_shstrndx * sizeof(Elf32_Shdr));
	if (r != FR_OK)
		goto patchFail;

	r = f_read(&fd, &shdr, sizeof(shdr), &br);
	if (r != FR_OK)
		goto patchFail;

	r = f_lseek(&fd, shdr.sh_offset);
	if (r != FR_OK)
		goto patchFail;

	r = f_read(&fd, shstrtab, shdr.sh_size > sizeof(shstrtab) ?
		sizeof(shstrtab) : shdr.sh_size, &shstrSize);
	if (r != FR_OK)
		goto patchFail;

	if (emu) {
		sector = checkEmuNAND();
		if (sector == 0) {
			msg = L"Failed to find EmuNAND.\n"
				L"Check your EmuNAND.\n";
			goto fail;
		}
	} else
		sector = 0;

	cur = ehdr.e_shoff;
	for (; ehdr.e_shnum; ehdr.e_shnum--, cur += sizeof(shdr)) {
		if (f_lseek(&fd, cur) != FR_OK)
			continue;

		if (f_read(&fd, &shdr, sizeof(shdr), &br) != FR_OK)
			continue;

		if (!(shdr.sh_flags & SHF_ALLOC) || shdr.sh_name >= shstrSize)
			continue;

		offset = locateSecInFirm(&shdr, (FirmHdr *)FIRM_ADDR);
		if (offset == 0)
			continue;

		p = (void *)(FIRM_ADDR + offset);
		sh_name = shstrtab + shdr.sh_name;

		if (!strcmp(sh_name, ".rodata.keyx")) {
			if (sysver >= 7)
				continue;

			if (f_open(&keyxFd, "slot0x25KeyX.bin", FA_READ) != FR_OK)
				continue;

			f_read(&keyxFd, p, shdr.sh_size, &br);
			f_close(&keyxFd);
		} else if (!strcmp(sh_name, ".rodata.nand.sector")) {
			if (sector)
				*(uint32_t *)p = (sector / 0x200) - 1;
		} else if (!strcmp(sh_name, ".rodata.label")) {
			*(uint32_t *)p = sector ? 'E-XR' : 'S-XR';
		} else if (shdr.sh_type == SHT_PROGBITS
			&& (sector || memcmp(sh_name, patchNandPrefix, sizeof(patchNandPrefix) - 1))
			&& (sysver < 7 || strcmp(sh_name, ".patch.p9.keyx")))
		{
			if (f_lseek(&fd, shdr.sh_offset) != FR_OK)
				continue;

			f_read(&fd, p, shdr.sh_size, &br);
		}
	}

	getFirmPath(path, getMpInfo() == MPINFO_KTR ?
		TID_KTR_NATIVE_FIRM : TID_CTR_NATIVE_FIRM);
	f_open(&fd, path, FA_WRITE | FA_CREATE_ALWAYS);
	f_write(&fd, (void *)FIRM_ADDR, fsz, &br);
	f_close(&fd);

	r = loadExecReboot(); // This won't return if it succeeds.
	msg = L"Failed to load reboot.bin: %d\n"
		L"Check your installation.\n";

fail:
	ConsoleInit();
	ConsoleSetTitle(L"rxMode");
	print(msg, r);
	print(L"\n");
	print(strings[STR_PRESS_BUTTON_ACTION],
		strings[STR_BUTTON_A], strings[STR_CONTINUE]);
	ConsoleShow();
	WaitForButton(BUTTON_A);

	return r;

patchFail:
	msg = L"Failed to load native_firm.elf: %d\n"
		L"Check your installation.\n";
	goto fail;
}
Exemplo n.º 9
0
int rxMode(int emu)
{
	wchar_t path[64];
	const char *shstrtab;
	const wchar_t *msg;
	uint8_t keyx[16];
	uint32_t tid;
	int r, sector;
	Elf32_Ehdr *ehdr;
	Elf32_Shdr *shdr, *btm;
	void *keyxArg;
	FIL fd;
	UINT br, fsz;

	if (emu) {
		sector = checkEmuNAND();
		if (sector == 0) {
			ConsoleInit();
			ConsoleSetTitle(L"EMUNAND NOT FOUND!");
			print(L"The emunand was not found on\n");
			print(L"your SDCard. \n");
			print(L"\n");
			print(L"Press A to boot SYSNAND\n");
			ConsoleShow();

			WaitForButton(BUTTON_A);

			swprintf(path, _MAX_LFN, L"/rxTools/Theme/%u/boot.bin",
				cfgs[CFG_THEME].val.i);
			DrawBottomSplash(path);
		}
	} else
		sector = 0;

	r = getMpInfo();
	switch (r) {
		case MPINFO_KTR:
			tid = TID_KTR_NATIVE_FIRM;
			break;

		case MPINFO_CTR:
			tid = TID_CTR_NATIVE_FIRM;
			break;

		default:
			msg = L"Unknown Platform: %d";
			goto fail;
	}

	setAgbBios();

	if (sysver < 7 && f_open(&fd, _T("slot0x25KeyX.bin"), FA_READ) == FR_OK) {
		f_read(&fd, keyx, sizeof(keyx), &br);
		f_close(&fd);
		keyxArg = keyx;
	} else
		keyxArg = NULL;

	getFirmPath(path, tid);
	r = loadFirm(path, &fsz);
	if (r) {
		msg = L"Failed to load NATIVE_FIRM: %d\n"
			L"Reboot rxTools and try again.\n";
		goto fail;
	}

	((FirmHdr *)FIRM_ADDR)->arm9Entry = 0x0801B01C;

	getFirmPatchPath(path, tid);
	r = f_open(&fd, path, FA_READ);
	if (r != FR_OK)
		goto patchFail;

	r = f_read(&fd, (void *)PATCH_ADDR, PATCH_SIZE, &br);
	if (r != FR_OK)
		goto patchFail;

	f_close(&fd);

	ehdr = (void *)PATCH_ADDR;
	shdr = (void *)(PATCH_ADDR + ehdr->e_shoff);
	shstrtab = (char *)PATCH_ADDR + shdr[ehdr->e_shstrndx].sh_offset;
	for (btm = shdr + ehdr->e_shnum; shdr != btm; shdr++) {
		if (!strcmp(shstrtab + shdr->sh_name, ".patch.p9.reboot.body")) {
			execReboot(sector, keyxArg, ehdr->e_entry, shdr);
			__builtin_unreachable();
		}
	}

	msg = L".patch.p9.reboot.body not found\n"
		L"Please check your installation.\n";
fail:
	ConsoleInit();
	ConsoleSetTitle(L"rxMode");
	print(msg, r);
	print(L"\n");
	print(strings[STR_PRESS_BUTTON_ACTION],
		strings[STR_BUTTON_A], strings[STR_CONTINUE]);
	ConsoleShow();
	WaitForButton(BUTTON_A);

	return r;

patchFail:
	msg = L"Failed to load the patch: %d\n"
		L"Check your installation.\n";
	goto fail;
}
Exemplo n.º 10
0
int rxMode(int emu)
{
    const Elf32_Addr line = 32;
    wchar_t path[64];
    const char *shstrtab;
    const wchar_t *msg;
    uint8_t keyx[16];
    uint32_t tid;
    int r, sector;
    Elf32_Ehdr *ehdr;
    Elf32_Shdr *shdr, *btmShdr;
    Elf32_Addr cur, btm;
    void *keyxArg;
    FIL fd;
    UINT br, fsz;

    if (emu) {
        sector = checkEmuNAND();
        if (sector == 0) {
            ConsoleInit();
            ConsoleSetTitle(L"EMUNAND NOT FOUND!");
            print(L"The emunand was not found on\n");
            print(L"your SDCard. \n");
            print(L"\n");
            print(L"Press A to boot SYSNAND\n");
            ConsoleShow();

            WaitForButton(BUTTON_A);

            swprintf(path, _MAX_LFN, L"/rxTools/Theme/%u/boot.bin",
                     cfgs[CFG_THEME].val.i);
            DrawBottomSplash(path);
        }
    } else
        sector = 0;

    r = getMpInfo();
    switch (r) {
    case MPINFO_KTR:
        tid = TID_KTR_NATIVE_FIRM;
        break;

    case MPINFO_CTR:
        tid = TID_CTR_NATIVE_FIRM;
        break;

    default:
        msg = L"Unknown Platform: %d";
        goto fail;
    }

    setAgbBios();

    if (sysver < 7 && f_open(&fd, _T("slot0x25KeyX.bin"), FA_READ) == FR_OK) {
        f_read(&fd, keyx, sizeof(keyx), &br);
        f_close(&fd);
        keyxArg = keyx;
    } else
        keyxArg = NULL;

    getFirmPath(path, tid);
    r = loadFirm(path, &fsz);
    if (r) {
        msg = L"Failed to load NATIVE_FIRM: %d\n"
              L"Reboot rxTools and try again.\n";
        goto fail;
    }

    ((FirmHdr *)FIRM_ADDR)->arm9Entry = 0x0801B01C;

    getFirmPatchPath(path, tid);
    r = f_open(&fd, path, FA_READ);
    if (r != FR_OK)
        goto patchFail;

    r = f_read(&fd, (void *)PATCH_ADDR, PATCH_SIZE, &br);
    if (r != FR_OK)
        goto patchFail;

    f_close(&fd);

    ehdr = (void *)PATCH_ADDR;
    shdr = (void *)(PATCH_ADDR + ehdr->e_shoff);
    shstrtab = (char *)PATCH_ADDR + shdr[ehdr->e_shstrndx].sh_offset;
    for (btmShdr = shdr + ehdr->e_shnum; shdr != btmShdr; shdr++) {
        if (!strcmp(shstrtab + shdr->sh_name, ".patch.p9.reboot.body")) {
            memcpy((void *)ehdr->e_entry,
                   (void *)(PATCH_ADDR + shdr->sh_offset),
                   shdr->sh_size);

            // Drain write buffer
            __asm__ volatile ("mcr p15, 0, %0, c7, c10, 4" :: "r"(0));

            cur = ehdr->e_entry & ~(line - 1);
            btm = ehdr->e_entry + shdr->sh_size;
            while (cur < btm) {
                __asm__ volatile (
                    // Clean Dcache
                    "mcr p15, 0, %0, c7, c10, 1\n\t"

                    // Flush Icache
                    "mcr p15, 0, %0, c7, c5, 1"
                    :: "r"(cur));

                cur += line;
            }

            ((void (*)(uint32_t, void *, uintptr_t))ehdr->e_entry)(
                sector, keyxArg, 0x1FFFFFF8);

            __builtin_unreachable();
        }
    }