Permalink
Browse files

added self chainloading

  • Loading branch information...
Reisyukaku committed Aug 29, 2018
1 parent 1ae5ce2 commit 1cf800308e672fd4894e37a12d9cc82976028412
Showing with 26 additions and 5 deletions.
  1. +1 −1 src/bootrom.c
  2. +13 −2 src/firmware.c
  3. +2 −0 src/firmware.h
  4. +8 −1 src/fs.c
  5. +2 −1 src/fs.h
View
@@ -36,5 +36,5 @@ void bootrom(void) {
// Clear the boot reason to avoid problems later
PMC(APBDEV_PMC_SCRATCH200) = 0x0;
PMC(APBDEV_PMC_RST_STATUS_0) = 0x0;
PMC(APBDEV_PMC_SCRATCH49_0) = 0x0;
//PMC(APBDEV_PMC_SCRATCH49_0) = 0x0;
}
View
@@ -398,14 +398,25 @@ void firmware() {
gfx_con_init(&gfx_con, &gfx_ctxt);
gfx_con_setcol(&gfx_con, ORANGE, 0, 0);
while (!sd_mount()) {
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_0) != 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_0) = 69;
((void (*)())PAYLOAD_ADDR)();
}
print("Welcome to ReiNX %s!\n", VERSION);
loadFirm();
drawSplash();
View
@@ -26,6 +26,8 @@
#define BOOT_PKG2_LOADED_4X 3
#define BOOT_DONE_4X 4
#define PAYLOAD_ADDR 0xCFF00000
//Instructions
#define NOP 0xD503201F
#define ADRP(r, o) 0x90000000 | ((((o) >> 12) & 0x3) << 29) | ((((o) >> 12) & 0x1FFFFC) << 3) | ((r) & 0x1F)
View
@@ -28,7 +28,7 @@ FATFS sd_fs;
int sd_mounted;
FIL fp;
u32 sd_mount() {
u32 sdMount() {
if (sd_mounted) return 1;
if (sdmmc_storage_init_sd(&sd_storage, &sd_sdmmc, SDMMC_1, SDMMC_BUS_WIDTH_4, 11) && f_mount(&sd_fs, "", 1) == FR_OK) {
@@ -39,6 +39,13 @@ u32 sd_mount() {
return 0;
}
void sdUnmount() {
f_mount(NULL, "", 1);
sdmmc_storage_end(&sd_storage);
sd_mounted = 0;
}
u32 fopen(const char *path, const char *mode) {
u32 m = (mode[0] == 0x77 ? (FA_WRITE|FA_CREATE_NEW) : FA_READ);
if (f_open(&fp, path, m) != FR_OK)
View
@@ -16,7 +16,8 @@
#pragma once
u32 sd_mount();
u32 sdMount();
void sdUnmount();
u32 fopen(const char *path, const char *mode);
u32 fread(void *buf, size_t size, size_t ntimes);
u32 fwrite(void *buf, size_t size, size_t ntimes);

0 comments on commit 1cf8003

Please sign in to comment.