Permalink
Please sign in to comment.
Showing
with
26,550 additions
and 0 deletions.
- +3 −0 .gitignore
- +339 −0 LICENSE.txt
- +54 −0 Makefile
- +32 −0 README.md
- BIN data/loader.kip
- BIN data/sm.kip
- BIN data/splash.bin
- +29 −0 link.ld
- +196 −0 src/bootloader.c
- +19 −0 src/bootloader.h
- +40 −0 src/bootrom.c
- +19 −0 src/bootrom.h
- +36 −0 src/error.c
- +23 −0 src/error.h
- +351 −0 src/firmware.c
- +17 −0 src/firmware.h
- +116 −0 src/fs.c
- +9 −0 src/fs.h
- +47 −0 src/fuse.c
- +21 −0 src/fuse.h
- +59 −0 src/hwinit.h
- +1,667 −0 src/hwinit/ELF.h
- +42 −0 src/hwinit/btn.c
- +29 −0 src/hwinit/btn.h
- +449 −0 src/hwinit/clock.c
- +108 −0 src/hwinit/clock.h
- +127 −0 src/hwinit/cluster.c
- +28 −0 src/hwinit/cluster.h
- +173 −0 src/hwinit/di.c
- +72 −0 src/hwinit/di.h
- +548 −0 src/hwinit/di.inl
- +71 −0 src/hwinit/diskio.c
- +80 −0 src/hwinit/diskio.h
- +667 −0 src/hwinit/emc.h
- +6,555 −0 src/hwinit/ff.c
- +366 −0 src/hwinit/ff.h
- +283 −0 src/hwinit/ffconf.h
- +608 −0 src/hwinit/ffunicode.c
- +522 −0 src/hwinit/gfx.c
- +78 −0 src/hwinit/gfx.h
- +94 −0 src/hwinit/gpio.c
- +77 −0 src/hwinit/gpio.h
- +142 −0 src/hwinit/heap.c
- +28 −0 src/hwinit/heap.h
- +132 −0 src/hwinit/i2c.c
- +35 −0 src/hwinit/i2c.h
- +141 −0 src/hwinit/ini.c
- +42 −0 src/hwinit/ini.h
- +38 −0 src/hwinit/integer.h
- +42 −0 src/hwinit/kfuse.c
- +41 −0 src/hwinit/kfuse.h
- +95 −0 src/hwinit/list.h
- +179 −0 src/hwinit/lz.c
- +52 −0 src/hwinit/lz.h
- +324 −0 src/hwinit/max77620.h
- +141 −0 src/hwinit/max7762x.c
- +68 −0 src/hwinit/max7762x.h
- +136 −0 src/hwinit/mc.c
- +13 −0 src/hwinit/mc.h
- +466 −0 src/hwinit/mc_t210.h
- +432 −0 src/hwinit/mmc.h
- +76 −0 src/hwinit/nx_emmc.c
- +72 −0 src/hwinit/nx_emmc.h
- +32 −0 src/hwinit/pinmux.c
- +87 −0 src/hwinit/pinmux.h
- +49 −0 src/hwinit/pmc.h
- +563 −0 src/hwinit/pmc_t210_lp0.h
- +109 −0 src/hwinit/sd.h
- +1,129 −0 src/hwinit/sdmmc.c
- +111 −0 src/hwinit/sdmmc.h
- +1,092 −0 src/hwinit/sdmmc_driver.c
- +126 −0 src/hwinit/sdmmc_driver.h
- +132 −0 src/hwinit/sdmmc_t210.h
- +522 −0 src/hwinit/sdram.c
- +24 −0 src/hwinit/sdram.h
- +1,152 −0 src/hwinit/sdram.inl
- +1,102 −0 src/hwinit/sdram_lp0.c
- +124 −0 src/hwinit/sdram_lz.inl
- +930 −0 src/hwinit/sdram_param_t210.h
- +961 −0 src/hwinit/sdram_param_t210_lp0.h
- +256 −0 src/hwinit/se.c
- +30 −0 src/hwinit/se.h
- +357 −0 src/hwinit/se_t210.h
- +125 −0 src/hwinit/t210.h
- +136 −0 src/hwinit/tsec.c
- +24 −0 src/hwinit/tsec.h
- +56 −0 src/hwinit/types.h
- +78 −0 src/hwinit/uart.c
- +59 −0 src/hwinit/uart.h
- +45 −0 src/hwinit/util.c
- +33 −0 src/hwinit/util.h
- +143 −0 src/package.c
- +90 −0 src/package.h
- +34 −0 src/reloc.s
- +90 −0 src/start.s
| @@ -0,0 +1,3 @@ | ||
| build/ | ||
| out/ | ||
| *zip |
| @@ -0,0 +1,54 @@ | ||
| rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2)) | ||
| ifeq ($(strip $(DEVKITARM)),) | ||
| $(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") | ||
| endif | ||
| CC = $(DEVKITARM)/bin/arm-none-eabi-gcc | ||
| LD = $(DEVKITARM)/bin/arm-none-eabi-ld | ||
| OBJCOPY = $(DEVKITARM)/bin/arm-none-eabi-objcopy | ||
| name := ReiNX | ||
| dir_source := src | ||
| dir_data := data | ||
| dir_build := build | ||
| dir_out := out | ||
| ARCH := -march=armv4t -mtune=arm7tdmi -mthumb -mthumb-interwork | ||
| CFLAGS = $(ARCH) -Os -nostdlib -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-inline -std=gnu11# -Wall | ||
| LDFLAGS = $(ARCH) -nostartfiles -lgcc -Wl,--nmagic,--gc-sections | ||
| objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \ | ||
| $(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \ | ||
| $(call rwildcard, $(dir_source), *.s *.c))) | ||
| define bin2o | ||
| bin2s $< | $(AS) -o $(@) | ||
| endef | ||
| .PHONY: all | ||
| all: $(dir_out)/$(name).bin | ||
| .PHONY: clean | ||
| clean: | ||
| @rm -rf $(dir_build) | ||
| @rm -rf $(dir_out) | ||
| $(dir_out)/$(name).bin: $(dir_build)/$(name).elf | ||
| @mkdir -p "$(@D)" | ||
| @mkdir -p "$(dir_out)/ReiNX/sysmodules" | ||
| @cp -R $(dir_data)/*.kip $(dir_out)/ReiNX/sysmodules/ | ||
| @cp -R $(dir_data)/*.bin $(dir_out)/ReiNX/ | ||
| $(OBJCOPY) -S -O binary $< $@ | ||
| $(dir_build)/$(name).elf: $(objects) | ||
| $(CC) $(LDFLAGS) -T link.ld $^ -o $@ | ||
| $(dir_build)/%.o: $(dir_source)/%.c | ||
| @mkdir -p "$(@D)" | ||
| $(CC) $(CFLAGS) -c $< -o $@ | ||
| $(dir_build)/%.o: $(dir_source)/%.s | ||
| @mkdir -p "$(@D)" | ||
| $(CC) $(CFLAGS) -c $< -o $@ |
| @@ -0,0 +1,32 @@ | ||
| # ReiNX | ||
| [](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html) | ||
| *The modular switch custom firmware* | ||
| **Usage:** | ||
| Put `ReiNX` folder on the root of your switch's SD card and run `ReiNX.bin` with your favorite fusee launcher. | ||
| **Compiling:** | ||
| You'll need devkitpro with devkitA64 and run `make` | ||
| **Features:** | ||
| * Loads all KIPs from `/ReiNX/sysmodules/` directory | ||
| * Optional custom kernel/secmon/warmboot | ||
| * Default kips with exefs redir from `/ReiNX/title/{tid}` | ||
| **Credits:** | ||
| Naehrwert for hardware init code and generally being helpful! | ||
| CTCaer and st4rk for their contribution to the hardware code aswell! | ||
| SciresM for kernel processes! | ||
| The community for your support! |
Binary file not shown.
Binary file not shown.
Binary file not shown.
| @@ -0,0 +1,29 @@ | ||
| ENTRY(_start) | ||
| SECTIONS | ||
| { | ||
| PROVIDE(__ipl_start = 0x40003000); | ||
| . = __ipl_start; | ||
| .text.start : | ||
| { | ||
| *(.text.start) | ||
| } | ||
| .text : | ||
| { | ||
| *(.text*); | ||
| } | ||
| .data : | ||
| { | ||
| *(.data*); | ||
| *(.rodata*); | ||
| } | ||
| . = ALIGN(0x10); | ||
| __ipl_end = .; | ||
| .bss : | ||
| { | ||
| __bss_start = .; | ||
| *(COMMON) | ||
| *(.bss*) | ||
| __bss_end = .; | ||
| } | ||
| } |
| @@ -0,0 +1,196 @@ | ||
| /* | ||
| * Copyright (c) 2018 Reisyukaku | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify it | ||
| * under the terms and conditions of the GNU General Public License, | ||
| * version 2, as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope 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 "hwinit.h" | ||
| #include "fuse.h" | ||
| #include "error.h" | ||
| #include "bootloader.h" | ||
| void check_sku() { | ||
| if (FUSE(FUSE_SKU) != 0x83) | ||
| panic(); | ||
| } | ||
| void check_config_fuses() { | ||
| u32 config = get_unknown_config(); | ||
| u32 unitType = get_unit_type(); | ||
| u32 bromVer = FUSE(FUSE_SOC_SPEEDO_1); | ||
| if (config == 3 || unitType == 2 || bromVer < 0x1F) | ||
| panic(); | ||
| } | ||
| void mbist_workaround() { | ||
| CLOCK(0x410) = (CLOCK(0x410) | 0x8000) & 0xFFFFBFFF; | ||
| CLOCK(0xD0) |= 0x40800000u; | ||
| CLOCK(0x2AC) = 0x40; | ||
| CLOCK(0x294) = 0x40000; | ||
| CLOCK(0x304) = 0x18000000; | ||
| sleep(2); | ||
| I2S(0x0A0) |= 0x400; | ||
| I2S(0x088) &= 0xFFFFFFFE; | ||
| I2S(0x1A0) |= 0x400; | ||
| I2S(0x188) &= 0xFFFFFFFE; | ||
| I2S(0x2A0) |= 0x400; | ||
| I2S(0x288) &= 0xFFFFFFFE; | ||
| I2S(0x3A0) |= 0x400; | ||
| I2S(0x388) &= 0xFFFFFFFE; | ||
| I2S(0x4A0) |= 0x400; | ||
| I2S(0x488) &= 0xFFFFFFFE; | ||
| DISPLAY_A(0xCF8) |= 4; | ||
| VIC(0x8C) = 0xFFFFFFFF; | ||
| sleep(2); | ||
| CLOCK(0x2A8) = 0x40; | ||
| CLOCK(0x300) = 0x18000000; | ||
| CLOCK(0x290) = 0x40000; | ||
| CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_H) = 0xC0; | ||
| CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_L) = 0x80000130; | ||
| CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_U) = 0x1F00200; | ||
| CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_V) = 0x80400808; | ||
| CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_W) = 0x402000FC; | ||
| CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_X) = 0x23000780; | ||
| CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_Y) = 0x300; | ||
| CLOCK(0xF8) = 0; | ||
| CLOCK(0xFC) = 0; | ||
| CLOCK(0x3A0) = 0; | ||
| CLOCK(0x3A4) = 0; | ||
| CLOCK(0x554) = 0; | ||
| CLOCK(0xD0) &= 0x1F7FFFFF; | ||
| CLOCK(0x410) &= 0xFFFF3FFF; | ||
| CLOCK(0x148) = CLOCK(0x148) & 0x1FFFFFFF | 0x80000000; | ||
| CLOCK(0x180) = CLOCK(0x180) & 0x1FFFFFFF | 0x80000000; | ||
| CLOCK(0x6A0) = CLOCK(0x6A0) & 0x1FFFFFFF | 0x80000000; | ||
| } | ||
| void config_pmc_scratch() { | ||
| PMC(APBDEV_PMC_SCRATCH20) &= 0xFFF3FFFF; | ||
| PMC(APBDEV_PMC_SCRATCH190) &= 0xFFFFFFFE; | ||
| PMC(APBDEV_PMC_SECURE_SCRATCH21) |= 0x10; | ||
| } | ||
| void config_oscillators() { | ||
| CLOCK(CLK_RST_CONTROLLER_SPARE_REG0) = CLOCK(CLK_RST_CONTROLLER_SPARE_REG0) & 0xFFFFFFF3 | 4; | ||
| SYSCTR0(SYSCTR0_CNTFID0) = 19200000; | ||
| TMR(0x14) = 0x45F; | ||
| CLOCK(CLK_RST_CONTROLLER_OSC_CTRL) = 0x50000071; | ||
| PMC(APBDEV_PMC_OSC_EDPD_OVER) = PMC(APBDEV_PMC_OSC_EDPD_OVER) & 0xFFFFFF81 | 0xE; | ||
| PMC(APBDEV_PMC_OSC_EDPD_OVER) = PMC(APBDEV_PMC_OSC_EDPD_OVER) & 0xFFBFFFFF | 0x400000; | ||
| PMC(APBDEV_PMC_CNTRL2) = PMC(APBDEV_PMC_CNTRL2) & 0xFFFFEFFF | 0x1000; | ||
| PMC(APBDEV_PMC_SCRATCH188) = PMC(APBDEV_PMC_SCRATCH188) & 0xFCFFFFFF | 0x2000000; | ||
| CLOCK(CLK_RST_CONTROLLER_CLK_SYSTEM_RATE) = 0x10; | ||
| CLOCK(CLK_RST_CONTROLLER_PLLMB_BASE) &= 0xBFFFFFFF; | ||
| PMC(APBDEV_PMC_TSC_MULT) = PMC(APBDEV_PMC_TSC_MULT) & 0xFFFF0000 | 0x249F; //0x249F = 19200000 * (16 / 32.768 kHz) | ||
| CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) = 0x20004444; | ||
| CLOCK(CLK_RST_CONTROLLER_SUPER_SCLK_DIVIDER) = 0x80000000; | ||
| CLOCK(CLK_RST_CONTROLLER_CLK_SYSTEM_RATE) = 2; | ||
| } | ||
| void config_gpios() { | ||
| PINMUX_AUX(PINMUX_AUX_UART2_TX) = 0; | ||
| PINMUX_AUX(PINMUX_AUX_UART3_TX) = 0; | ||
| PINMUX_AUX(PINMUX_AUX_GPIO_PE6) = 0x40; | ||
| PINMUX_AUX(PINMUX_AUX_GPIO_PH6) = 0x40; | ||
| gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_GPIO); | ||
| gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_GPIO); | ||
| gpio_config(GPIO_PORT_E, GPIO_PIN_6, GPIO_MODE_GPIO); | ||
| gpio_config(GPIO_PORT_H, GPIO_PIN_6, GPIO_MODE_GPIO); | ||
| gpio_output_enable(GPIO_PORT_G, GPIO_PIN_0, GPIO_OUTPUT_DISABLE); | ||
| gpio_output_enable(GPIO_PORT_D, GPIO_PIN_1, GPIO_OUTPUT_DISABLE); | ||
| gpio_output_enable(GPIO_PORT_E, GPIO_PIN_6, GPIO_OUTPUT_DISABLE); | ||
| gpio_output_enable(GPIO_PORT_H, GPIO_PIN_6, GPIO_OUTPUT_DISABLE); | ||
| pinmux_config_i2c(I2C_1); | ||
| pinmux_config_i2c(I2C_5); | ||
| pinmux_config_uart(UART_A); | ||
| // Configure volume up/down as inputs. | ||
| gpio_config(GPIO_PORT_X, GPIO_PIN_6, GPIO_MODE_GPIO); | ||
| gpio_config(GPIO_PORT_X, GPIO_PIN_7, GPIO_MODE_GPIO); | ||
| gpio_output_enable(GPIO_PORT_X, GPIO_PIN_6, GPIO_OUTPUT_DISABLE); | ||
| gpio_output_enable(GPIO_PORT_X, GPIO_PIN_7, GPIO_OUTPUT_DISABLE); | ||
| } | ||
| void setup() { | ||
| config_oscillators(); | ||
| APB_MISC(0x40) = 0; | ||
| config_gpios(); | ||
| if (get_unit_type() == 0) { | ||
| // TODO: devunit sub_40018D90 | ||
| } | ||
| clock_enable_cl_dvfs(); | ||
| clock_enable_i2c(I2C_1); | ||
| clock_enable_i2c(I2C_5); | ||
| static const clock_t clock_unk1 = { 0x358, 0x360, 0x42C, 0x1F, 0, 0 }; | ||
| static const clock_t clock_unk2 = { 0x358, 0x360, 0, 0x1E, 0, 0 }; | ||
| clock_enable(&clock_unk1); | ||
| clock_enable(&clock_unk2); | ||
| i2c_init(I2C_1); | ||
| i2c_init(I2C_5); | ||
| i2c_send_byte(I2C_5, 0x3C, MAX77620_REG_CNFGBBC, 0x40); | ||
| i2c_send_byte(I2C_5, 0x3C, MAX77620_REG_ONOFFCNFG1, 0x78); | ||
| i2c_send_byte(I2C_5, 0x3C, MAX77620_REG_FPS_CFG0, 0x38); | ||
| i2c_send_byte(I2C_5, 0x3C, MAX77620_REG_FPS_CFG1, 0x3A); | ||
| i2c_send_byte(I2C_5, 0x3C, MAX77620_REG_FPS_CFG2, 0x38); | ||
| i2c_send_byte(I2C_5, 0x3C, MAX77620_REG_FPS_LDO4, 0xF); | ||
| i2c_send_byte(I2C_5, 0x3C, MAX77620_REG_FPS_LDO8, 0xC7); | ||
| i2c_send_byte(I2C_5, 0x3C, MAX77620_REG_FPS_SD0, 0x4F); | ||
| i2c_send_byte(I2C_5, 0x3C, MAX77620_REG_FPS_SD1, 0x29); | ||
| i2c_send_byte(I2C_5, 0x3C, MAX77620_REG_FPS_SD3, 0x1B); | ||
| i2c_send_byte(I2C_5, 0x3C, MAX77620_REG_SD0, 42); //42 = (1125000 - 600000) / 12500 -> 1.125V | ||
| config_pmc_scratch(); | ||
| CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) = CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) & 0xFFFF8888 | 0x3333; | ||
| mc_config_carveout(); | ||
| sdram_init(); | ||
| sdram_lp0_save_params(sdram_get_params()); | ||
| } | ||
| void bootloader() { | ||
| mbist_workaround(); | ||
| clock_enable_se(); | ||
| // This makes fuse registers visible | ||
| clock_enable_fuse(0x01); | ||
| check_sku(); | ||
| // Check configuration fuses | ||
| check_config_fuses(); | ||
| // Disables fuse programming until next reboot | ||
| FUSE(FUSE_PRIVATEKEYDISABLE) = 0x10; | ||
| // Setup memory controllers | ||
| mc_enable(); | ||
| // Pre-Firmware setup | ||
| setup(); | ||
| } |
| @@ -0,0 +1,19 @@ | ||
| /* | ||
| * Copyright (c) 2018 Reisyukaku | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify it | ||
| * under the terms and conditions of the GNU General Public License, | ||
| * version 2, as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope 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/>. | ||
| */ | ||
| #pragma once | ||
| void bootloader(); |
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Copyright (c) 2018 Reisyukaku | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify it | ||
| * under the terms and conditions of the GNU General Public License, | ||
| * version 2, as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope 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 "hwinit.h" | ||
| #include "bootrom.h" | ||
| void bootrom(void) { | ||
| // Bootrom part we skipped. | ||
| u32 sbk[4] = { FUSE(0x1A4), FUSE(0x1A8), FUSE(0x1AC), FUSE(0x1B0) }; | ||
| se_aes_key_set(14, sbk, 0x10); | ||
| // Lock SBK from being read. | ||
| SE(SE_KEY_TABLE_ACCESS_REG_OFFSET + 14 * 4) = 0x7E; | ||
| // This memset needs to happen here, else TZRAM will behave weirdly later on. | ||
| memset((void *)0x7C010000, 0, 0x10000); | ||
| PMC(APBDEV_PMC_CRYPTO_OP) = 0; | ||
| SE(SE_INT_STATUS_REG_OFFSET) = 0x1F; | ||
| // Lock SSK (although it's not set and unused anyways). | ||
| SE(SE_KEY_TABLE_ACCESS_REG_OFFSET + 15 * 4) = 0x7E; | ||
| // 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; | ||
| } |
Oops, something went wrong.
0 comments on commit
9625fd1