Skip to content

Commit

Permalink
Fixed intermittent splash from CakeBrah, made splash last slightly lo…
Browse files Browse the repository at this point in the history
…nger, added shutdown on error, slimmed down FatFs, added error on missing emuNAND, changed folder to "aurei", changed the dat name to "AuReiNand.dat", propered the built-in screen init of the chainloader, remade the look of the 3dsx

(First luma-powered CFW!)
  • Loading branch information
AuroraWright committed Mar 20, 2016
1 parent 6dfb331 commit c8b2912
Show file tree
Hide file tree
Showing 20 changed files with 214 additions and 144 deletions.
32 changes: 16 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ifneq ($(PYTHON_VER_MAJOR), 3)
PYTHON3 := py -3
endif

name := ReiNand
name := AuReiNand

dir_source := source
dir_data := data
Expand All @@ -26,7 +26,7 @@ dir_loader := loader

ASFLAGS := -mlittle-endian -mcpu=arm946e-s -march=armv5te
CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -fshort-wchar -std=c11 -Wno-main -O2 -ffast-math
FLAGS := name=$(name).dat dir_out=$(abspath $(dir_out)) ICON=$(abspath icon.png) --no-print-directory
FLAGS := name=$(name).dat dir_out=$(abspath $(dir_out)) ICON=$(abspath icon.png) APP_DESCRIPTION="Noob-friendly 3DS CFW." APP_AUTHOR="Reisyukaku/Aurora Wright" --no-print-directory

objects_cfw = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
$(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
Expand All @@ -43,29 +43,29 @@ launcher: $(dir_out)/$(name).dat
a9lh: $(dir_out)/arm9loaderhax.bin

.PHONY: emunand
emunand: $(dir_out)/rei/emunand/emunand.bin
emunand: $(dir_out)/aurei/emunand/emunand.bin

.PHONY: reboot
reboot: $(dir_out)/rei/reboot/reboot.bin
reboot: $(dir_out)/aurei/reboot/reboot.bin

.PHONY: ninjhax
ninjhax: $(dir_out)/3ds/$(name)

.PHONY: loader
loader: $(dir_out)/rei/loader.bin
loader: $(dir_out)/aurei/loader.bin

.PHONY: clean
clean:
@$(MAKE) $(FLAGS) -C $(dir_mset) clean
@$(MAKE) $(FLAGS) -C $(dir_ninjhax) clean
@rm -rf $(dir_out) $(dir_build)
@cd $(dir_loader) && make clean
@$(MAKE) -C $(dir_loader) clean

$(dir_out)/$(name).dat: $(dir_build)/main.bin $(dir_out)/rei
$(dir_out)/$(name).dat: $(dir_build)/main.bin $(dir_out)/aurei
@$(MAKE) $(FLAGS) -C $(dir_mset) launcher
dd if=$(dir_build)/main.bin of=$@ bs=512 seek=144

$(dir_out)/arm9loaderhax.bin: $(dir_build)/main.bin $(dir_out)/rei
$(dir_out)/arm9loaderhax.bin: $(dir_build)/main.bin $(dir_out)/aurei
@cp -av $(dir_build)/main.bin $@

$(dir_out)/3ds/$(name):
Expand All @@ -74,21 +74,21 @@ $(dir_out)/3ds/$(name):
@mv $(dir_out)/$(name).3dsx $@
@mv $(dir_out)/$(name).smdh $@

$(dir_out)/rei:
@mkdir -p "$(dir_out)/rei"
$(dir_out)/aurei:
@mkdir -p "$(dir_out)/aurei"

$(dir_out)/rei/emunand/emunand.bin: $(dir_emu)/emuCode.s
$(dir_out)/aurei/emunand/emunand.bin: $(dir_emu)/emuCode.s
@armips $<
@mkdir -p "$(dir_out)/rei/emunand"
@mkdir -p "$(dir_out)/aurei/emunand"
@mv emunand.bin $@

$(dir_out)/rei/reboot/reboot.bin: $(dir_reboot)/rebootCode.s
$(dir_out)/aurei/reboot/reboot.bin: $(dir_reboot)/rebootCode.s
@armips $<
@mkdir -p "$(dir_out)/rei/reboot"
@mkdir -p "$(dir_out)/aurei/reboot"
@mv reboot.bin $@

$(dir_out)/rei/loader.bin: $(dir_out)/rei $(dir_loader)/Makefile
@cd $(dir_loader) && make
$(dir_out)/aurei/loader.bin: $(dir_out)/aurei $(dir_loader)/Makefile
@$(MAKE) -C $(dir_loader)
@mv $(dir_loader)/loader.bin $@

$(dir_build)/main.bin: $(dir_build)/main.elf
Expand Down
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions loader/source/fatfs/sdmmc/common.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once

#include <stdbool.h>
#include "../../types.h"
75 changes: 12 additions & 63 deletions loader/source/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ static const struct { u8 bus_id, reg_addr; } dev_data[] = {
{2, 0xA4}, {2, 0x9A}, {2, 0xA0},
};

inline u8 i2cGetDeviceBusId(u8 device_id) {
static inline u8 i2cGetDeviceBusId(u8 device_id) {
return dev_data[device_id].bus_id;
}

inline u8 i2cGetDeviceRegAddr(u8 device_id) {
static inline u8 i2cGetDeviceRegAddr(u8 device_id) {
return dev_data[device_id].reg_addr;
}

Expand All @@ -26,7 +26,7 @@ static vu8* reg_data_addrs[] = {
(vu8*)(I2C3_REG_OFF + I2C_REG_DATA),
};

inline vu8* i2cGetDataReg(u8 bus_id) {
static inline vu8* i2cGetDataReg(u8 bus_id) {
return reg_data_addrs[bus_id];
}

Expand All @@ -38,37 +38,37 @@ static vu8* reg_cnt_addrs[] = {
(vu8*)(I2C3_REG_OFF + I2C_REG_CNT),
};

inline vu8* i2cGetCntReg(u8 bus_id) {
static inline vu8* i2cGetCntReg(u8 bus_id) {
return reg_cnt_addrs[bus_id];
}

//-----------------------------------------------------------------------------

inline void i2cWaitBusy(u8 bus_id) {
static inline void i2cWaitBusy(u8 bus_id) {
while (*i2cGetCntReg(bus_id) & 0x80);
}

inline bool i2cGetResult(u8 bus_id) {
static inline u32 i2cGetResult(u8 bus_id) {
i2cWaitBusy(bus_id);
return (*i2cGetCntReg(bus_id) >> 4) & 1;
}

void i2cStop(u8 bus_id, u8 arg0) {
static void i2cStop(u8 bus_id, u8 arg0) {
*i2cGetCntReg(bus_id) = (arg0 << 5) | 0xC0;
i2cWaitBusy(bus_id);
*i2cGetCntReg(bus_id) = 0xC5;
}

//-----------------------------------------------------------------------------

bool i2cSelectDevice(u8 bus_id, u8 dev_reg) {
static u32 i2cSelectDevice(u8 bus_id, u8 dev_reg) {
i2cWaitBusy(bus_id);
*i2cGetDataReg(bus_id) = dev_reg;
*i2cGetCntReg(bus_id) = 0xC2;
return i2cGetResult(bus_id);
}

bool i2cSelectRegister(u8 bus_id, u8 reg) {
static u32 i2cSelectRegister(u8 bus_id, u8 reg) {
i2cWaitBusy(bus_id);
*i2cGetDataReg(bus_id) = reg;
*i2cGetCntReg(bus_id) = 0xC0;
Expand All @@ -77,58 +77,7 @@ bool i2cSelectRegister(u8 bus_id, u8 reg) {

//-----------------------------------------------------------------------------

u8 i2cReadRegister(u8 dev_id, u8 reg) {
u8 bus_id = i2cGetDeviceBusId(dev_id);
u8 dev_addr = i2cGetDeviceRegAddr(dev_id);

for (size_t i = 0; i < 8; i++) {
if (i2cSelectDevice(bus_id, dev_addr) && i2cSelectRegister(bus_id, reg)) {
if (i2cSelectDevice(bus_id, dev_addr | 1)) {
i2cWaitBusy(bus_id);
i2cStop(bus_id, 1);
i2cWaitBusy(bus_id);
return *i2cGetDataReg(bus_id);
}
}
*i2cGetCntReg(bus_id) = 0xC5;
i2cWaitBusy(bus_id);
}
return 0xff;
}

bool i2cReadRegisterBuffer(unsigned int dev_id, int reg, u8* buffer, size_t buf_size) {
u8 bus_id = i2cGetDeviceBusId(dev_id);
u8 dev_addr = i2cGetDeviceRegAddr(dev_id);

size_t j = 0;
while (!i2cSelectDevice(bus_id, dev_addr)
|| !i2cSelectRegister(bus_id, reg)
|| !i2cSelectDevice(bus_id, dev_addr | 1))
{
i2cWaitBusy(bus_id);
*i2cGetCntReg(bus_id) = 0xC5;
i2cWaitBusy(bus_id);
if (++j >= 8)
return false;
}

if (buf_size != 1) {
for (size_t i = 0; i < buf_size - 1; i++) {
i2cWaitBusy(bus_id);
*i2cGetCntReg(bus_id) = 0xF0;
i2cWaitBusy(bus_id);
buffer[i] = *i2cGetDataReg(bus_id);
}
}

i2cWaitBusy(bus_id);
*i2cGetCntReg(bus_id) = 0xE1;
i2cWaitBusy(bus_id);
*buffer = *i2cGetDataReg(bus_id);
return true;
}

bool i2cWriteRegister(u8 dev_id, u8 reg, u8 data) {
u32 i2cWriteRegister(u8 dev_id, u8 reg, u8 data) {
u8 bus_id = i2cGetDeviceBusId(dev_id);
u8 dev_addr = i2cGetDeviceRegAddr(dev_id);

Expand All @@ -139,11 +88,11 @@ bool i2cWriteRegister(u8 dev_id, u8 reg, u8 data) {
*i2cGetCntReg(bus_id) = 0xC1;
i2cStop(bus_id, 0);
if (i2cGetResult(bus_id))
return true;
return 1;
}
*i2cGetCntReg(bus_id) = 0xC5;
i2cWaitBusy(bus_id);
}

return false;
return 0;
}
19 changes: 1 addition & 18 deletions loader/source/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,4 @@
#define I2C_DEV_GYRO 10
#define I2C_DEV_IR 13

u8 i2cGetDeviceBusId(u8 device_id);
u8 i2cGetDeviceRegAddr(u8 device_id);

vu8* i2cGetDataReg(u8 bus_id);
vu8* i2cGetCntReg(u8 bus_id);

void i2cWaitBusy(u8 bus_id);
bool i2cGetResult(u8 bus_id);
u8 i2cGetData(u8 bus_id);
void i2cStop(u8 bus_id, u8 arg0);

bool i2cSelectDevice(u8 bus_id, u8 dev_reg);
bool i2cSelectRegister(u8 bus_id, u8 reg);

u8 i2cReadRegister(u8 dev_id, u8 reg);
bool i2cWriteRegister(u8 dev_id, u8 reg, u8 data);

bool i2cReadRegisterBuffer(unsigned int dev_id, int reg, u8* buffer, size_t buf_size);
u32 i2cWriteRegister(u8 dev_id, u8 reg, u8 data);
20 changes: 10 additions & 10 deletions loader/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ void main(void){
//Get pressed buttons
u16 pressed = HID_PAD;

if(((pressed & BUTTON_B) && loadPayload("/rei/payloads/b.bin")) ||
((pressed & BUTTON_X) && loadPayload("/rei/payloads/x.bin")) ||
((pressed & BUTTON_Y) && loadPayload("/rei/payloads/y.bin")) ||
((pressed & BUTTON_SELECT) && loadPayload("/rei/payloads/select.bin")) ||
((pressed & BUTTON_START) && loadPayload("/rei/payloads/start.bin")) ||
((pressed & BUTTON_RIGHT) && loadPayload("/rei/payloads/right.bin")) ||
((pressed & BUTTON_LEFT) && loadPayload("/rei/payloads/left.bin")) ||
((pressed & BUTTON_UP) && loadPayload("/rei/payloads/up.bin")) ||
((pressed & BUTTON_DOWN) && loadPayload("/rei/payloads/down.bin")) ||
loadPayload("/rei/payloads/default.bin")){
if(((pressed & BUTTON_B) && loadPayload("/aurei/payloads/b.bin")) ||
((pressed & BUTTON_X) && loadPayload("/aurei/payloads/x.bin")) ||
((pressed & BUTTON_Y) && loadPayload("/aurei/payloads/y.bin")) ||
((pressed & BUTTON_SELECT) && loadPayload("/aurei/payloads/select.bin")) ||
((pressed & BUTTON_START) && loadPayload("/aurei/payloads/start.bin")) ||
((pressed & BUTTON_RIGHT) && loadPayload("/aurei/payloads/right.bin")) ||
((pressed & BUTTON_LEFT) && loadPayload("/aurei/payloads/left.bin")) ||
((pressed & BUTTON_UP) && loadPayload("/aurei/payloads/up.bin")) ||
((pressed & BUTTON_DOWN) && loadPayload("/aurei/payloads/down.bin")) ||
loadPayload("/aurei/payloads/default.bin")){
//Determine if screen was already inited
if(*(vu8 *)0x10141200 == 0x1) initLCD();
((void (*)())PAYLOAD_ADDRESS)();
Expand Down
16 changes: 7 additions & 9 deletions loader/source/screeninit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#include "i2c.h"

void initLCD(void){
vu32 *const arm11 = (u32 *)0x1FFFFFF8;
vu32 *const arm11 = (vu32 *)0x1FFFFFF8;

void __attribute__((naked)) ARM11(void){
__asm(".word 0xF10C01C0");
*(vu32 *)0x10141200 = 0x1007F;
*(vu32 *)0x10202014 = 0x00000001;
*(vu32 *)0x1020200C &= 0xFFFEFFFE;
Expand Down Expand Up @@ -91,6 +92,11 @@ void initLCD(void){
*(vu32 *)0x10400568 = 0x18346500;
*(vu32 *)0x1040056c = 0x18346500;

//Set CakeBrah framebuffers
*((vu32 *)0x23FFFE00) = 0x18300000;
*((vu32 *)0x23FFFE04) = 0x18300000;
*((vu32 *)0x23FFFE08) = 0x18346500;

//Clear ARM11 entry offset
*arm11 = 0;

Expand All @@ -100,14 +106,6 @@ void initLCD(void){
((void (*)())*arm11)();
}

//Set CakeBrah framebuffers
*(vu32 *)0x23FFFE00 = 0x18300000;
*(vu32 *)0x23FFFE04 = 0x18300000;
*(vu32 *)0x23FFFE08 = 0x18346500;

*arm11 = (u32)ARM11;

//This delay is needed for some reason
for(vu32 i = 0; i < 0x2000; ++i);
while(*arm11);
}
1 change: 0 additions & 1 deletion loader/source/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#pragma once

#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

Expand Down
2 changes: 1 addition & 1 deletion reboot/rebootCode.s
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Memcpy:
BX LR

FileName:
.dcw "sdmc:/rei/patched_firmware_sys.bin"
.dcw "sdmc:/aurei/patched_firmware_sys.bin"
.word 0x0

.pool
Expand Down
12 changes: 6 additions & 6 deletions source/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ void __attribute__((naked)) shutdownLCD(void){
}

static void clearScreen(void){
memset(fb->top_left, 0, 0x46500);
memset(fb->top_right, 0, 0x46500);
memset(fb->bottom, 0, 0x38400);
memset32(fb->top_left, 0, 0x46500);
memset32(fb->top_right, 0, 0x46500);
memset32(fb->bottom, 0, 0x38400);
}

void loadSplash(void){
clearScreen();
//Don't delay boot if no splash image is on the SD
if(fileRead(fb->top_left, "/rei/splash.bin", 0x46500) +
fileRead(fb->bottom, "/rei/splashbottom.bin", 0x38400)){
u64 i = 0xFFFFFF; while(--i) __asm("mov r0, r0"); //Less Ghetto sleep func
if(fileRead(fb->top_left, "/aurei/splash.bin", 0x46500) +
fileRead(fb->bottom, "/aurei/splashbottom.bin", 0x38400)){
u64 i = 0x1300000; while(--i) __asm("mov r0, r0"); //Less Ghetto sleep func
}
}
5 changes: 5 additions & 0 deletions source/emunand.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ void getEmunandSect(u32 *off, u32 *head, u32 emuNAND){
}
//Fallback to the first emuNAND if there's no second one
else if(emuNAND == 2) getEmunandSect(off, head, 1);
//Check if a RedNAND is present
else if(sdmmc_sdcard_readsectors(1, 1, temp) == 0){
if(*(u32 *)(temp + 0x100) != NCSD_MAGIC)
*head = 0;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/fatfs/ffconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/ and optional writing functions as well. */


#define _FS_MINIMIZE 0
#define _FS_MINIMIZE 3
/* This option defines minimization level to remove some basic API functions.
/
/ 0: All basic functions are enabled.
Expand Down
Loading

0 comments on commit c8b2912

Please sign in to comment.