├── bdk ├── libs │ ├── lvgl │ │ ├── docs │ │ │ ├── astyle_h │ │ │ └── astyle_c │ │ ├── lv_hal │ │ │ ├── lv_hal.mk │ │ │ ├── lv_hal.h │ │ │ ├── lv_hal_tick.h │ │ │ └── lv_hal_tick.c │ │ ├── lv_themes │ │ │ ├── lv_themes.mk │ │ │ └── lv_theme_hekate.h │ │ ├── lv_core │ │ │ ├── lv_core.mk │ │ │ ├── lv_lang.h │ │ │ └── lv_refr.h │ │ ├── lvgl.mk │ │ ├── lv_draw │ │ │ ├── lv_draw.mk │ │ │ ├── lv_draw_rect.h │ │ │ ├── lv_draw_triangle.h │ │ │ ├── lv_draw_line.h │ │ │ ├── lv_draw_label.h │ │ │ ├── lv_draw_arc.h │ │ │ └── lv_draw_vbasic.h │ │ ├── lv_fonts │ │ │ ├── lv_fonts.mk │ │ │ ├── lv_font_builtin.h │ │ │ ├── hekate_symbol_120.c │ │ │ └── lv_font_builtin.c │ │ ├── lv_misc │ │ │ ├── lv_misc.mk │ │ │ ├── lv_templ.h │ │ │ ├── lv_templ.c │ │ │ ├── lv_gc.c │ │ │ ├── lv_gc.h │ │ │ ├── lv_circ.c │ │ │ ├── lv_circ.h │ │ │ ├── lv_math.h │ │ │ ├── lv_log.c │ │ │ └── lv_log.h │ │ ├── lv_objx │ │ │ ├── lv_objx.mk │ │ │ ├── lv_led.h │ │ │ └── lv_objx_templ.h │ │ ├── licence.txt │ │ ├── lv_version.h │ │ └── lvgl.h │ ├── nx_savedata │ │ ├── fs_int64.h │ │ ├── directory_entry.h │ │ ├── path_parser.h │ │ ├── save_fs_entry.h │ │ ├── allocation_table_iterator.h │ │ ├── hierarchical_duplex_storage.h │ │ ├── integrity_verification_storage.h │ │ ├── save_data_directory.h │ │ ├── allocation_table_storage.h │ │ ├── journal_map.c │ │ ├── save_data_file.h │ │ ├── cached_storage.h │ │ ├── journal_storage.h │ │ └── journal_map.h │ └── compr │ │ ├── blz.h │ │ └── lz.h ├── gfx_utils.h ├── fatfs_cfg.h ├── utils │ ├── dirlist.h │ ├── sprintf.h │ ├── btn.h │ ├── ini.h │ ├── aarch64_util.h │ ├── list.h │ ├── util.h │ └── dirlist.c ├── soc │ ├── ccplex.h │ ├── hw_init.h │ ├── pinmux.c │ ├── kfuse.h │ ├── kfuse.c │ ├── i2c.h │ ├── bpmp.h │ └── gpio.h ├── mem │ ├── mc.h │ ├── heap.h │ └── minerva.h ├── storage │ ├── ramdisk.h │ ├── nx_sd.h │ ├── mbr_gpt.h │ └── ramdisk.c ├── thermal │ ├── fan.h │ ├── tmp451.h │ └── tmp451.c ├── power │ ├── regulator_5v.h │ └── bm92t36.h ├── ianos │ ├── ianos.h │ └── elfload │ │ ├── elfarch.h │ │ ├── elfreloc_arm.c │ │ └── elfreloc_aarch64.c ├── sec │ ├── tsec.h │ ├── tsec_t210.h │ └── se.h ├── module.h ├── input │ ├── als.h │ └── joycon.h └── rtc │ └── max77620-rtc.h ├── keygen └── tsec_keygen ├── docker-compose.yml ├── Versions.inc ├── .gitignore ├── loader ├── link.ld ├── start.S └── Makefile ├── source ├── link.ld ├── frontend │ ├── gui.h │ └── gui.c ├── keys │ ├── gmac.h │ ├── cal0_read.h │ ├── keys.h │ ├── es_types.h │ ├── ssl_crypto.h │ ├── es_crypto.h │ └── nfc_crypto.c ├── config.h ├── libs │ └── fatfs │ │ └── ffsystem.c ├── config.c ├── hos │ └── hos.h ├── storage │ ├── emummc.h │ └── nx_emmc.h ├── start.S └── gfx │ ├── tui.h │ └── gfx.h ├── tools ├── bin2c │ ├── Makefile │ └── bin2c.c ├── lz │ ├── Makefile │ ├── lz.h │ └── lz77.c ├── fix_regs.py └── smmu_payload.py └── Dockerfile /bdk/libs/lvgl/docs/astyle_h: -------------------------------------------------------------------------------- 1 | --convert-tabs --indent=spaces=4 2 | -------------------------------------------------------------------------------- /keygen/tsec_keygen: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kofysh/Lockpick_RCM/HEAD/keygen/tsec_keygen -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | lockpick: 3 | build: 4 | context: . 5 | volumes: 6 | - .:/workspace 7 | -------------------------------------------------------------------------------- /Versions.inc: -------------------------------------------------------------------------------- 1 | # LP Version. 2 | LPVERSION_MAJOR := 1 3 | LPVERSION_MINOR := 9 4 | LPVERSION_BUGFX := 11 5 | LPVERSION_RSVD := 0 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vs 2 | .vscode 3 | build/* 4 | output/* 5 | research/* 6 | loader/payload_00.h 7 | loader/payload_01.h 8 | tools/bin2c/bin2c 9 | keygen/tsec_keygen.h 10 | tools/lz/lz77 11 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/docs/astyle_c: -------------------------------------------------------------------------------- 1 | --style=kr --convert-tabs --indent=spaces=4 --indent-switches --pad-oper --unpad-paren --align-pointer=middle --suffix=.bak --lineend=linux --min-conditional-indent= 2 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_hal/lv_hal.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_hal_disp.c 2 | CSRCS += lv_hal_indev.c 3 | CSRCS += lv_hal_tick.c 4 | 5 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_hal 6 | VPATH += :$(LVGL_DIR)/lvgl/lv_hal 7 | 8 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_hal" 9 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_themes/lv_themes.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_theme.c 2 | CSRCS += lv_theme_default.c 3 | CSRCS += lv_theme_templ.c 4 | CSRCS += lv_theme_material.c 5 | 6 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_themes 7 | VPATH += :$(LVGL_DIR)/lvgl/lv_themes 8 | 9 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_themes" 10 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_core/lv_core.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_group.c 2 | CSRCS += lv_indev.c 3 | CSRCS += lv_obj.c 4 | CSRCS += lv_refr.c 5 | CSRCS += lv_style.c 6 | CSRCS += lv_vdb.c 7 | CSRCS += lv_lang.c 8 | 9 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_core 10 | VPATH += :$(LVGL_DIR)/lvgl/lv_core 11 | 12 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_core" 13 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lvgl.mk: -------------------------------------------------------------------------------- 1 | include $(LVGL_DIR)/lvgl/lv_core/lv_core.mk 2 | include $(LVGL_DIR)/lvgl/lv_hal/lv_hal.mk 3 | include $(LVGL_DIR)/lvgl/lv_objx/lv_objx.mk 4 | include $(LVGL_DIR)/lvgl/lv_fonts/lv_fonts.mk 5 | include $(LVGL_DIR)/lvgl/lv_misc/lv_misc.mk 6 | include $(LVGL_DIR)/lvgl/lv_themes/lv_themes.mk 7 | include $(LVGL_DIR)/lvgl/lv_draw/lv_draw.mk 8 | 9 | -------------------------------------------------------------------------------- /loader/link.ld: -------------------------------------------------------------------------------- 1 | ENTRY(_start) 2 | 3 | SECTIONS { 4 | PROVIDE(__ipl_start = LDR_LOAD_ADDR); 5 | . = __ipl_start; 6 | .text : { 7 | *(.text._start); 8 | KEEP(*(._boot_cfg)); 9 | KEEP(*(._ipl_version)); 10 | *(.text*); 11 | } 12 | .data : { 13 | *(.data*); 14 | *(.rodata*); 15 | *(._payload_00); 16 | *(._payload_01); 17 | } 18 | __ldr_end = .; 19 | . = ALIGN(0x10); 20 | __ipl_end = .; 21 | } 22 | -------------------------------------------------------------------------------- /source/link.ld: -------------------------------------------------------------------------------- 1 | ENTRY(_start) 2 | 3 | SECTIONS { 4 | PROVIDE(__ipl_start = LDR_LOAD_ADDR); 5 | . = __ipl_start; 6 | .text : { 7 | *(.text._start); 8 | KEEP(*(._boot_cfg)); 9 | KEEP(*(._ipl_version)); 10 | *(.text*); 11 | } 12 | .data : { 13 | *(.data*); 14 | *(.rodata*); 15 | *(._payload_00); 16 | *(._payload_01); 17 | } 18 | __ldr_end = .; 19 | . = ALIGN(0x10); 20 | __ipl_end = .; 21 | } 22 | -------------------------------------------------------------------------------- /tools/bin2c/Makefile: -------------------------------------------------------------------------------- 1 | NATIVE_CC ?= gcc 2 | 3 | ifeq (, $(shell which $(NATIVE_CC) 2>/dev/null)) 4 | $(error "Native GCC is missing. Please install it first. If it's path is custom, set it with export NATIVE_CC=") 5 | endif 6 | 7 | .PHONY: all clean 8 | 9 | all: bin2c 10 | @echo > /dev/null 11 | 12 | clean: 13 | @rm -f bin2c 14 | 15 | bin2c: bin2c.c 16 | @$(NATIVE_CC) -o $@ bin2c.c 17 | -------------------------------------------------------------------------------- /tools/lz/Makefile: -------------------------------------------------------------------------------- 1 | NATIVE_CC ?= gcc 2 | 3 | ifeq (, $(shell which $(NATIVE_CC) 2>/dev/null)) 4 | $(error "Native GCC is missing. Please install it first. If it's path is custom, set it with export NATIVE_CC=") 5 | endif 6 | 7 | .PHONY: all clean 8 | 9 | all: lz77 10 | @echo > /dev/null 11 | 12 | clean: 13 | @rm -f lz77 14 | 15 | lz77: lz.c lz77.c 16 | @$(NATIVE_CC) -o $@ lz.c lz77.c 17 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_draw_vbasic.c 2 | CSRCS += lv_draw_rbasic.c 3 | CSRCS += lv_draw.c 4 | CSRCS += lv_draw_rect.c 5 | CSRCS += lv_draw_label.c 6 | CSRCS += lv_draw_line.c 7 | CSRCS += lv_draw_img.c 8 | CSRCS += lv_draw_arc.c 9 | CSRCS += lv_draw_triangle.c 10 | 11 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_draw 12 | VPATH += :$(LVGL_DIR)/lvgl/lv_draw 13 | 14 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_draw" 15 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_fonts/lv_fonts.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_font_builtin.c 2 | CSRCS += hekate_symbol_10.c 3 | CSRCS += hekate_symbol_20.c 4 | CSRCS += hekate_symbol_30.c 5 | CSRCS += hekate_symbol_40.c 6 | CSRCS += interui_12.c 7 | CSRCS += interui_20.c 8 | CSRCS += interui_30.c 9 | CSRCS += interui_40.c 10 | 11 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_fonts 12 | VPATH += :$(LVGL_DIR)/lvgl/lv_fonts 13 | 14 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_fonts" 15 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | FROM devkitpro/devkitarm:latest AS root 3 | 4 | # Use Bash (explicitly) as the default shell. 5 | SHELL ["/bin/bash", "-euxo", "pipefail", "-c"] 6 | 7 | # Obviously, please keep these package names alphabetized. 8 | RUN apt-get -y update && apt-get -y upgrade && \ 9 | apt-get -y install \ 10 | gcc \ 11 | ; 12 | 13 | # Compile source code. 14 | WORKDIR /workspace 15 | 16 | ENTRYPOINT ["make"] 17 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_misc.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_font.c 2 | CSRCS += lv_circ.c 3 | CSRCS += lv_area.c 4 | CSRCS += lv_task.c 5 | CSRCS += lv_fs.c 6 | CSRCS += lv_anim.c 7 | CSRCS += lv_mem.c 8 | CSRCS += lv_ll.c 9 | CSRCS += lv_color.c 10 | CSRCS += lv_txt.c 11 | CSRCS += lv_ufs.c 12 | CSRCS += lv_math.c 13 | CSRCS += lv_log.c 14 | CSRCS += lv_gc.c 15 | 16 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_misc 17 | VPATH += :$(LVGL_DIR)/lvgl/lv_misc 18 | 19 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_misc" 20 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_templ.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_templ.h 3 | * 4 | */ 5 | 6 | #ifndef LV_TEMPL_H 7 | #define LV_TEMPL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | /********************* 18 | * DEFINES 19 | *********************/ 20 | 21 | /********************** 22 | * TYPEDEFS 23 | **********************/ 24 | 25 | /********************** 26 | * GLOBAL PROTOTYPES 27 | **********************/ 28 | 29 | /********************** 30 | * MACROS 31 | **********************/ 32 | 33 | 34 | #ifdef __cplusplus 35 | } /* extern "C" */ 36 | #endif 37 | 38 | #endif /*LV_TEMPL_H*/ 39 | -------------------------------------------------------------------------------- /source/frontend/gui.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2021 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | int save_fb_to_bmp(); 18 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_hal/lv_hal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file hal.h 3 | * 4 | */ 5 | 6 | #ifndef HAL_H 7 | #define HAL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_hal_disp.h" 17 | #include "lv_hal_indev.h" 18 | #include "lv_hal_tick.h" 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | 28 | /********************** 29 | * GLOBAL PROTOTYPES 30 | **********************/ 31 | 32 | /********************** 33 | * MACROS 34 | **********************/ 35 | 36 | #ifdef __cplusplus 37 | } /* extern "C" */ 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_templ.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_templ.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | 10 | /********************* 11 | * DEFINES 12 | *********************/ 13 | 14 | /********************** 15 | * TYPEDEFS 16 | **********************/ 17 | 18 | /********************** 19 | * STATIC PROTOTYPES 20 | **********************/ 21 | 22 | /********************** 23 | * STATIC VARIABLES 24 | **********************/ 25 | 26 | /********************** 27 | * MACROS 28 | **********************/ 29 | 30 | /********************** 31 | * GLOBAL FUNCTIONS 32 | **********************/ 33 | 34 | /********************** 35 | * STATIC FUNCTIONS 36 | **********************/ 37 | -------------------------------------------------------------------------------- /bdk/gfx_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _GFX_UTILS_H_ 18 | #define _GFX_UTILS_H_ 19 | 20 | #ifdef GFX_INC 21 | #include GFX_INC 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /bdk/fatfs_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _FATFS_CFG_H_ 18 | #define _FATFS_CFG_H_ 19 | 20 | #ifdef FFCFG_INC 21 | #include FFCFG_INC 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /bdk/utils/dirlist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include 18 | 19 | char *dirlist(const char *directory, const char *pattern, bool includeHiddenFiles, bool parse_dirs); 20 | -------------------------------------------------------------------------------- /bdk/soc/ccplex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _CCPLEX_H_ 18 | #define _CCPLEX_H_ 19 | 20 | #include 21 | 22 | void ccplex_boot_cpu0(u32 entry); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /tools/fix_regs.py: -------------------------------------------------------------------------------- 1 | import re 2 | import sys 3 | 4 | def parse_defs(fname): 5 | f = open(fname, "r") 6 | lines = f.readlines() 7 | f.close() 8 | res = {} 9 | for l in lines: 10 | p = [str(_.strip()) for _ in l.strip().split(" ", 1)] 11 | res[int(p[1], 16)] = p[0] 12 | return res 13 | 14 | mc = parse_defs("mc.def") 15 | emc = parse_defs("emc.def") 16 | 17 | f = open(sys.argv[1], "r") 18 | buf = f.read() 19 | f.close() 20 | 21 | def fix(m): 22 | what = m.groups()[0] 23 | off = int(m.groups()[1], 16) 24 | if what == "MC": 25 | if off in mc: 26 | return "MC({0})".format(mc[off]) 27 | elif what == "EMC": 28 | if off in emc: 29 | return "EMC({0})".format(emc[off]) 30 | return "{0}(0x{1:X})".format(what, off) 31 | 32 | buf = re.sub(r'([A-Z]+)\(0x([0-9a-fA-F]+)\)', fix, buf) 33 | 34 | f = open(sys.argv[2], "w") 35 | f.write(buf) 36 | f.close() 37 | -------------------------------------------------------------------------------- /bdk/utils/sprintf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _SPRINTF_H_ 18 | #define _SPRINTF_H_ 19 | 20 | #include "types.h" 21 | 22 | u32 s_printf(char *buffer, const char *fmt, ...); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_gc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_gc.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | 10 | #include "lv_gc.h" 11 | 12 | /********************* 13 | * DEFINES 14 | *********************/ 15 | 16 | /********************** 17 | * TYPEDEFS 18 | **********************/ 19 | 20 | /********************** 21 | * STATIC PROTOTYPES 22 | **********************/ 23 | 24 | /********************** 25 | * STATIC VARIABLES 26 | **********************/ 27 | #if (!defined(LV_ENABLE_GC)) || LV_ENABLE_GC == 0 28 | LV_ROOTS 29 | #endif /* LV_ENABLE_GC */ 30 | /********************** 31 | * MACROS 32 | **********************/ 33 | 34 | /********************** 35 | * GLOBAL FUNCTIONS 36 | **********************/ 37 | 38 | /********************** 39 | * STATIC FUNCTIONS 40 | **********************/ 41 | -------------------------------------------------------------------------------- /source/keys/gmac.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _GMAC_H_ 18 | #define _GMAC_H_ 19 | 20 | #include 21 | 22 | void calc_gmac(u32 ks, void *out_gmac, const void *data, u32 size, const void *key, const void *iv); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_objx/lv_objx.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_arc.c 2 | CSRCS += lv_bar.c 3 | CSRCS += lv_cb.c 4 | CSRCS += lv_ddlist.c 5 | CSRCS += lv_kb.c 6 | CSRCS += lv_line.c 7 | CSRCS += lv_mbox.c 8 | CSRCS += lv_preload.c 9 | CSRCS += lv_roller.c 10 | CSRCS += lv_table.c 11 | CSRCS += lv_tabview.c 12 | CSRCS += lv_tileview.c 13 | CSRCS += lv_btn.c 14 | CSRCS += lv_calendar.c 15 | CSRCS += lv_chart.c 16 | CSRCS += lv_canvas.c 17 | CSRCS += lv_gauge.c 18 | CSRCS += lv_label.c 19 | CSRCS += lv_list.c 20 | CSRCS += lv_slider.c 21 | CSRCS += lv_ta.c 22 | CSRCS += lv_spinbox.c 23 | CSRCS += lv_btnm.c 24 | CSRCS += lv_cont.c 25 | CSRCS += lv_img.c 26 | CSRCS += lv_imgbtn.c 27 | CSRCS += lv_led.c 28 | CSRCS += lv_lmeter.c 29 | CSRCS += lv_page.c 30 | CSRCS += lv_sw.c 31 | CSRCS += lv_win.c 32 | 33 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_objx 34 | VPATH += :$(LVGL_DIR)/lvgl/lv_objx 35 | 36 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_objx" 37 | -------------------------------------------------------------------------------- /bdk/mem/mc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _MC_H_ 18 | #define _MC_H_ 19 | 20 | #include 21 | #include 22 | 23 | void mc_config_tsec_carveout(u32 bom, u32 size1mb, bool lock); 24 | void mc_config_carveout(); 25 | void mc_config_carveout_finalize(); 26 | void mc_enable_ahb_redirect(bool full_aperture); 27 | void mc_disable_ahb_redirect(); 28 | void mc_enable(); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /bdk/storage/ramdisk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ramdisk driver for Tegra X1 3 | * 4 | * Copyright (c) 2019-2021 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef RAM_DISK_H 20 | #define RAM_DISK_H 21 | 22 | #include 23 | 24 | #define RAMDISK_CLUSTER_SZ 32768 25 | 26 | int ram_disk_init(FATFS *ram_fs, u32 ramdisk_size); 27 | int ram_disk_read(u32 sector, u32 sector_count, void *buf); 28 | int ram_disk_write(u32 sector, u32 sector_count, const void *buf); 29 | 30 | #endif -------------------------------------------------------------------------------- /bdk/thermal/fan.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Fan driver for Nintendo Switch 3 | * 4 | * Copyright (c) 2018 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __FAN_H_ 20 | #define __FAN_H_ 21 | 22 | #include 23 | 24 | // Disable: 0 (0 RPM), min duty: 1 (960 RPM), max duty 235 (11000 RPM). 25 | void set_fan_duty(u32 duty); 26 | // Passing NULL ptr on either of the two, disables parsing of it. 27 | void get_fan_speed(u32 *duty, u32 *rpm); 28 | 29 | #endif /* __FAN_H_ */ 30 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/licence.txt: -------------------------------------------------------------------------------- 1 | MIT licence 2 | Copyright (c) 2016 Gábor Kiss-Vámosi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /bdk/utils/btn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _BTN_H_ 19 | #define _BTN_H_ 20 | 21 | #include 22 | 23 | #define BTN_POWER BIT(0) 24 | #define BTN_VOL_DOWN BIT(1) 25 | #define BTN_VOL_UP BIT(2) 26 | #define BTN_SINGLE BIT(7) 27 | 28 | u8 btn_read(); 29 | u8 btn_read_vol(); 30 | u8 btn_wait(); 31 | u8 btn_wait_timeout(u32 time_ms, u8 mask); 32 | u8 btn_wait_timeout_single(u32 time_ms, u8 mask); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw_rect.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_rect.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_RECT_H 7 | #define LV_DRAW_RECT_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_draw.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * GLOBAL PROTOTYPES 28 | **********************/ 29 | 30 | /** 31 | * Draw a rectangle 32 | * @param coords the coordinates of the rectangle 33 | * @param mask the rectangle will be drawn only in this mask 34 | * @param style pointer to a style 35 | * @param opa_scale scale down all opacities by the factor 36 | */ 37 | void lv_draw_rect(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); 38 | 39 | /********************** 40 | * MACROS 41 | **********************/ 42 | 43 | 44 | #ifdef __cplusplus 45 | } /* extern "C" */ 46 | #endif 47 | 48 | #endif /*LV_DRAW_RECT_H*/ 49 | -------------------------------------------------------------------------------- /bdk/power/regulator_5v.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _REGULATOR_5V_H_ 18 | #define _REGULATOR_5V_H_ 19 | 20 | #include 21 | 22 | enum 23 | { 24 | REGULATOR_5V_FAN = BIT(0), 25 | REGULATOR_5V_JC_R = BIT(1), 26 | REGULATOR_5V_JC_L = BIT(2), 27 | REGULATOR_5V_ALL = 0xFF 28 | }; 29 | 30 | void regulator_5v_enable(u8 dev); 31 | void regulator_5v_disable(u8 dev); 32 | bool regulator_5v_get_dev_enabled(u8 dev); 33 | void regulator_5v_usb_src_enable(bool enable); 34 | 35 | #endif -------------------------------------------------------------------------------- /bdk/soc/hw_init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2021 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _HW_INIT_H_ 19 | #define _HW_INIT_H_ 20 | 21 | #include 22 | 23 | #define BL_MAGIC_CRBOOT_SLD 0x30444C53 // SLD0, seamless display type 0. 24 | #define BL_MAGIC_BROKEN_HWI 0xBAADF00D // Broken hwinit. 25 | 26 | extern u32 hw_rst_status; 27 | extern u32 hw_rst_reason; 28 | 29 | void hw_init(); 30 | void hw_reinit_workaround(bool coreboot, u32 magic); 31 | u32 hw_get_chip_id(); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw_triangle.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_triangle.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_TRIANGLE_H 7 | #define LV_DRAW_TRIANGLE_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_draw.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * GLOBAL PROTOTYPES 28 | **********************/ 29 | /*Experimental use for 3D modeling*/ 30 | #define USE_LV_TRIANGLE 1 31 | 32 | #if USE_LV_TRIANGLE != 0 33 | /** 34 | * 35 | * @param points pointer to an array with 3 points 36 | * @param mask the triangle will be drawn only in this mask 37 | * @param color color of the triangle 38 | */ 39 | void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, lv_color_t color); 40 | #endif 41 | 42 | /********************** 43 | * MACROS 44 | **********************/ 45 | 46 | 47 | #ifdef __cplusplus 48 | } /* extern "C" */ 49 | #endif 50 | 51 | #endif /*LV_DRAW_TRIANGLE_H*/ 52 | -------------------------------------------------------------------------------- /tools/smmu_payload.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (c) 2018 balika011 3 | 4 | This program is free software; you can redistribute it and/or modify it 5 | under the terms and conditions of the GNU General Public License, 6 | version 2, as published by the Free Software Foundation. 7 | 8 | This program is distributed in the hope it will be useful, but WITHOUT 9 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with this program. If not, see . 15 | ''' 16 | 17 | from keystone import * 18 | 19 | CODE = b''' 20 | LDR X1, =0x70019010 21 | MOV X0, #0x1 22 | STR W0, [X1] 23 | 24 | loop: 25 | IC IALLUIS 26 | DSB ISH 27 | B loop 28 | MOV X0, #0x0 29 | STR W0, [X1] 30 | LDR X0, =0x4002B000 31 | BR X0 32 | ''' 33 | try: 34 | ks = Ks(KS_ARCH_ARM64, KS_MODE_LITTLE_ENDIAN) 35 | encoding, count = ks.asm(CODE, 0x0) 36 | print("%s = %s (number of statements: %u)" %(CODE, ', '.join([('0x%02x' % (x)) for x in encoding]), count)) 37 | except KsError as e: 38 | print("ERROR: %s" %e) -------------------------------------------------------------------------------- /bdk/ianos/ianos.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 M4xw 3 | * Copyright (c) 2018 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef IANOS_H 19 | #define IANOS_H 20 | 21 | #include 22 | 23 | typedef enum 24 | { 25 | DRAM_LIB = 0, // DRAM library. 26 | EXEC_ELF = 1, // Executable elf that does not return. 27 | DR64_LIB = 2, // AARCH64 DRAM library. 28 | AR64_ELF = 3, // Executable elf that does not return. 29 | KEEP_IN_RAM = (1 << 31) // Shared library mask. 30 | } elfType_t; 31 | 32 | uintptr_t ianos_loader(char *path, elfType_t type, void* config); 33 | 34 | #endif -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw_line.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_line.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_LINE_H 7 | #define LV_DRAW_LINE_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | /********************* 18 | * DEFINES 19 | *********************/ 20 | 21 | /********************** 22 | * TYPEDEFS 23 | **********************/ 24 | 25 | /********************** 26 | * GLOBAL PROTOTYPES 27 | **********************/ 28 | 29 | /** 30 | * Draw a line 31 | * @param point1 first point of the line 32 | * @param point2 second point of the line 33 | * @param mask the line will be drawn only on this area 34 | * @param style pointer to a line's style 35 | * @param opa_scale scale down all opacities by the factor 36 | */ 37 | void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * mask, 38 | const lv_style_t * style, lv_opa_t opa_scale); 39 | 40 | /********************** 41 | * MACROS 42 | **********************/ 43 | 44 | 45 | #ifdef __cplusplus 46 | } /* extern "C" */ 47 | #endif 48 | 49 | #endif /*LV_DRAW_LINE_H*/ 50 | -------------------------------------------------------------------------------- /source/keys/cal0_read.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _CAL0_READ_H_ 18 | #define _CAL0_READ_H_ 19 | 20 | #include "../storage/nx_emmc_bis.h" 21 | #include 22 | 23 | bool cal0_read(u32 tweak_ks, u32 crypt_ks, void *read_buffer); 24 | bool cal0_get_ssl_rsa_key(const nx_emmc_cal0_t *cal0, const void **out_key, u32 *out_key_size, const void **out_iv, u32 *out_generation); 25 | bool cal0_get_eticket_rsa_key(const nx_emmc_cal0_t *cal0, const void **out_key, u32 *out_key_size, const void **out_iv, u32 *out_generation); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /bdk/power/bm92t36.h: -------------------------------------------------------------------------------- 1 | /* 2 | * USB-PD driver for Nintendo Switch's TI BM92T36 3 | * 4 | * Copyright (c) 2020 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __BM92T36_H_ 20 | #define __BM92T36_H_ 21 | 22 | #include 23 | 24 | #define BM92T36_I2C_ADDR 0x18 25 | 26 | typedef struct _usb_pd_object_t 27 | { 28 | u32 amperage; 29 | u32 voltage; 30 | } usb_pd_object_t; 31 | 32 | typedef struct _usb_pd_objects_t 33 | { 34 | u32 pdo_no; 35 | usb_pd_object_t pdos[7]; 36 | usb_pd_object_t selected_pdo; 37 | } usb_pd_objects_t; 38 | 39 | void bm92t36_get_sink_info(bool *inserted, usb_pd_objects_t *usb_pd); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /bdk/soc/pinmux.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | void pinmux_config_uart(u32 idx) 21 | { 22 | PINMUX_AUX(PINMUX_AUX_UARTX_TX(idx)) = 0; 23 | PINMUX_AUX(PINMUX_AUX_UARTX_RX(idx)) = PINMUX_INPUT_ENABLE | PINMUX_PULL_UP; 24 | PINMUX_AUX(PINMUX_AUX_UARTX_RTS(idx)) = 0; 25 | PINMUX_AUX(PINMUX_AUX_UARTX_CTS(idx)) = PINMUX_INPUT_ENABLE | PINMUX_PULL_DOWN; 26 | } 27 | 28 | void pinmux_config_i2c(u32 idx) 29 | { 30 | PINMUX_AUX(PINMUX_AUX_X_I2C_SCL(idx)) = PINMUX_INPUT_ENABLE; 31 | PINMUX_AUX(PINMUX_AUX_X_I2C_SDA(idx)) = PINMUX_INPUT_ENABLE; 32 | } 33 | -------------------------------------------------------------------------------- /bdk/sec/tsec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2021 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _TSEC_H_ 19 | #define _TSEC_H_ 20 | 21 | #include 22 | 23 | enum tsec_fw_type 24 | { 25 | // Retail Hovi Keygen. 26 | TSEC_FW_TYPE_OLD = 0, // 1.0.0 - 6.1.0. 27 | TSEC_FW_TYPE_EMU = 1, // 6.2.0 emulated enviroment. 28 | TSEC_FW_TYPE_NEW = 2, // 7.0.0+. 29 | }; 30 | 31 | typedef struct _tsec_ctxt_t 32 | { 33 | const void *fw; 34 | u32 size; 35 | u32 type; 36 | void *pkg1; 37 | u32 pkg11_off; 38 | u32 secmon_base; 39 | } tsec_ctxt_t; 40 | 41 | int tsec_query(void *tsec_keys, tsec_ctxt_t *tsec_ctxt); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /bdk/utils/ini.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _INI_H_ 19 | #define _INI_H_ 20 | 21 | #include 22 | #include 23 | 24 | #define INI_CHOICE 3 25 | #define INI_CAPTION 5 26 | #define INI_CHGLINE 6 27 | #define INI_NEWLINE 0xFE 28 | #define INI_COMMENT 0xFF 29 | 30 | typedef struct _ini_kv_t 31 | { 32 | char *key; 33 | char *val; 34 | link_t link; 35 | } ini_kv_t; 36 | 37 | typedef struct _ini_sec_t 38 | { 39 | char *name; 40 | link_t kvs; 41 | link_t link; 42 | u32 type; 43 | u32 color; 44 | } ini_sec_t; 45 | 46 | int ini_parse(link_t *dst, char *ini_path, bool is_dir); 47 | char *ini_check_payload_section(ini_sec_t *cfg); 48 | 49 | #endif 50 | 51 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw_label.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_label.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_LABEL_H 7 | #define LV_DRAW_LABEL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_draw.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * GLOBAL PROTOTYPES 28 | **********************/ 29 | 30 | /** 31 | * Write a text 32 | * @param coords coordinates of the label 33 | * @param mask the label will be drawn only in this area 34 | * @param style pointer to a style 35 | * @param opa_scale scale down all opacities by the factor 36 | * @param txt 0 terminated text to write 37 | * @param flag settings for the text from 'txt_flag_t' enum 38 | * @param offset text offset in x and y direction (NULL if unused) 39 | * 40 | */ 41 | void lv_draw_label(const lv_area_t * coords,const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale, 42 | const char * txt, lv_txt_flag_t flag, lv_point_t * offset); 43 | 44 | /********************** 45 | * MACROS 46 | **********************/ 47 | 48 | 49 | #ifdef __cplusplus 50 | } /* extern "C" */ 51 | #endif 52 | 53 | #endif /*LV_DRAW_LABEL_H*/ 54 | -------------------------------------------------------------------------------- /bdk/soc/kfuse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _KFUSE_H_ 18 | #define _KFUSE_H_ 19 | 20 | #include 21 | 22 | #define KFUSE_STATE_CURBLOCK_MASK 0x3F 23 | #define KFUSE_STATE_ERRBLOCK_SHIFT 8 24 | #define KFUSE_STATE_ERRBLOCK_MASK 0x3F00 25 | #define KFUSE_STATE_DONE BIT(16) 26 | #define KFUSE_STATE_CRCPASS BIT(17) 27 | #define KFUSE_STATE_RESTART BIT(24) 28 | #define KFUSE_STATE_STOP BIT(25) 29 | #define KFUSE_STATE_SOFTRESET BIT(31) 30 | 31 | #define KFUSE_KEYADDR_AUTOINC BIT(16) 32 | 33 | #define KFUSE_STATE 0x80 34 | #define KFUSE_KEYADDR 0x88 35 | #define KFUSE_KEYS 0x8C 36 | 37 | #define KFUSE_NUM_WORDS 144 38 | 39 | int kfuse_wait_ready(); 40 | int kfuse_read(u32 *buf); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /bdk/soc/kfuse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | int kfuse_wait_ready() 22 | { 23 | // Wait for KFUSE to finish init and verification of data. 24 | while (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_DONE)) 25 | ; 26 | 27 | if (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_CRCPASS)) 28 | return 0; 29 | 30 | return 1; 31 | } 32 | 33 | int kfuse_read(u32 *buf) 34 | { 35 | int res = 0; 36 | 37 | clock_enable_kfuse(); 38 | 39 | if (!kfuse_wait_ready()) 40 | goto out; 41 | 42 | KFUSE(KFUSE_KEYADDR) = KFUSE_KEYADDR_AUTOINC; 43 | for (int i = 0; i < KFUSE_NUM_WORDS; i++) 44 | buf[i] = KFUSE(KFUSE_KEYS); 45 | 46 | res = 1; 47 | 48 | out: 49 | clock_disable_kfuse(); 50 | return res; 51 | } 52 | -------------------------------------------------------------------------------- /bdk/mem/heap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2020 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _HEAP_H_ 19 | #define _HEAP_H_ 20 | 21 | #include 22 | 23 | typedef struct _hnode 24 | { 25 | int used; 26 | u32 size; 27 | struct _hnode *prev; 28 | struct _hnode *next; 29 | u32 align[4]; // Align to arch cache line size. 30 | } hnode_t; 31 | 32 | typedef struct _heap 33 | { 34 | u32 start; 35 | hnode_t *first; 36 | } heap_t; 37 | 38 | typedef struct 39 | { 40 | u32 total; 41 | u32 used; 42 | } heap_monitor_t; 43 | 44 | void heap_init(u32 base); 45 | void heap_copy(heap_t *heap); 46 | void *malloc(u32 size); 47 | void *calloc(u32 num, u32 size); 48 | void free(void *buf); 49 | void heap_monitor(heap_monitor_t *mon, bool print_node_stats); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /bdk/libs/nx_savedata/fs_int64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Atmosphère-NX 3 | * Copyright (c) 2020 shchmue 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _FS_INT64_H_ 19 | #define _FS_INT64_H_ 20 | 21 | #include 22 | 23 | #include 24 | 25 | /* For 64-bit integers which are 4-byte aligned but not 8-byte aligned. */ 26 | typedef struct { 27 | uint32_t low; 28 | uint32_t high; 29 | } fs_int64_t; 30 | 31 | static ALWAYS_INLINE void fs_int64_set(fs_int64_t *i, int64_t val) { 32 | i->low = (uint32_t)((val & (uint64_t)(0x00000000FFFFFFFFul)) >> 0); 33 | i->high = (uint32_t)((val & (uint64_t)(0xFFFFFFFF00000000ul)) >> 32); 34 | } 35 | 36 | static ALWAYS_INLINE const int64_t fs_int64_get(fs_int64_t *i) { 37 | return ((int64_t)(i->high) << 32) | ((int64_t)i->low); 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /bdk/module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Common Module Header 3 | * Copyright (c) 2018 M4xw 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _MODULE_H_ 19 | #define _MODULE_H_ 20 | 21 | #include 22 | #include 23 | 24 | #define IANOS_EXT0 0x304E4149 25 | 26 | // Module Callback 27 | typedef void (*cbMainModule_t)(const char *s); 28 | typedef void (*memcpy_t)(void *, void *, size_t); 29 | typedef void (*memset_t)(void *, int, size_t); 30 | typedef int (*reg_voltage_set_t)(u32, u32); 31 | 32 | typedef struct _bdkParams_t 33 | { 34 | void *gfxCon; 35 | void *gfxCtx; 36 | heap_t *sharedHeap; 37 | memcpy_t memcpy; 38 | memset_t memset; 39 | u32 extension_magic; 40 | reg_voltage_set_t reg_voltage_set; 41 | } *bdkParams_t; 42 | 43 | // Module Entrypoint 44 | typedef void (*moduleEntrypoint_t)(void *, bdkParams_t); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /bdk/libs/compr/blz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 rajkosto 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _BLZ_H_ 18 | #define _BLZ_H_ 19 | 20 | #include 21 | 22 | typedef struct _blz_footer 23 | { 24 | u32 cmp_and_hdr_size; 25 | u32 header_size; 26 | u32 addl_size; 27 | } blz_footer; 28 | 29 | // Returns pointer to footer in compData if present, additionally copies it to outFooter if not NULL. 30 | const blz_footer *blz_get_footer(const unsigned char *compData, unsigned int compDataLen, blz_footer *outFooter); 31 | // Returns 0 on failure. 32 | int blz_uncompress_inplace(unsigned char *dataBuf, unsigned int compSize, const blz_footer *footer); 33 | // Returns 0 on failure. 34 | int blz_uncompress_srcdest(const unsigned char *compData, unsigned int compDataLen, unsigned char *dstData, unsigned int dstSize); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /source/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2019 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _CONFIG_H_ 18 | #define _CONFIG_H_ 19 | 20 | #include 21 | 22 | typedef struct _hekate_config 23 | { 24 | // Non-volatile config. 25 | u32 autoboot; 26 | u32 autoboot_list; 27 | u32 bootwait; 28 | u32 backlight; 29 | u32 autohosoff; 30 | u32 autonogc; 31 | u32 updater2p; 32 | u32 bootprotect; 33 | // Global temporary config. 34 | bool t210b01; 35 | bool aes_slots_new; 36 | bool emummc_force_disable; 37 | bool rcm_patched; 38 | u32 errors; 39 | } hekate_config; 40 | 41 | void set_default_configuration(); 42 | int create_config_entry(); 43 | void config_autoboot(); 44 | void config_bootdelay(); 45 | void config_backlight(); 46 | void config_auto_hos_poweroff(); 47 | void config_nogc(); 48 | 49 | #endif /* _CONFIG_H_ */ 50 | -------------------------------------------------------------------------------- /bdk/soc/i2c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2020 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _I2C_H_ 19 | #define _I2C_H_ 20 | 21 | #include 22 | 23 | #define I2C_1 0 24 | #define I2C_2 1 25 | #define I2C_3 2 26 | #define I2C_4 3 27 | #define I2C_5 4 28 | #define I2C_6 5 29 | 30 | void i2c_init(u32 i2c_idx); 31 | int i2c_recv_buf(u8 *buf, u32 size, u32 i2c_idx, u32 dev_addr); 32 | int i2c_send_buf_big(u32 i2c_idx, u32 dev_addr, u8 *buf, u32 size); 33 | int i2c_recv_buf_big(u8 *buf, u32 size, u32 i2c_idx, u32 dev_addr, u32 reg); 34 | int i2c_send_buf_small(u32 i2c_idx, u32 dev_addr, u32 reg, u8 *buf, u32 size); 35 | int i2c_recv_buf_small(u8 *buf, u32 size, u32 i2c_idx, u32 dev_addr, u32 reg); 36 | int i2c_send_byte(u32 i2c_idx, u32 dev_addr, u32 reg, u8 val); 37 | u8 i2c_recv_byte(u32 i2c_idx, u32 dev_addr, u32 reg); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_version.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_version.h 3 | * 4 | */ 5 | 6 | #ifndef LV_VERSION_H 7 | #define LV_VERSION_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | /*Current version of LittlevGL*/ 17 | #define LVGL_VERSION_MAJOR 5 18 | #define LVGL_VERSION_MINOR 3 19 | #define LVGL_VERSION_PATCH 0 20 | #define LVGL_VERSION_INFO "hekate" 21 | 22 | 23 | /********************* 24 | * DEFINES 25 | *********************/ 26 | 27 | /********************** 28 | * TYPEDEFS 29 | **********************/ 30 | 31 | /********************** 32 | * GLOBAL PROTOTYPES 33 | **********************/ 34 | 35 | /********************** 36 | * MACROS 37 | **********************/ 38 | /* Gives 1 if the x.y.z version is supported in the current version 39 | * Usage: 40 | * 41 | * - Require v6 42 | * #if LV_VERSION_CHECK(6,0,0) 43 | * new_func_in_v6(); 44 | * #endif 45 | * 46 | * 47 | * - Require at least v5.3 48 | * #if LV_VERSION_CHECK(5,3,0) 49 | * new_feature_from_v5_3(); 50 | * #endif 51 | * 52 | * 53 | * - Require v5.3.2 bugfixes 54 | * #if LV_VERSION_CHECK(5,3,2) 55 | * bugfix_in_v5_3_2(); 56 | * #endif 57 | * 58 | * */ 59 | #define LV_VERSION_CHECK(x,y,z) (x == LVGL_VERSION_MAJOR && (y < LVGL_VERSION_MINOR || (y == LVGL_VERSION_MINOR && z <= LVGL_VERSION_PATCH))) 60 | 61 | 62 | #ifdef __cplusplus 63 | } /* extern "C" */ 64 | #endif 65 | 66 | #endif /*LV_VERSION_H*/ 67 | -------------------------------------------------------------------------------- /source/libs/fatfs/ffsystem.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------*/ 2 | /* Sample Code of OS Dependent Functions for FatFs */ 3 | /* (C) ChaN, 2018 */ 4 | /* (C) CTCaer, 2018 */ 5 | /*------------------------------------------------------------------------*/ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | 13 | #if FF_USE_LFN == 3 /* Dynamic memory allocation */ 14 | 15 | /*------------------------------------------------------------------------*/ 16 | /* Allocate a memory block */ 17 | /*------------------------------------------------------------------------*/ 18 | 19 | void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */ 20 | UINT msize /* Number of bytes to allocate */ 21 | ) 22 | { 23 | return malloc(msize); /* Allocate a new memory block with POSIX API */ 24 | } 25 | 26 | 27 | /*------------------------------------------------------------------------*/ 28 | /* Free a memory block */ 29 | /*------------------------------------------------------------------------*/ 30 | 31 | void ff_memfree ( 32 | void* mblock /* Pointer to the memory block to free (nothing to do if null) */ 33 | ) 34 | { 35 | free(mblock); /* Free the memory block with POSIX API */ 36 | } 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /bdk/utils/aarch64_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2019 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _ARM64_H_ 19 | #define _ARM64_H_ 20 | 21 | #include 22 | 23 | #define LSL0 0 24 | #define LSL16 16 25 | #define LSL32 32 26 | 27 | #define _PAGEOFF(x) ((x) & 0xFFFFF000) 28 | 29 | #define _ADRP(r, o) (0x90000000 | ((((o) >> 12) & 0x3) << 29) | ((((o) >> 12) & 0x1FFFFC) << 3) | ((r) & 0x1F)) 30 | #define _BL(a, o) (0x94000000 | ((((o) - (a)) >> 2) & 0x3FFFFFF)) 31 | #define _B(a, o) (0x14000000 | ((((o) - (a)) >> 2) & 0x3FFFFFF)) 32 | #define _MOVKX(r, i, s) (0xF2800000 | (((s) & 0x30) << 17) | (((i) & 0xFFFF) << 5) | ((r) & 0x1F)) 33 | #define _MOVZX(r, i, s) (0xD2800000 | (((s) & 0x30) << 17) | (((i) & 0xFFFF) << 5) | ((r) & 0x1F)) 34 | #define _MOVZW(r, i, s) (0x52800000 | (((s) & 0x30) << 17) | (((i) & 0xFFFF) << 5) | ((r) & 0x1F)) 35 | #define _NOP() 0xD503201F 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw_arc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_arc.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_ARC_H 7 | #define LV_DRAW_ARC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_draw.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * GLOBAL PROTOTYPES 28 | **********************/ 29 | 30 | /** 31 | * Draw an arc. (Can draw pie too with great thickness.) 32 | * @param center_x the x coordinate of the center of the arc 33 | * @param center_y the y coordinate of the center of the arc 34 | * @param radius the radius of the arc 35 | * @param mask the arc will be drawn only in this mask 36 | * @param start_angle the start angle of the arc (0 deg on the bottom, 90 deg on the right) 37 | * @param end_angle the end angle of the arc 38 | * @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used) 39 | * @param opa_scale scale down all opacities by the factor 40 | */ 41 | void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, const lv_area_t * mask, 42 | uint16_t start_angle, uint16_t end_angle, const lv_style_t * style, lv_opa_t opa_scale); 43 | 44 | /********************** 45 | * MACROS 46 | **********************/ 47 | 48 | 49 | #ifdef __cplusplus 50 | } /* extern "C" */ 51 | #endif 52 | 53 | #endif /*LV_DRAW_ARC*/ 54 | -------------------------------------------------------------------------------- /bdk/ianos/elfload/elfarch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014, Owen Shepherd 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 | * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | * PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef ELFARCH_H 18 | #define ELFARCH_H 19 | 20 | #if defined(__i386__) 21 | #define EM_THIS EM_386 22 | #define EL_ARCH_USES_REL 23 | #elif defined(__amd64__) 24 | #define EM_THIS EM_AMD64 25 | #define EL_ARCH_USES_RELA 26 | #elif defined(__arm__) 27 | #define EM_THIS EM_ARM 28 | #define EL_ARCH_USES_REL 29 | #elif defined(__aarch64__) 30 | #define EM_THIS EM_AARCH64 31 | #define EL_ARCH_USES_RELA 32 | #define EL_ARCH_USES_REL 33 | #else 34 | #error specify your ELF architecture 35 | #endif 36 | 37 | #if defined(__LP64__) || defined(__LLP64__) 38 | #define ELFSIZE 64 39 | #else 40 | #define ELFSIZE 32 41 | #endif 42 | 43 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 44 | #define ELFDATATHIS ELFDATA2LSB 45 | #else 46 | #define ELFDATATHIS ELFDATA2MSB 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /bdk/thermal/tmp451.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SOC/PCB Temperature driver for Nintendo Switch's TI TMP451 3 | * 4 | * Copyright (c) 2018 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __TMP451_H_ 20 | #define __TMP451_H_ 21 | 22 | #include 23 | 24 | #define TMP451_I2C_ADDR 0x4C 25 | 26 | #define TMP451_PCB_TEMP_REG 0x00 27 | #define TMP451_SOC_TEMP_REG 0x01 28 | 29 | #define TMP451_CONFIG_REG 0x09 30 | #define TMP451_CNV_RATE_REG 0x0A 31 | 32 | #define TMP451_SOC_TMP_DEC_REG 0x10 33 | #define TMP451_PCB_TMP_DEC_REG 0x15 34 | 35 | #define TMP451_SOC_TMP_OFH_REG 0x11 36 | #define TMP451_SOC_TMP_OFL_REG 0x12 37 | 38 | // If input is false, the return value is packed. MSByte is the integer in oC 39 | // and the LSByte is the decimal point truncated to 2 decimal places. 40 | // Otherwise it's an integer oC. 41 | u16 tmp451_get_soc_temp(bool integer); 42 | u16 tmp451_get_pcb_temp(bool integer); 43 | void tmp451_init(); 44 | void tmp451_end(); 45 | 46 | #endif /* __TMP451_H_ */ 47 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_hal/lv_hal_tick.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_hal_tick.h 3 | * Provide access to the system tick with 1 millisecond resolution 4 | */ 5 | 6 | #ifndef LV_HAL_TICK_H 7 | #define LV_HAL_TICK_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "../../lv_conf.h" 20 | #endif 21 | #include 22 | 23 | /********************* 24 | * DEFINES 25 | *********************/ 26 | #ifndef LV_ATTRIBUTE_TICK_INC 27 | #define LV_ATTRIBUTE_TICK_INC 28 | #endif 29 | 30 | /********************** 31 | * TYPEDEFS 32 | **********************/ 33 | 34 | /********************** 35 | * GLOBAL PROTOTYPES 36 | **********************/ 37 | 38 | /** 39 | * You have to call this function periodically 40 | * @param tick_period the call period of this function in milliseconds 41 | */ 42 | LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period); 43 | 44 | /** 45 | * Get the elapsed milliseconds since start up 46 | * @return the elapsed milliseconds 47 | */ 48 | uint32_t lv_tick_get(void); 49 | 50 | /** 51 | * Get the elapsed milliseconds since a previous time stamp 52 | * @param prev_tick a previous time stamp (return value of systick_get() ) 53 | * @return the elapsed milliseconds since 'prev_tick' 54 | */ 55 | uint32_t lv_tick_elaps(uint32_t prev_tick); 56 | 57 | /********************** 58 | * MACROS 59 | **********************/ 60 | 61 | #ifdef __cplusplus 62 | } /* extern "C" */ 63 | #endif 64 | 65 | #endif /*LV_HAL_TICK_H*/ 66 | -------------------------------------------------------------------------------- /source/config.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #include "config.h" 21 | #include 22 | #include 23 | #include "gfx/tui.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | extern hekate_config h_cfg; 35 | 36 | void set_default_configuration() 37 | { 38 | h_cfg.autoboot = 0; 39 | h_cfg.autoboot_list = 0; 40 | h_cfg.bootwait = 3; 41 | h_cfg.backlight = 100; 42 | h_cfg.autohosoff = 0; 43 | h_cfg.autonogc = 1; 44 | h_cfg.updater2p = 0; 45 | h_cfg.bootprotect = 0; 46 | h_cfg.errors = 0; 47 | h_cfg.aes_slots_new = false; 48 | h_cfg.rcm_patched = fuse_check_patched_rcm(); 49 | h_cfg.emummc_force_disable = false; 50 | h_cfg.t210b01 = hw_get_chip_id() == GP_HIDREV_MAJOR_T210B01; 51 | } 52 | -------------------------------------------------------------------------------- /bdk/storage/nx_sd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2021 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef NX_SD_H 19 | #define NX_SD_H 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | enum 26 | { 27 | SD_INIT_FAIL = 0, 28 | SD_1BIT_HS25 = 1, 29 | SD_4BIT_HS25 = 2, 30 | SD_UHS_SDR82 = 3, 31 | SD_UHS_SDR104 = 4 32 | }; 33 | 34 | enum 35 | { 36 | SD_ERROR_INIT_FAIL = 0, 37 | SD_ERROR_RW_FAIL = 1, 38 | SD_ERROR_RW_RETRY = 2 39 | }; 40 | 41 | extern sdmmc_t sd_sdmmc; 42 | extern sdmmc_storage_t sd_storage; 43 | extern FATFS sd_fs; 44 | 45 | void sd_error_count_increment(u8 type); 46 | u16 *sd_get_error_count(); 47 | bool sd_get_card_removed(); 48 | bool sd_get_card_initialized(); 49 | bool sd_get_card_mounted(); 50 | u32 sd_get_mode(); 51 | int sd_init_retry(bool power_cycle); 52 | bool sd_initialize(bool power_cycle); 53 | bool sd_mount(); 54 | void sd_unmount(); 55 | void sd_end(); 56 | bool sd_is_gpt(); 57 | void *sd_file_read(const char *path, u32 *fsize); 58 | int sd_save_to_file(void *buf, u32 size, const char *filename); 59 | 60 | #endif -------------------------------------------------------------------------------- /source/hos/hos.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2021 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _HOS_H_ 19 | #define _HOS_H_ 20 | 21 | #define KEYBLOB_OFFSET 0x180000 22 | 23 | #define KB_FIRMWARE_VERSION_100 0 24 | #define KB_FIRMWARE_VERSION_300 1 25 | #define KB_FIRMWARE_VERSION_301 2 26 | #define KB_FIRMWARE_VERSION_400 3 27 | #define KB_FIRMWARE_VERSION_500 4 28 | #define KB_FIRMWARE_VERSION_600 5 29 | #define KB_FIRMWARE_VERSION_620 6 30 | #define KB_FIRMWARE_VERSION_700 7 31 | #define KB_FIRMWARE_VERSION_810 8 32 | #define KB_FIRMWARE_VERSION_900 9 33 | #define KB_FIRMWARE_VERSION_910 10 34 | #define KB_FIRMWARE_VERSION_1210 11 35 | #define KB_FIRMWARE_VERSION_1300 12 36 | #define KB_FIRMWARE_VERSION_1400 13 37 | #define KB_FIRMWARE_VERSION_1500 14 38 | #define KB_FIRMWARE_VERSION_1600 15 39 | #define KB_FIRMWARE_VERSION_1700 16 40 | #define KB_FIRMWARE_VERSION_1800 17 41 | #define KB_FIRMWARE_VERSION_1900 18 42 | #define KB_FIRMWARE_VERSION_2000 19 43 | #define KB_FIRMWARE_VERSION_2100 20 44 | #define KB_FIRMWARE_VERSION_MAX KB_FIRMWARE_VERSION_2000 //!TODO: Update on mkey changes. 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /source/storage/emummc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef EMUMMC_H 18 | #define EMUMMC_H 19 | 20 | #include 21 | #include 22 | 23 | typedef enum 24 | { 25 | EMUMMC_TYPE_NONE = 0, 26 | EMUMMC_TYPE_PARTITION = 1, 27 | EMUMMC_TYPE_FILES = 2, 28 | } emummc_type_t; 29 | 30 | typedef enum { 31 | EMUMMC_MMC_NAND = 0, 32 | EMUMMC_MMC_SD = 1, 33 | EMUMMC_MMC_GC = 2, 34 | } emummc_mmc_t; 35 | 36 | typedef struct _emummc_cfg_t 37 | { 38 | int enabled; 39 | u64 sector; 40 | u32 id; 41 | char *path; 42 | char *nintendo_path; 43 | // Internal. 44 | char *emummc_file_based_path; 45 | u32 file_based_part_size; 46 | u32 active_part; 47 | int fs_ver; 48 | } emummc_cfg_t; 49 | 50 | extern emummc_cfg_t emu_cfg; 51 | 52 | void emummc_load_cfg(); 53 | bool emummc_set_path(char *path); 54 | int emummc_storage_init_mmc(); 55 | int emummc_storage_end(); 56 | int emummc_storage_read(u32 sector, u32 num_sectors, void *buf); 57 | int emummc_storage_write(u32 sector, u32 num_sectors, void *buf); 58 | int emummc_storage_set_mmc_partition(u32 partition); 59 | 60 | #endif -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_gc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_gc.h 3 | * 4 | */ 5 | 6 | #ifndef LV_GC_H 7 | #define LV_GC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | #ifdef LV_CONF_INCLUDE_SIMPLE 18 | #include "lv_conf.h" 19 | #else 20 | #include "../../lv_conf.h" 21 | #endif 22 | 23 | #include 24 | #include "lv_mem.h" 25 | #include "lv_ll.h" 26 | 27 | /********************* 28 | * DEFINES 29 | *********************/ 30 | 31 | #define LV_GC_ROOTS(prefix) \ 32 | prefix lv_ll_t _lv_task_ll; /*Linked list to store the lv_tasks*/ \ 33 | prefix lv_ll_t _lv_scr_ll; /*Linked list of screens*/ \ 34 | prefix lv_ll_t _lv_drv_ll;\ 35 | prefix lv_ll_t _lv_file_ll;\ 36 | prefix lv_ll_t _lv_anim_ll;\ 37 | prefix void * _lv_def_scr;\ 38 | prefix void * _lv_act_scr;\ 39 | prefix void * _lv_top_layer;\ 40 | prefix void * _lv_sys_layer;\ 41 | prefix void * _lv_task_act;\ 42 | prefix void * _lv_indev_list;\ 43 | prefix void * _lv_disp_list;\ 44 | 45 | #define LV_NO_PREFIX 46 | #define LV_ROOTS LV_GC_ROOTS(LV_NO_PREFIX) 47 | 48 | #if LV_ENABLE_GC == 1 49 | # if LV_MEM_CUSTOM != 1 50 | # error "GC requires CUSTOM_MEM" 51 | # endif /* LV_MEM_CUSTOM */ 52 | #else /* LV_ENABLE_GC */ 53 | # define LV_GC_ROOT(x) x 54 | LV_GC_ROOTS(extern) 55 | #endif /* LV_ENABLE_GC */ 56 | 57 | 58 | /********************** 59 | * TYPEDEFS 60 | **********************/ 61 | 62 | /********************** 63 | * GLOBAL PROTOTYPES 64 | **********************/ 65 | 66 | /********************** 67 | * MACROS 68 | **********************/ 69 | 70 | 71 | #ifdef __cplusplus 72 | } /* extern "C" */ 73 | #endif 74 | 75 | #endif /*LV_GC_H*/ 76 | -------------------------------------------------------------------------------- /source/storage/nx_emmc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2019-2020 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _NX_EMMC_H_ 19 | #define _NX_EMMC_H_ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #define NX_GPT_FIRST_LBA 1 27 | #define NX_GPT_NUM_BLOCKS 33 28 | #define NX_EMMC_BLOCKSIZE 512 29 | 30 | typedef struct _emmc_part_t 31 | { 32 | u32 index; 33 | u32 lba_start; 34 | u32 lba_end; 35 | u64 attrs; 36 | char name[37]; 37 | link_t link; 38 | } emmc_part_t; 39 | 40 | extern sdmmc_t emmc_sdmmc; 41 | extern sdmmc_storage_t emmc_storage; 42 | extern FATFS emmc_fs; 43 | 44 | void nx_emmc_gpt_parse(link_t *gpt, sdmmc_storage_t *storage); 45 | void nx_emmc_gpt_free(link_t *gpt); 46 | emmc_part_t *nx_emmc_part_find(link_t *gpt, const char *name); 47 | int nx_emmc_part_read(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf); 48 | int nx_emmc_part_write(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf); 49 | 50 | void nx_emmc_get_autorcm_masks(u8 *mod0, u8 *mod1); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_core/lv_lang.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_lang.h 3 | * 4 | */ 5 | 6 | #ifndef LV_LANG_H 7 | #define LV_LANG_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "../../lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_MULTI_LANG 23 | 24 | #include 25 | 26 | /********************* 27 | * DEFINES 28 | *********************/ 29 | #define LV_LANG_TXT_ID_NONE 0xFFFF /*Used to not assign any text IDs for a multi-language object.*/ 30 | 31 | /********************** 32 | * TYPEDEFS 33 | **********************/ 34 | 35 | /********************** 36 | * GLOBAL PROTOTYPES 37 | **********************/ 38 | 39 | /** 40 | * Change the language 41 | * @param lang_id the id of the 42 | */ 43 | void lv_lang_set(uint8_t lang_id); 44 | 45 | /** 46 | * Set a function to get the texts of the set languages from a `txt_id` 47 | * @param fp a function pointer to get the texts 48 | */ 49 | void lv_lang_set_text_func(const void * (*fp)(uint16_t)); 50 | 51 | /** 52 | * Use the function set by `lv_lang_set_text_func` to get the `txt_id` text in the set language 53 | * @param txt_id an ID of the text to get 54 | * @return the `txt_id` txt on the set language 55 | */ 56 | const void * lv_lang_get_text(uint16_t txt_id); 57 | 58 | /** 59 | * Return with ID of the currently selected language 60 | * @return pointer to the active screen object (loaded by 'lv_scr_load()') 61 | */ 62 | uint8_t lv_lang_act(void); 63 | 64 | /********************** 65 | * MACROS 66 | **********************/ 67 | 68 | #endif /*USE_LV_MULTI_LANG*/ 69 | 70 | #ifdef __cplusplus 71 | } /* extern "C" */ 72 | #endif 73 | 74 | #endif /*LV_LANG_H*/ 75 | -------------------------------------------------------------------------------- /bdk/mem/minerva.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _FE_MINERVA_H_ 18 | #define _FE_MINERVA_H_ 19 | 20 | #include "mtc_table.h" 21 | #include 22 | 23 | #define MTC_INIT_MAGIC 0x3043544D 24 | #define MTC_NEW_MAGIC 0x5243544D 25 | 26 | #define EMC_PERIODIC_TRAIN_MS 250 27 | 28 | typedef struct 29 | { 30 | u32 rate_to; 31 | u32 rate_from; 32 | emc_table_t *mtc_table; 33 | u32 table_entries; 34 | emc_table_t *current_emc_table; 35 | u32 train_mode; 36 | u32 sdram_id; 37 | u32 prev_temp; 38 | bool emc_2X_clk_src_is_pllmb; 39 | bool fsp_for_src_freq; 40 | bool train_ram_patterns; 41 | bool init_done; 42 | } mtc_config_t; 43 | 44 | enum train_mode_t 45 | { 46 | OP_SWITCH = 0, 47 | OP_TRAIN = 1, 48 | OP_TRAIN_SWITCH = 2, 49 | OP_PERIODIC_TRAIN = 3, 50 | OP_TEMP_COMP = 4 51 | }; 52 | 53 | typedef enum 54 | { 55 | FREQ_204 = 204000, 56 | FREQ_800 = 800000, 57 | FREQ_1600 = 1600000 58 | } minerva_freq_t; 59 | 60 | extern void (*minerva_cfg)(mtc_config_t *mtc_cfg, void *); 61 | u32 minerva_init(); 62 | void minerva_change_freq(minerva_freq_t freq); 63 | void minerva_prep_boot_freq(); 64 | void minerva_periodic_training(); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /bdk/libs/compr/lz.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Name: lz.h 3 | * Author: Marcus Geelnard 4 | * Description: LZ77 coder/decoder interface. 5 | * Reentrant: Yes 6 | *------------------------------------------------------------------------- 7 | * Copyright (c) 2003-2006 Marcus Geelnard 8 | * 9 | * This software is provided 'as-is', without any express or implied 10 | * warranty. In no event will the authors be held liable for any damages 11 | * arising from the use of this software. 12 | * 13 | * Permission is granted to anyone to use this software for any purpose, 14 | * including commercial applications, and to alter it and redistribute it 15 | * freely, subject to the following restrictions: 16 | * 17 | * 1. The origin of this software must not be misrepresented; you must not 18 | * claim that you wrote the original software. If you use this software 19 | * in a product, an acknowledgment in the product documentation would 20 | * be appreciated but is not required. 21 | * 22 | * 2. Altered source versions must be plainly marked as such, and must not 23 | * be misrepresented as being the original software. 24 | * 25 | * 3. This notice may not be removed or altered from any source 26 | * distribution. 27 | * 28 | * Marcus Geelnard 29 | * marcus.geelnard at home.se 30 | *************************************************************************/ 31 | 32 | #ifndef _lz_h_ 33 | #define _lz_h_ 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /************************************************************************* 41 | * Function prototypes 42 | *************************************************************************/ 43 | 44 | unsigned int LZ_Uncompress( const unsigned char *in, unsigned char *out, 45 | unsigned int insize ); 46 | 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* _lz_h_ */ 53 | -------------------------------------------------------------------------------- /loader/start.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | .section .text._start 18 | .arm 19 | 20 | .extern _reloc_ipl 21 | .type _reloc_ipl, %function 22 | 23 | .extern memset 24 | .type memset, %function 25 | 26 | .extern loader_main 27 | .type loader_main, %function 28 | 29 | .globl _start 30 | .type _start, %function 31 | _start: 32 | ADR R0, _start 33 | LDR R1, =__ipl_start 34 | CMP R0, R1 35 | BEQ _real_start 36 | 37 | /* If we are not in the right location already, copy a relocator to upper IRAM. */ 38 | ADR R2, _reloc_ipl 39 | LDR R3, =0x4003FF00 40 | MOV R4, #(_real_start - _reloc_ipl) 41 | _copy_loop: 42 | LDMIA R2!, {R5} 43 | STMIA R3!, {R5} 44 | SUBS R4, #4 45 | BNE _copy_loop 46 | 47 | /* Use the relocator to copy ourselves into the right place. */ 48 | LDR R2, =__ipl_end 49 | SUB R2, R2, R1 50 | LDR R3, =_real_start 51 | LDR R4, =0x4003FF00 52 | BX R4 53 | 54 | _reloc_ipl: 55 | LDMIA R0!, {R4-R7} 56 | STMIA R1!, {R4-R7} 57 | SUBS R2, #0x10 58 | BNE _reloc_ipl 59 | /* Jump to the relocated entry. */ 60 | BX R3 61 | 62 | _real_start: 63 | /* Initially, we place our stack in IRAM but will move it to SDRAM later. */ 64 | LDR SP, =0x40007000 65 | LDR R0, =__ldr_end 66 | BL loader_main 67 | B . 68 | .word 0 69 | .word 0 70 | .word 0 71 | .word 0 72 | .word 0 73 | .word 0 74 | -------------------------------------------------------------------------------- /source/start.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | .section .text._start 18 | .arm 19 | 20 | .extern _reloc_ipl 21 | .type _reloc_ipl, %function 22 | 23 | .extern memset 24 | .type memset, %function 25 | 26 | .extern loader_main 27 | .type loader_main, %function 28 | 29 | .globl _start 30 | .type _start, %function 31 | _start: 32 | ADR R0, _start 33 | LDR R1, =__ipl_start 34 | CMP R0, R1 35 | BEQ _real_start 36 | 37 | /* If we are not in the right location already, copy a relocator to upper IRAM. */ 38 | ADR R2, _reloc_ipl 39 | LDR R3, =0x4003FF00 40 | MOV R4, #(_real_start - _reloc_ipl) 41 | _copy_loop: 42 | LDMIA R2!, {R5} 43 | STMIA R3!, {R5} 44 | SUBS R4, #4 45 | BNE _copy_loop 46 | 47 | /* Use the relocator to copy ourselves into the right place. */ 48 | LDR R2, =__ipl_end 49 | SUB R2, R2, R1 50 | LDR R3, =_real_start 51 | LDR R4, =0x4003FF00 52 | BX R4 53 | 54 | _reloc_ipl: 55 | LDMIA R0!, {R4-R7} 56 | STMIA R1!, {R4-R7} 57 | SUBS R2, #0x10 58 | BNE _reloc_ipl 59 | /* Jump to the relocated entry. */ 60 | BX R3 61 | 62 | _real_start: 63 | /* Initially, we place our stack in IRAM but will move it to SDRAM later. */ 64 | LDR SP, =0x40007000 65 | LDR R0, =__ldr_end 66 | BL loader_main 67 | B . 68 | .word 0 69 | .word 0 70 | .word 0 71 | .word 0 72 | .word 0 73 | .word 0 74 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_themes/lv_theme_hekate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2019 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef LV_THEME_HEKATE_H 18 | #define LV_THEME_HEKATE_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /********************* 25 | * INCLUDES 26 | *********************/ 27 | #ifdef LV_CONF_INCLUDE_SIMPLE 28 | #include "lv_conf.h" 29 | #else 30 | #include "../../lv_conf.h" 31 | #endif 32 | 33 | #if USE_LV_THEME_HEKATE 34 | 35 | /********************* 36 | * DEFINES 37 | *********************/ 38 | 39 | /********************** 40 | * TYPEDEFS 41 | **********************/ 42 | 43 | /********************** 44 | * GLOBAL PROTOTYPES 45 | **********************/ 46 | 47 | /** 48 | * Initialize the material theme 49 | * @param hue [0..360] hue value from HSV color space to define the theme's base color 50 | * @param font pointer to a font (NULL to use the default) 51 | * @return pointer to the initialized theme 52 | */ 53 | lv_theme_t * lv_theme_hekate_init(uint16_t hue, lv_font_t *font); 54 | 55 | /** 56 | * Get a pointer to the theme 57 | * @return pointer to the theme 58 | */ 59 | lv_theme_t * lv_theme_get_hekate(void); 60 | 61 | /********************** 62 | * MACROS 63 | **********************/ 64 | 65 | #endif 66 | 67 | #ifdef __cplusplus 68 | } /* extern "C" */ 69 | #endif 70 | 71 | #endif /*LV_THEME_MATERIAL_H*/ 72 | -------------------------------------------------------------------------------- /bdk/sec/tsec_t210.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _TSEC_T210_H_ 18 | #define _TSEC_T210_H_ 19 | 20 | #define TSEC_BOOTKEYVER 0x1040 21 | #define TSEC_STATUS 0x1044 22 | #define TSEC_ITFEN 0x1048 23 | #define TSEC_ITFEN_CTXEN BIT(0) 24 | #define TSEC_ITFEN_MTHDEN BIT(1) 25 | #define TSEC_IRQMSET 0x1010 26 | #define TSEC_IRQMSET_WDTMR BIT(1) 27 | #define TSEC_IRQMSET_HALT BIT(4) 28 | #define TSEC_IRQMSET_EXTERR BIT(5) 29 | #define TSEC_IRQMSET_SWGEN0 BIT(6) 30 | #define TSEC_IRQMSET_SWGEN1 BIT(7) 31 | #define TSEC_IRQMSET_EXT(val) (((val) & 0xFF) << 8) 32 | #define TSEC_IRQDEST 0x101C 33 | #define TSEC_IRQDEST_HALT BIT(4) 34 | #define TSEC_IRQDEST_EXTERR BIT(5) 35 | #define TSEC_IRQDEST_SWGEN0 BIT(6) 36 | #define TSEC_IRQDEST_SWGEN1 BIT(7) 37 | #define TSEC_IRQDEST_EXT(val) (((val) & 0xFF) << 8) 38 | #define TSEC_CPUCTL 0x1100 39 | #define TSEC_CPUCTL_STARTCPU BIT(1) 40 | #define TSEC_BOOTVEC 0x1104 41 | #define TSEC_DMACTL 0x110C 42 | #define TSEC_DMATRFBASE 0x1110 43 | #define TSEC_DMATRFMOFFS 0x1114 44 | #define TSEC_DMATRFCMD 0x1118 45 | #define TSEC_DMATRFCMD_IDLE BIT(1) 46 | #define TSEC_DMATRFCMD_IMEM BIT(4) 47 | #define TSEC_DMATRFCMD_SIZE_256B (6 << 8) 48 | #define TSEC_DMATRFFBOFFS 0x111C 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /source/keys/keys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _KEYS_H_ 18 | #define _KEYS_H_ 19 | 20 | #include "crypto.h" 21 | 22 | #include "../hos/hos.h" 23 | #include 24 | #include 25 | 26 | #define TPRINTF(text) \ 27 | end_time = get_tmr_us(); \ 28 | gfx_printf(text" done in %d us\n", end_time - start_time); \ 29 | start_time = get_tmr_us(); \ 30 | minerva_periodic_training() 31 | 32 | #define TPRINTFARGS(text, args...) \ 33 | end_time = get_tmr_us(); \ 34 | gfx_printf(text" done in %d us\n", args, end_time - start_time); \ 35 | start_time = get_tmr_us(); \ 36 | minerva_periodic_training() 37 | 38 | // save key wrapper 39 | #define SAVE_KEY(name) _save_key(#name, name, sizeof(name), text_buffer) 40 | // save key with different name than variable 41 | #define SAVE_KEY_VAR(name, varname) _save_key(#name, varname, sizeof(varname), text_buffer) 42 | // save key family wrapper 43 | #define SAVE_KEY_FAMILY(name, start) _save_key_family(#name, name, start, ARRAY_SIZE(name), sizeof(*(name)), text_buffer) 44 | // save key family with different name than variable 45 | #define SAVE_KEY_FAMILY_VAR(name, varname, start) _save_key_family(#name, varname, start, ARRAY_SIZE(varname), sizeof(*(varname)), text_buffer) 46 | 47 | void dump_keys(); 48 | int save_mariko_partial_keys(u32 start, u32 count, bool append); 49 | void derive_amiibo_keys(); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_circ.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_circ.c 3 | * Circle drawing algorithm (with Bresenham) 4 | * Only a 1/8 circle is calculated. Use CIRC_OCT1_X, CIRC_OCT1_Y macros to get 5 | * the other octets. 6 | */ 7 | 8 | /********************* 9 | * INCLUDES 10 | *********************/ 11 | #include "lv_circ.h" 12 | 13 | /********************* 14 | * DEFINES 15 | *********************/ 16 | 17 | /********************** 18 | * TYPEDEFS 19 | **********************/ 20 | 21 | /********************** 22 | * STATIC PROTOTYPES 23 | **********************/ 24 | 25 | /********************** 26 | * STATIC VARIABLES 27 | **********************/ 28 | 29 | /********************** 30 | * MACROS 31 | **********************/ 32 | 33 | /********************** 34 | * GLOBAL FUNCTIONS 35 | **********************/ 36 | 37 | /** 38 | * Initialize the circle drawing 39 | * @param c pointer to a point. The coordinates will be calculated here 40 | * @param tmp point to a variable. It will store temporary data 41 | * @param radius radius of the circle 42 | */ 43 | void lv_circ_init(lv_point_t * c, lv_coord_t * tmp, lv_coord_t radius) 44 | { 45 | c->x = radius; 46 | c->y = 0; 47 | *tmp = 1 - radius; 48 | } 49 | 50 | /** 51 | * Test the circle drawing is ready or not 52 | * @param c same as in circ_init 53 | * @return true if the circle is not ready yet 54 | */ 55 | bool lv_circ_cont(lv_point_t * c) 56 | { 57 | return c->y <= c->x ? true : false; 58 | } 59 | 60 | /** 61 | * Get the next point from the circle 62 | * @param c same as in circ_init. The next point stored here. 63 | * @param tmp same as in circ_init. 64 | */ 65 | void lv_circ_next(lv_point_t * c, lv_coord_t * tmp) 66 | { 67 | c->y++; 68 | 69 | if(*tmp <= 0) { 70 | (*tmp) += 2 * c->y + 1; // Change in decision criterion for y -> y+1 71 | } else { 72 | c->x--; 73 | (*tmp) += 2 * (c->y - c->x) + 1; // Change for y -> y+1, x -> x-1 74 | } 75 | } 76 | 77 | /********************** 78 | * STATIC FUNCTIONS 79 | **********************/ 80 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_circ.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_circ.h 3 | * 4 | */ 5 | 6 | #ifndef LV_CIRC_H 7 | #define LV_CIRC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | 14 | /********************* 15 | * INCLUDES 16 | *********************/ 17 | #include 18 | #include "lv_area.h" 19 | #include 20 | 21 | /********************* 22 | * DEFINES 23 | *********************/ 24 | #define LV_CIRC_OCT1_X(p) (p.x) 25 | #define LV_CIRC_OCT1_Y(p) (p.y) 26 | #define LV_CIRC_OCT2_X(p) (p.y) 27 | #define LV_CIRC_OCT2_Y(p) (p.x) 28 | #define LV_CIRC_OCT3_X(p) (-p.y) 29 | #define LV_CIRC_OCT3_Y(p) (p.x) 30 | #define LV_CIRC_OCT4_X(p) (-p.x) 31 | #define LV_CIRC_OCT4_Y(p) (p.y) 32 | #define LV_CIRC_OCT5_X(p) (-p.x) 33 | #define LV_CIRC_OCT5_Y(p) (-p.y) 34 | #define LV_CIRC_OCT6_X(p) (-p.y) 35 | #define LV_CIRC_OCT6_Y(p) (-p.x) 36 | #define LV_CIRC_OCT7_X(p) (p.y) 37 | #define LV_CIRC_OCT7_Y(p) (-p.x) 38 | #define LV_CIRC_OCT8_X(p) (p.x) 39 | #define LV_CIRC_OCT8_Y(p) (-p.y) 40 | 41 | /********************** 42 | * TYPEDEFS 43 | **********************/ 44 | 45 | /********************** 46 | * GLOBAL PROTOTYPES 47 | **********************/ 48 | 49 | /** 50 | * Initialize the circle drawing 51 | * @param c pointer to a point. The coordinates will be calculated here 52 | * @param tmp point to a variable. It will store temporary data 53 | * @param radius radius of the circle 54 | */ 55 | void lv_circ_init(lv_point_t * c, lv_coord_t * tmp, lv_coord_t radius); 56 | 57 | /** 58 | * Test the circle drawing is ready or not 59 | * @param c same as in circ_init 60 | * @return true if the circle is not ready yet 61 | */ 62 | bool lv_circ_cont(lv_point_t * c); 63 | 64 | /** 65 | * Get the next point from the circle 66 | * @param c same as in circ_init. The next point stored here. 67 | * @param tmp same as in circ_init. 68 | */ 69 | void lv_circ_next(lv_point_t * c, lv_coord_t * tmp); 70 | 71 | /********************** 72 | * MACROS 73 | **********************/ 74 | 75 | #ifdef __cplusplus 76 | } /* extern "C" */ 77 | #endif 78 | 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /source/gfx/tui.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _TUI_H_ 19 | #define _TUI_H_ 20 | 21 | #include 22 | #include 23 | 24 | #define MENT_END 0 25 | #define MENT_HANDLER 1 26 | #define MENT_MENU 2 27 | #define MENT_DATA 3 28 | #define MENT_BACK 4 29 | #define MENT_CAPTION 5 30 | #define MENT_CHGLINE 6 31 | #define MENT_HDLR_RE 7 32 | 33 | typedef struct _ment_t 34 | { 35 | u32 type; 36 | const char *caption; 37 | u32 color; 38 | void *data; 39 | union 40 | { 41 | void(*handler)(void *); 42 | struct _menu_t *menu; 43 | }; 44 | } ment_t; 45 | 46 | typedef struct _menu_t 47 | { 48 | ment_t *ents; 49 | const char *caption; 50 | u32 x; 51 | u32 y; 52 | } menu_t; 53 | 54 | #define MDEF_END() {MENT_END} 55 | #define MDEF_HANDLER(caption, _handler, color) { MENT_HANDLER, caption, color, NULL, { .handler = _handler } } 56 | #define MDEF_HANDLER_EX(caption, data, _handler, color) { MENT_HANDLER, caption, color, data, { .handler = _handler } } 57 | #define MDEF_MENU(caption, _menu, color) { MENT_MENU, caption, color, NULL, { .menu = _menu } } 58 | #define MDEF_BACK(color) { MENT_BACK, "Back", color } 59 | #define MDEF_CAPTION(caption, color) { MENT_CAPTION, caption, color } 60 | #define MDEF_CHGLINE() {MENT_CHGLINE} 61 | 62 | void tui_sbar(bool force_update); 63 | void tui_pbar(int x, int y, u32 val, u32 fgcol, u32 bgcol); 64 | void *tui_do_menu(menu_t *menu); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lvgl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lvgl.h 3 | * Include all LittleV GL related headers 4 | */ 5 | 6 | #ifndef LVGL_H 7 | #define LVGL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | #include "lv_version.h" 18 | 19 | #include "lv_misc/lv_log.h" 20 | #include "lv_misc/lv_task.h" 21 | 22 | #include "lv_hal/lv_hal.h" 23 | 24 | #include "lv_core/lv_obj.h" 25 | #include "lv_core/lv_group.h" 26 | #include "lv_core/lv_lang.h" 27 | #include "lv_core/lv_vdb.h" 28 | #include "lv_core/lv_refr.h" 29 | 30 | #include "lv_themes/lv_theme.h" 31 | 32 | #include "lv_objx/lv_btn.h" 33 | #include "lv_objx/lv_imgbtn.h" 34 | #include "lv_objx/lv_img.h" 35 | #include "lv_objx/lv_label.h" 36 | #include "lv_objx/lv_line.h" 37 | #include "lv_objx/lv_page.h" 38 | #include "lv_objx/lv_cont.h" 39 | #include "lv_objx/lv_list.h" 40 | #include "lv_objx/lv_chart.h" 41 | #include "lv_objx/lv_table.h" 42 | #include "lv_objx/lv_cb.h" 43 | #include "lv_objx/lv_bar.h" 44 | #include "lv_objx/lv_slider.h" 45 | #include "lv_objx/lv_led.h" 46 | #include "lv_objx/lv_btnm.h" 47 | #include "lv_objx/lv_kb.h" 48 | #include "lv_objx/lv_ddlist.h" 49 | #include "lv_objx/lv_roller.h" 50 | #include "lv_objx/lv_ta.h" 51 | #include "lv_objx/lv_canvas.h" 52 | #include "lv_objx/lv_win.h" 53 | #include "lv_objx/lv_tabview.h" 54 | #include "lv_objx/lv_tileview.h" 55 | #include "lv_objx/lv_mbox.h" 56 | #include "lv_objx/lv_gauge.h" 57 | #include "lv_objx/lv_lmeter.h" 58 | #include "lv_objx/lv_sw.h" 59 | #include "lv_objx/lv_kb.h" 60 | #include "lv_objx/lv_arc.h" 61 | #include "lv_objx/lv_preload.h" 62 | #include "lv_objx/lv_calendar.h" 63 | #include "lv_objx/lv_spinbox.h" 64 | 65 | /********************* 66 | * DEFINES 67 | *********************/ 68 | 69 | /********************** 70 | * TYPEDEFS 71 | **********************/ 72 | 73 | /********************** 74 | * GLOBAL PROTOTYPES 75 | **********************/ 76 | 77 | /********************** 78 | * MACROS 79 | **********************/ 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif /*LVGL_H*/ 86 | -------------------------------------------------------------------------------- /tools/lz/lz.h: -------------------------------------------------------------------------------- 1 | // 2 | // Name: lz.h 3 | // Author: Marcus Geelnard 4 | // Description: LZ77 coder/decoder interface. 5 | // Reentrant: Yes 6 | // ------------------------------------------------------------------------ 7 | // $ATH_LICENSE_NULL$ 8 | // Copyright (c) 2003-2006 Marcus Geelnard 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | // Marcus Geelnard 30 | // marcus.geelnard at home.se 31 | // 32 | 33 | // 34 | // This file has been altered from the original version. 35 | // 36 | 37 | #ifndef _lz_h_ 38 | #define _lz_h_ 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | 45 | /************************************************************************* 46 | * Function prototypes 47 | *************************************************************************/ 48 | 49 | int LZ_Compress( unsigned char *in, unsigned char *out, 50 | unsigned int insize ); 51 | int LZ_CompressFast( unsigned char *in, unsigned char *out, 52 | unsigned int insize, unsigned int *work ); 53 | int LZ_Uncompress( unsigned char *in, unsigned char *out, 54 | unsigned int insize ); 55 | 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* _lz_h_ */ 62 | -------------------------------------------------------------------------------- /bdk/storage/mbr_gpt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2019 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef MBR_GPT_H 19 | #define MBR_GPT_H 20 | 21 | #include 22 | 23 | typedef struct _mbr_chs_t 24 | { 25 | u8 head; 26 | u8 sector; 27 | u8 cylinder; 28 | } __attribute__((packed)) mbr_chs_t; 29 | 30 | typedef struct _mbr_part_t 31 | { 32 | u8 status; 33 | mbr_chs_t start_sct_chs; 34 | u8 type; 35 | mbr_chs_t end_sct_chs; 36 | u32 start_sct; 37 | u32 size_sct; 38 | } __attribute__((packed)) mbr_part_t; 39 | 40 | typedef struct _mbr_t 41 | { 42 | u8 bootstrap[440]; 43 | u32 signature; 44 | u16 copy_protected; 45 | mbr_part_t partitions[4]; 46 | u16 boot_signature; 47 | } __attribute__((packed)) mbr_t; 48 | 49 | typedef struct _gpt_entry_t 50 | { 51 | u8 type_guid[0x10]; 52 | u8 part_guid[0x10]; 53 | u64 lba_start; 54 | u64 lba_end; 55 | u64 attrs; 56 | u16 name[36]; 57 | } gpt_entry_t; 58 | 59 | typedef struct _gpt_header_t 60 | { 61 | u64 signature; // "EFI PART" 62 | u32 revision; 63 | u32 size; 64 | u32 crc32; 65 | u32 res1; 66 | u64 my_lba; 67 | u64 alt_lba; 68 | u64 first_use_lba; 69 | u64 last_use_lba; 70 | u8 disk_guid[0x10]; 71 | u64 part_ent_lba; 72 | u32 num_part_ents; 73 | u32 part_ent_size; 74 | u32 part_ents_crc32; 75 | u8 res2[420]; // Used as first 3 partition entries backup for HOS. 76 | } gpt_header_t; 77 | 78 | typedef struct _gpt_t 79 | { 80 | gpt_header_t header; 81 | gpt_entry_t entries[128]; 82 | } gpt_t; 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /tools/bin2c/bin2c.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This is bin2c program, which allows you to convert binary file to 3 | * C language array, for use as embedded resource, for instance you can 4 | * embed graphics or audio file directly into your program. 5 | * This is public domain software, use it on your own risk. 6 | * Contact Serge Fukanchik at fuxx@mail.ru if you have any questions. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | /* Replace . with _ */ 16 | char* 17 | make_ident ( char* name ) 18 | { 19 | char* ret; 20 | char* p; 21 | 22 | ret = strdup ( name ); 23 | 24 | for ( p = ret; p[0]; p++ ) 25 | { 26 | if ( !isalnum ( p[0] ) ) p[0] = '_'; 27 | } 28 | return ret; 29 | } 30 | 31 | int 32 | main ( int argc, char* argv[] ) 33 | { 34 | unsigned char buf[BUFSIZ]; 35 | char* ident; 36 | FILE *fd; 37 | size_t size, i, total, blksize = BUFSIZ; 38 | int need_comma = 0; 39 | 40 | if ( argc != 2 ) 41 | { 42 | fprintf ( stderr, "Usage: %s binary_file > output_file\n", argv[0] ); 43 | return -1; 44 | } 45 | 46 | fd = fopen ( argv[1], "rb" ); 47 | if ( fd == NULL ) 48 | { 49 | fprintf ( stderr, "%s: can't open %s for reading\n", argv[0], argv[1] ); 50 | return -1; 51 | } 52 | 53 | fseek(fd, 0, SEEK_END); 54 | size = ftell(fd); 55 | rewind(fd); 56 | 57 | ident = make_ident ( argv[1] ); 58 | 59 | printf ( "static const unsigned char __attribute__((section (\"._%s\"))) %s[] = {", ident, ident ); 60 | for ( total = 0; total < size; ) 61 | { 62 | if ( size - total < blksize ) blksize = size - total; 63 | if ( fread ( buf, 1, blksize, fd ) != blksize ) 64 | { 65 | fprintf ( stderr, "%s: file read error\n", argv[0] ); 66 | return -1; 67 | } 68 | for ( i = 0; i < blksize; i++ ) 69 | { 70 | if ( need_comma ) printf ( ", " ); 71 | else need_comma = 1; 72 | if ( ( total % 11 ) == 0 ) printf ( "\n\t" ); 73 | printf ( "0x%.2x", buf[i] ); 74 | total++; 75 | } 76 | } 77 | printf ( "\n};\n" ); 78 | 79 | fclose ( fd ); 80 | free ( ident ); 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /bdk/input/als.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ambient light sensor driver for Nintendo Switch's Rohm BH1730 3 | * 4 | * Copyright (c) 2018 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __ALS_H_ 20 | #define __ALS_H_ 21 | 22 | #include 23 | 24 | #define BH1730_I2C_ADDR 0x29 25 | 26 | #define BH1730_CMD_MAGIC 0x80 27 | #define BH1730_CMD_SETADDR 0x00 28 | #define BH1730_CMD_SPECCMD 0x60 29 | #define BH1730_SPECCMD_RESET 0x4 30 | 31 | #define BH1730_CONTROL_REG 0x00 32 | #define BH1730_CTL_ADC_VALID 0x10 33 | #define BH1730_CTL_ONE_TIME 0x08 34 | #define BH1730_CTL_DAT0_ONLY 0x04 35 | #define BH1730_CTL_ADC_EN 0x02 36 | #define BH1730_CTL_POWER_ON 0x01 37 | #define BH1730_TIMING_REG 0x01 38 | #define BH1730_GAIN_REG 0x07 39 | #define BH1730_GAIN_1X 0x00 40 | #define BH1730_GAIN_2X 0x01 41 | #define BH1730_GAIN_64X 0x02 42 | #define BH1730_GAIN_128X 0x03 43 | #define BH1730_DATA0LOW_REG 0x14 44 | #define BH1730_DATA0HIGH_REG 0x15 45 | #define BH1730_DATA1LOW_REG 0x16 46 | #define BH1730_DATA1HIGH_REG 0x17 47 | 48 | #define BH1730_ADDR(reg) (BH1730_CMD_MAGIC | BH1730_CMD_SETADDR | (reg)) 49 | #define BH1730_SPEC(cmd) (BH1730_CMD_MAGIC | BH1730_CMD_SPECCMD | (cmd)) 50 | 51 | typedef struct _als_ctxt_t 52 | { 53 | u32 lux; 54 | bool over_limit; 55 | u32 vi_light; 56 | u32 ir_light; 57 | u8 gain; 58 | u8 cycle; 59 | } als_ctxt_t; 60 | 61 | void set_als_cfg(als_ctxt_t *als_ctxt, u8 gain, u8 cycle); 62 | void get_als_lux(als_ctxt_t *als_ctxt); 63 | u8 als_power_on(als_ctxt_t *als_ctxt); 64 | 65 | #endif /* __ALS_H_ */ 66 | -------------------------------------------------------------------------------- /bdk/ianos/elfload/elfreloc_arm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * wrote this file. As long as you retain this notice you can do 5 | * whatever you want with this stuff. If we meet some day, and you think this 6 | * stuff is worth it, you can buy me a beer in return. M4xw 7 | * ---------------------------------------------------------------------------- 8 | */ 9 | 10 | #include "elfload.h" 11 | 12 | #if defined(__arm__) 13 | 14 | // Taken from http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044f/IHI0044F_aaelf.pdf 15 | #define R_ARM_NONE 0 16 | #define R_ARM_ABS32 2 17 | #define R_ARM_JUMP_SLOT 22 18 | #define R_ARM_GLOB_DAT 21 19 | #define R_ARM_RELATIVE 23 20 | 21 | el_status el_applyrel(el_ctx *ctx, Elf_Rel *rel) 22 | { 23 | uint32_t sym = ELF_R_SYM(rel->r_info); // Symbol offset 24 | uint32_t type = ELF_R_TYPE(rel->r_info); // Relocation Type 25 | uintptr_t *p = (uintptr_t *)(rel->r_offset + ctx->base_load_paddr); // Target Addr 26 | 27 | #if 0 // For later symbol usage 28 | Elf32_Sym *elfSym; 29 | const char *symbolName; 30 | 31 | // We resolve relocs from the originating elf-image 32 | elfSym = (Elf32_Sym *)(ctx->symtab.sh_offset + (char *)buffteg) + sym; 33 | int strtab_offset = ctx->shstr.sh_offset; 34 | char *strtab = (char *)buffteg + strtab_offset; 35 | symbolName = strtab + elfSym->st_name; 36 | //EL_DEBUG("Str: %s sz: %x val: %x\n", symbolName, elfSym->st_size, elfSym->st_value); 37 | #endif 38 | 39 | switch (type) 40 | { 41 | case R_ARM_NONE: 42 | EL_DEBUG("R_ARM_NONE\n"); 43 | break; 44 | case R_ARM_JUMP_SLOT: 45 | case R_ARM_ABS32: 46 | case R_ARM_GLOB_DAT: 47 | // Stubbed for later purpose 48 | //*p += elfSym->st_value; // + vaddr from sec 49 | //*p |= 0; // 1 if Thumb && STT_FUNC, ignored for now 50 | break; 51 | case R_ARM_RELATIVE: // Needed for PIE 52 | if (sym) 53 | { 54 | return EL_BADREL; 55 | } 56 | *p += ctx->base_load_vaddr; 57 | break; 58 | 59 | default: 60 | return EL_BADREL; 61 | } 62 | 63 | return EL_OK; 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /bdk/libs/nx_savedata/directory_entry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /* 18 | ISC License 19 | 20 | hactool Copyright (c) 2018, SciresM 21 | 22 | Permission to use, copy, modify, and/or distribute this software for any 23 | purpose with or without fee is hereby granted, provided that the above 24 | copyright notice and this permission notice appear in all copies. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 27 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 28 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 29 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 30 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 31 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 32 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 | */ 34 | 35 | #ifndef _DIRECTORY_ENTRY_H_ 36 | #define _DIRECTORY_ENTRY_H_ 37 | 38 | #include 39 | 40 | typedef enum { 41 | OPEN_DIR_MODE_DIR = 1, 42 | OPEN_DIR_MODE_FILE = 2, 43 | OPEN_DIR_MODE_NO_FILE_SIZE = -2147483648, 44 | OPEN_DIR_MODE_ALL = OPEN_DIR_MODE_DIR | OPEN_DIR_MODE_FILE 45 | } open_directory_mode_t; 46 | 47 | typedef enum { 48 | DIR_ENT_TYPE_DIR = 0, 49 | DIR_ENT_TYPE_FILE 50 | } directory_entry_type_t; 51 | 52 | typedef struct { 53 | char name[0x301]; 54 | uint8_t attributes; 55 | uint8_t _0x302[2]; 56 | directory_entry_type_t type; 57 | uint64_t size; 58 | } directory_entry_t; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_math.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file math_base.h 3 | * 4 | */ 5 | 6 | #ifndef LV_MATH_H 7 | #define LV_MATH_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | 14 | /********************* 15 | * INCLUDES 16 | *********************/ 17 | #include 18 | 19 | /********************* 20 | * DEFINES 21 | *********************/ 22 | #define LV_MATH_MIN(a,b) ((a) < (b) ? (a) : (b)) 23 | #define LV_MATH_MAX(a,b) ((a) > (b) ? (a) : (b)) 24 | #define LV_MATH_ABS(x) ((x) > 0 ? (x) : (-(x))) 25 | 26 | #define LV_TRIGO_SIN_MAX 32767 27 | #define LV_TRIGO_SHIFT 15 /* >> LV_TRIGO_SHIFT to normalize*/ 28 | 29 | #define LV_BEZIER_VAL_MAX 1024 /*Max time in Bezier functions (not [0..1] to use integers) */ 30 | #define LV_BEZIER_VAL_SHIFT 10 /*log2(LV_BEZIER_VAL_MAX): used to normalize up scaled values*/ 31 | 32 | /********************** 33 | * TYPEDEFS 34 | **********************/ 35 | 36 | /********************** 37 | * GLOBAL PROTOTYPES 38 | **********************/ 39 | /** 40 | * Convert a number to string 41 | * @param num a number 42 | * @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements) 43 | * @return same as `buf` (just for convenience) 44 | */ 45 | char * lv_math_num_to_str(int32_t num, char * buf); 46 | 47 | /** 48 | * Return with sinus of an angle 49 | * @param angle 50 | * @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767 51 | */ 52 | int16_t lv_trigo_sin(int16_t angle); 53 | 54 | /** 55 | * Calculate a value of a Cubic Bezier function. 56 | * @param t time in range of [0..LV_BEZIER_VAL_MAX] 57 | * @param u0 start values in range of [0..LV_BEZIER_VAL_MAX] 58 | * @param u1 control value 1 values in range of [0..LV_BEZIER_VAL_MAX] 59 | * @param u2 control value 2 in range of [0..LV_BEZIER_VAL_MAX] 60 | * @param u3 end values in range of [0..LV_BEZIER_VAL_MAX] 61 | * @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX] 62 | */ 63 | int32_t lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3); 64 | 65 | /********************** 66 | * MACROS 67 | **********************/ 68 | 69 | #ifdef __cplusplus 70 | } /* extern "C" */ 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_fonts/lv_font_builtin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /** 18 | * @file lv_font_builtin.h 19 | * 20 | */ 21 | 22 | #ifndef LV_FONT_BUILTIN_H 23 | #define LV_FONT_BUILTIN_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /********************* 30 | * INCLUDES 31 | *********************/ 32 | #ifdef LV_CONF_INCLUDE_SIMPLE 33 | #include "lv_conf.h" 34 | #else 35 | #include "../../lv_conf.h" 36 | #endif 37 | 38 | #include "../lv_misc/lv_font.h" 39 | 40 | /********************* 41 | * DEFINES 42 | *********************/ 43 | 44 | /********************** 45 | * TYPEDEFS 46 | **********************/ 47 | 48 | /********************** 49 | * GLOBAL PROTOTYPES 50 | **********************/ 51 | 52 | /** 53 | * Initialize the built-in fonts 54 | */ 55 | void lv_font_builtin_init(void); 56 | 57 | /********************** 58 | * MACROS 59 | **********************/ 60 | 61 | /********************** 62 | * FONT DECLARATIONS 63 | **********************/ 64 | 65 | /*20 px */ 66 | #if USE_INTERUI_20 67 | LV_FONT_DECLARE(interui_20); 68 | #endif 69 | 70 | #if USE_HEKATE_SYMBOL_20 71 | LV_FONT_DECLARE(hekate_symbol_20); 72 | #endif 73 | 74 | /*30 px */ 75 | #if USE_INTERUI_30 76 | LV_FONT_DECLARE(interui_30); 77 | #endif 78 | 79 | #if USE_HEKATE_SYMBOL_30 80 | LV_FONT_DECLARE(hekate_symbol_30); 81 | #endif 82 | 83 | #if USE_UBUNTU_MONO 84 | LV_FONT_DECLARE(ubuntu_mono); 85 | #endif 86 | 87 | #if USE_HEKATE_SYMBOL_120 88 | LV_FONT_DECLARE(hekate_symbol_120); 89 | #endif 90 | 91 | #ifdef __cplusplus 92 | } /* extern "C" */ 93 | #endif 94 | 95 | #endif /*LV_FONT_BUILTIN_H*/ 96 | -------------------------------------------------------------------------------- /source/keys/es_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _ES_TYPES_H_ 18 | #define _ES_TYPES_H_ 19 | 20 | #include 21 | #include 22 | 23 | typedef struct { 24 | u8 private_exponent[SE_RSA2048_DIGEST_SIZE]; 25 | u8 modulus[SE_RSA2048_DIGEST_SIZE]; 26 | u32 public_exponent; 27 | u8 reserved[0xC]; 28 | } eticket_rsa_keypair_t; 29 | 30 | // only tickets of type Rsa2048Sha256 are expected 31 | typedef struct { 32 | u32 signature_type; // always 0x10004 33 | u8 signature[SE_RSA2048_DIGEST_SIZE]; 34 | u8 sig_padding[0x3C]; 35 | char issuer[0x40]; 36 | u8 titlekey_block[SE_RSA2048_DIGEST_SIZE]; 37 | u8 format_version; 38 | u8 titlekey_type; 39 | u16 ticket_version; 40 | u8 license_type; 41 | u8 common_key_id; 42 | u16 property_mask; 43 | u64 reserved; 44 | u64 ticket_id; 45 | u64 device_id; 46 | u8 rights_id[0x10]; 47 | u32 account_id; 48 | u32 sect_total_size; 49 | u32 sect_hdr_offset; 50 | u16 sect_hdr_count; 51 | u16 sect_hdr_entry_size; 52 | u8 padding[0x140]; 53 | } ticket_t; 54 | 55 | typedef struct { 56 | u8 rights_id[0x10]; 57 | u64 ticket_id; 58 | u32 account_id; 59 | u16 property_mask; 60 | u16 reserved; 61 | } ticket_record_t; 62 | 63 | typedef struct { 64 | u8 read_buffer[SZ_256K]; 65 | u8 rights_ids[SZ_256K / 0x10][0x10]; 66 | u8 titlekeys[SZ_256K / 0x10][0x10]; 67 | } titlekey_buffer_t; 68 | 69 | typedef struct { 70 | char rights_id[0x20]; 71 | char equals[3]; 72 | char titlekey[0x20]; 73 | char newline[1]; 74 | } titlekey_text_buffer_t; 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /bdk/libs/nx_savedata/path_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /* 18 | ISC License 19 | 20 | hactool Copyright (c) 2018, SciresM 21 | 22 | Permission to use, copy, modify, and/or distribute this software for any 23 | purpose with or without fee is hereby granted, provided that the above 24 | copyright notice and this permission notice appear in all copies. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 27 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 28 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 29 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 30 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 31 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 32 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 | */ 34 | 35 | #ifndef _PATH_PARSER_H_ 36 | #define _PATH_PARSER_H_ 37 | 38 | #include 39 | 40 | #include 41 | 42 | typedef struct { 43 | const char *_path; 44 | uint64_t path_len; 45 | uint32_t _offset; 46 | uint32_t _length; 47 | bool _finished; 48 | } path_parser_ctx_t; 49 | 50 | static ALWAYS_INLINE bool save_path_parser_is_finished(path_parser_ctx_t *ctx) { 51 | return ctx->_finished; 52 | } 53 | 54 | bool save_path_parser_init(path_parser_ctx_t *ctx, const char *path); 55 | bool save_path_parser_move_next(path_parser_ctx_t *ctx); 56 | const char *save_path_parser_get_current(path_parser_ctx_t *ctx, uint32_t *out_len); 57 | bool save_path_parser_try_get_next(path_parser_ctx_t *ctx, char *name); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /loader/Makefile: -------------------------------------------------------------------------------- 1 | ifeq ($(strip $(DEVKITARM)),) 2 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 3 | endif 4 | 5 | include $(DEVKITARM)/base_rules 6 | 7 | ################################################################################ 8 | 9 | LDR_LOAD_ADDR := 0x40007000 10 | MAGIC := 0x4B434F4C #"LOCK" 11 | include ../Versions.inc 12 | 13 | ################################################################################ 14 | 15 | TARGET := loader 16 | BUILDDIR := ../build 17 | OUTPUTDIR := ../output 18 | BDKDIR := bdk 19 | BDKINC := -I../$(BDKDIR) 20 | VPATH += $(dir $(wildcard ../$(BDKDIR)/*/)) $(dir $(wildcard ../$(BDKDIR)/*/*/)) 21 | 22 | # Main and graphics. 23 | OBJS = $(addprefix $(BUILDDIR)/$(TARGET)/, \ 24 | start.o loader.o lz.o \ 25 | ) 26 | 27 | ################################################################################ 28 | 29 | CUSTOMDEFINES := -DLP_MAGIC=$(MAGIC) 30 | CUSTOMDEFINES += -DLP_VER_MJ=$(LPVERSION_MAJOR) -DLP_VER_MN=$(LPVERSION_MINOR) -DLP_VER_BF=$(LPVERSION_BUGFX) -DLP_RESERVED=$(LPVERSION_RSVD) 31 | 32 | #TODO: Considering reinstating some of these when pointer warnings have been fixed. 33 | WARNINGS := -Wall -Wno-array-bounds -Wno-stringop-overflow 34 | 35 | ARCH := -march=armv4t -mtune=arm7tdmi -mthumb-interwork 36 | CFLAGS = $(ARCH) -O2 -g -nostdlib -ffunction-sections -fdata-sections -fomit-frame-pointer -std=gnu11 $(WARNINGS) $(CUSTOMDEFINES) 37 | LDFLAGS = $(ARCH) -nostartfiles -lgcc -Wl,--nmagic,--gc-sections -Xlinker --defsym=LDR_LOAD_ADDR=$(LDR_LOAD_ADDR) 38 | 39 | ################################################################################ 40 | 41 | .PHONY: all clean 42 | 43 | all: $(TARGET).bin $(TOOLSLZ) $(TOOLSB2C) 44 | 45 | clean: 46 | @rm -rf $(OBJS) 47 | 48 | $(TARGET).bin: $(BUILDDIR)/$(TARGET)/$(TARGET).elf 49 | $(OBJCOPY) -S -O binary $< $(OUTPUTDIR)/$(PAYLOAD_NAME).bin 50 | 51 | $(BUILDDIR)/$(TARGET)/$(TARGET).elf: $(OBJS) 52 | @$(CC) $(LDFLAGS) -T link.ld $^ -o $@ 53 | 54 | $(BUILDDIR)/$(TARGET)/%.o: %.c 55 | @$(CC) $(CFLAGS) $(BDKINC) -c $< -o $@ 56 | 57 | $(BUILDDIR)/$(TARGET)/%.o: %.S 58 | @$(CC) $(CFLAGS) -c $< -o $@ 59 | 60 | $(OBJS): $(BUILDDIR)/$(TARGET) 61 | 62 | $(BUILDDIR)/$(TARGET): 63 | @mkdir -p "$(BUILDDIR)" 64 | @mkdir -p "$(BUILDDIR)/$(TARGET)" 65 | @mkdir -p "$(OUTPUTDIR)" 66 | -------------------------------------------------------------------------------- /bdk/soc/bpmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BPMP-Lite Cache/MMU and Frequency driver for Tegra X1 3 | * 4 | * Copyright (c) 2019-2021 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _BPMP_H_ 20 | #define _BPMP_H_ 21 | 22 | #include 23 | 24 | typedef enum 25 | { 26 | BPMP_MMU_MAINT_NOP = 0, 27 | BPMP_MMU_MAINT_CLEAN_PHY = 1, 28 | BPMP_MMU_MAINT_INVALID_PHY = 2, 29 | BPMP_MMU_MAINT_CLEAN_INVALID_PHY = 3, 30 | BPMP_MMU_MAINT_CLEAN_LINE = 9, 31 | BPMP_MMU_MAINT_INVALID_LINE = 10, 32 | BPMP_MMU_MAINT_CLEAN_INVALID_LINE = 11, 33 | BPMP_MMU_MAINT_CLEAN_WAY = 17, 34 | BPMP_MMU_MAINT_INVALID_WAY = 18, 35 | BPMP_MMU_MAINT_CLN_INV_WAY = 19 36 | } bpmp_maintenance_t; 37 | 38 | typedef struct _bpmp_mmu_entry_t 39 | { 40 | u32 start_addr; 41 | u32 end_addr; 42 | u32 attr; 43 | u32 enable; 44 | } bpmp_mmu_entry_t; 45 | 46 | typedef enum 47 | { 48 | BPMP_CLK_NORMAL, // 408MHz 0% - 136MHz APB. 49 | BPMP_CLK_HIGH_BOOST, // 544MHz 33% - 136MHz APB. 50 | BPMP_CLK_SUPER_BOOST, // 576MHz 41% - 144MHz APB. 51 | BPMP_CLK_HYPER_BOOST, // 589MHz 44% - 147MHz APB. 52 | //BPMP_CLK_DEV_BOOST, // 608MHz 49% - 152MHz APB. 53 | BPMP_CLK_MAX 54 | } bpmp_freq_t; 55 | 56 | #define BPMP_CLK_LOWER_BOOST BPMP_CLK_SUPER_BOOST 57 | #define BPMP_CLK_DEFAULT_BOOST BPMP_CLK_HYPER_BOOST 58 | 59 | void bpmp_mmu_maintenance(u32 op, bool force); 60 | void bpmp_mmu_set_entry(int idx, bpmp_mmu_entry_t *entry, bool apply); 61 | void bpmp_mmu_enable(); 62 | void bpmp_mmu_disable(); 63 | void bpmp_clk_rate_get(); 64 | bpmp_freq_t bpmp_clk_rate_set(bpmp_freq_t fid); 65 | void bpmp_usleep(u32 us); 66 | void bpmp_msleep(u32 ms); 67 | void bpmp_halt(); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /bdk/storage/ramdisk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Ramdisk driver for Tegra X1 3 | * 4 | * Copyright (c) 2019-2021 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | 21 | #include "ramdisk.h" 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | static u32 disk_size = 0; 29 | 30 | int ram_disk_init(FATFS *ram_fs, u32 ramdisk_size) 31 | { 32 | int res = 0; 33 | disk_size = ramdisk_size; 34 | 35 | // If ramdisk is not raw, format it. 36 | if (ram_fs) 37 | { 38 | u8 *buf = malloc(0x400000); 39 | 40 | // Set ramdisk size. 41 | ramdisk_size >>= 9; 42 | disk_set_info(DRIVE_RAM, SET_SECTOR_COUNT, &ramdisk_size); 43 | 44 | // Unmount ramdisk. 45 | f_mount(NULL, "ram:", 1); 46 | 47 | // Format as exFAT w/ 32KB cluster with no MBR. 48 | res = f_mkfs("ram:", FM_EXFAT | FM_SFD, RAMDISK_CLUSTER_SZ, buf, 0x400000); 49 | 50 | // Mount ramdisk. 51 | if (!res) 52 | res = f_mount(ram_fs, "ram:", 1); 53 | 54 | free(buf); 55 | } 56 | 57 | return res; 58 | } 59 | 60 | int ram_disk_read(u32 sector, u32 sector_count, void *buf) 61 | { 62 | u32 sector_off = RAM_DISK_ADDR + (sector << 9); 63 | u32 bytes_count = sector_count << 9; 64 | 65 | if ((sector_off - RAM_DISK_ADDR) > disk_size) 66 | return 1; 67 | 68 | memcpy(buf, (void *)sector_off, bytes_count); 69 | 70 | return 0; 71 | } 72 | 73 | int ram_disk_write(u32 sector, u32 sector_count, const void *buf) 74 | { 75 | u32 sector_off = RAM_DISK_ADDR + (sector << 9); 76 | u32 bytes_count = sector_count << 9; 77 | 78 | if ((sector_off - RAM_DISK_ADDR) > disk_size) 79 | return 1; 80 | 81 | memcpy((void *)sector_off, buf, bytes_count); 82 | 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /bdk/libs/nx_savedata/save_fs_entry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /* 18 | ISC License 19 | 20 | hactool Copyright (c) 2018, SciresM 21 | 22 | Permission to use, copy, modify, and/or distribute this software for any 23 | purpose with or without fee is hereby granted, provided that the above 24 | copyright notice and this permission notice appear in all copies. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 27 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 28 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 29 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 30 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 31 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 32 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 | */ 34 | 35 | #ifndef _SAVE_FS_ENTRY_H_ 36 | #define _SAVE_FS_ENTRY_H_ 37 | 38 | #include "fs_int64.h" 39 | 40 | #include 41 | #include 42 | 43 | typedef struct { 44 | char name[0x40]; 45 | uint32_t parent; 46 | } save_entry_key_t; 47 | 48 | static_assert(sizeof(save_entry_key_t) == 0x44, "Save entry key size is wrong!"); 49 | 50 | typedef struct { 51 | uint32_t start_block; 52 | fs_int64_t length; 53 | uint32_t _0xC[2]; 54 | } save_file_info_t; 55 | 56 | static_assert(sizeof(save_file_info_t) == 0x14, "Save file info size is wrong!"); 57 | 58 | typedef struct { 59 | uint32_t next_directory; 60 | uint32_t next_file; 61 | uint32_t _0x8[3]; 62 | } save_find_position_t; 63 | 64 | static_assert(sizeof(save_find_position_t) == 0x14, "Save find position size is wrong!"); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /source/keys/ssl_crypto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _SSL_CRYPTO_H_ 18 | #define _SSL_CRYPTO_H_ 19 | 20 | #include "crypto.h" 21 | 22 | #include 23 | 24 | #define SSL_RSA_KEY_SIZE (SE_AES_IV_SIZE + SE_RSA2048_DIGEST_SIZE) 25 | 26 | static const u8 ssl_rsa_kekek_source[0x10] __attribute__((aligned(4))) = { 27 | 0x7F, 0x5B, 0xB0, 0x84, 0x7B, 0x25, 0xAA, 0x67, 0xFA, 0xC8, 0x4B, 0xE2, 0x3D, 0x7B, 0x69, 0x03}; 28 | static const u8 ssl_rsa_kek_source[0x10] __attribute__((aligned(4))) = { 29 | 0x9A, 0x38, 0x3B, 0xF4, 0x31, 0xD0, 0xBD, 0x81, 0x32, 0x53, 0x4B, 0xA9, 0x64, 0x39, 0x7D, 0xE3}; 30 | static const u8 ssl_rsa_kek_source_dev[0x10] __attribute__((aligned(4))) = { 31 | 0xD5, 0xD2, 0xFC, 0x00, 0xFD, 0x49, 0xDD, 0xF8, 0xEE, 0x7B, 0xC4, 0x4B, 0xE1, 0x4C, 0xAA, 0x99}; 32 | static const u8 ssl_rsa_kek_source_legacy[0x10] __attribute__((aligned(4))) = { 33 | 0xED, 0x36, 0xB1, 0x32, 0x27, 0x17, 0xD2, 0xB0, 0xBA, 0x1F, 0xC1, 0xBD, 0x4D, 0x38, 0x0F, 0x5E}; 34 | static const u8 ssl_client_cert_kek_source[0x10] __attribute__((aligned(4))) = { 35 | 0x64, 0xB8, 0x30, 0xDD, 0x0F, 0x3C, 0xB7, 0xFB, 0x4C, 0x16, 0x01, 0x97, 0xEA, 0x9D, 0x12, 0x10}; 36 | static const u8 ssl_client_cert_key_source[0x10] __attribute__((aligned(4))) = { 37 | 0x4D, 0x92, 0x5A, 0x69, 0x42, 0x23, 0xBB, 0x92, 0x59, 0x16, 0x3E, 0x51, 0x8C, 0x78, 0x14, 0x0F}; 38 | 39 | void ssl_derive_rsa_kek_device_unique(key_storage_t *keys, void *out_rsa_kek, u32 generation); 40 | void ssl_derive_rsa_kek_legacy(key_storage_t *keys, void *out_rsa_kek); 41 | void ssl_derive_rsa_kek_original(key_storage_t *keys, void *out_rsa_kek, bool is_dev); 42 | 43 | bool decrypt_ssl_rsa_key(key_storage_t *keys, void *buffer); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /bdk/libs/nx_savedata/allocation_table_iterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /* 18 | ISC License 19 | 20 | hactool Copyright (c) 2018, SciresM 21 | 22 | Permission to use, copy, modify, and/or distribute this software for any 23 | purpose with or without fee is hereby granted, provided that the above 24 | copyright notice and this permission notice appear in all copies. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 27 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 28 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 29 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 30 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 31 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 32 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 | */ 34 | 35 | #ifndef _ALLOCATION_TABLE_ITER_H_ 36 | #define _ALLOCATION_TABLE_ITER_H_ 37 | 38 | #include "allocation_table.h" 39 | 40 | #include 41 | 42 | typedef struct { 43 | allocation_table_ctx_t *fat; 44 | uint32_t virtual_block; 45 | uint32_t physical_block; 46 | uint32_t current_segment_size; 47 | uint32_t next_block; 48 | uint32_t prev_block; 49 | } allocation_table_iterator_ctx_t; 50 | 51 | bool save_allocation_table_iterator_begin(allocation_table_iterator_ctx_t *ctx, allocation_table_ctx_t *table, uint32_t initial_block); 52 | bool save_allocation_table_iterator_move_next(allocation_table_iterator_ctx_t *ctx); 53 | bool save_allocation_table_iterator_move_prev(allocation_table_iterator_ctx_t *ctx); 54 | bool save_allocation_table_iterator_seek(allocation_table_iterator_ctx_t *ctx, uint32_t block); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /bdk/libs/nx_savedata/hierarchical_duplex_storage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /* 18 | ISC License 19 | 20 | hactool Copyright (c) 2018, SciresM 21 | 22 | Permission to use, copy, modify, and/or distribute this software for any 23 | purpose with or without fee is hereby granted, provided that the above 24 | copyright notice and this permission notice appear in all copies. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 27 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 28 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 29 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 30 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 31 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 32 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 | */ 34 | 35 | #ifndef _HIER_DUPLEX_STORAGE_H_ 36 | #define _HIER_DUPLEX_STORAGE_H_ 37 | 38 | #include "duplex_storage.h" 39 | #include "header.h" 40 | #include "remap_storage.h" 41 | #include "storage.h" 42 | 43 | #include 44 | 45 | typedef struct { 46 | duplex_storage_ctx_t layers[2]; 47 | duplex_storage_ctx_t *data_layer; 48 | uint64_t _length; 49 | substorage storage; 50 | } hierarchical_duplex_storage_ctx_t; 51 | 52 | typedef struct { 53 | uint8_t *data_a; 54 | uint8_t *data_b; 55 | duplex_info_t info; 56 | } duplex_fs_layer_info_t; 57 | 58 | bool save_hierarchical_duplex_storage_init(hierarchical_duplex_storage_ctx_t *ctx, remap_storage_ctx_t *storage, save_header_t *header); 59 | bool save_hierarchical_duplex_storage_flush(hierarchical_duplex_storage_ctx_t *ctx, remap_storage_ctx_t *storage, save_header_t *header); 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_log.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_log.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include "lv_log.h" 10 | #if USE_LV_LOG 11 | 12 | #if LV_LOG_PRINTF 13 | #include 14 | #include 15 | #include 16 | #include 17 | #endif 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * STATIC PROTOTYPES 28 | **********************/ 29 | 30 | /********************** 31 | * STATIC VARIABLES 32 | **********************/ 33 | static void (*print_cb)(lv_log_level_t, const char *, uint32_t, const char *); 34 | 35 | /********************** 36 | * MACROS 37 | **********************/ 38 | 39 | /********************** 40 | * GLOBAL FUNCTIONS 41 | **********************/ 42 | 43 | /** 44 | * Register custom print (or anything else) function to call when log is added 45 | * @param f a function pointer: 46 | * `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)` 47 | */ 48 | void lv_log_register_print(void f(lv_log_level_t, const char *, uint32_t, const char *)) 49 | { 50 | print_cb = f; 51 | } 52 | 53 | /** 54 | * Add a log 55 | * @param level the level of log. (From `lv_log_level_t` enum) 56 | * @param file name of the file when the log added 57 | * @param line line number in the source code where the log added 58 | * @param dsc description of the log 59 | */ 60 | void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc) 61 | { 62 | if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/ 63 | 64 | if(level >= LV_LOG_LEVEL) { 65 | 66 | #if LV_LOG_PRINTF && defined(DEBUG_UART_PORT) 67 | static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error"}; 68 | char *log = (char *)malloc(0x1000); 69 | s_printf(log, "%s: %s \t(%s #%d)\r\n", lvl_prefix[level], dsc, file, line); 70 | uart_send(DEBUG_UART_PORT, (u8 *)log, strlen(log) + 1); 71 | //gfx_printf("%s: %s \t(%s #%d)\n", lvl_prefix[level], dsc, file, line); 72 | #else 73 | if(print_cb) print_cb(level, file, line, dsc); 74 | #endif 75 | } 76 | } 77 | 78 | /********************** 79 | * STATIC FUNCTIONS 80 | **********************/ 81 | 82 | #endif /*USE_LV_LOG*/ 83 | -------------------------------------------------------------------------------- /source/keys/es_crypto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #ifndef _ES_CRYPTO_H_ 18 | #define _ES_CRYPTO_H_ 19 | 20 | #include "crypto.h" 21 | #include "es_types.h" 22 | 23 | #include 24 | #include 25 | 26 | #define ETICKET_RSA_KEYPAIR_SIZE (SE_AES_IV_SIZE + SE_RSA2048_DIGEST_SIZE * 2 + SE_KEY_128_SIZE) 27 | 28 | #define TICKET_SIG_TYPE_RSA2048_SHA256 0x10004 29 | 30 | static const u8 eticket_rsa_kek_source[0x10] __attribute__((aligned(4))) = { 31 | 0xDB, 0xA4, 0x51, 0x12, 0x4C, 0xA0, 0xA9, 0x83, 0x68, 0x14, 0xF5, 0xED, 0x95, 0xE3, 0x12, 0x5B}; 32 | static const u8 eticket_rsa_kek_source_dev[0x10] __attribute__((aligned(4))) = { 33 | 0xBE, 0xC0, 0xBC, 0x8E, 0x75, 0xA0, 0xF6, 0x0C, 0x4A, 0x56, 0x64, 0x02, 0x3E, 0xD4, 0x9C, 0xD5}; 34 | static const u8 eticket_rsa_kek_source_legacy[0x10] __attribute__((aligned(4))) = { 35 | 0x88, 0x87, 0x50, 0x90, 0xA6, 0x2F, 0x75, 0x70, 0xA2, 0xD7, 0x71, 0x51, 0xAE, 0x6D, 0x39, 0x87}; 36 | static const u8 eticket_rsa_kekek_source[0x10] __attribute__((aligned(4))) = { 37 | 0x46, 0x6E, 0x57, 0xB7, 0x4A, 0x44, 0x7F, 0x02, 0xF3, 0x21, 0xCD, 0xE5, 0x8F, 0x2F, 0x55, 0x35}; 38 | 39 | bool test_eticket_rsa_keypair(const eticket_rsa_keypair_t *keypair); 40 | 41 | void es_derive_rsa_kek_device_unique(key_storage_t *keys, void *out_rsa_kek, u32 generation, bool is_dev); 42 | void es_derive_rsa_kek_legacy(key_storage_t *keys, void *out_rsa_kek); 43 | void es_derive_rsa_kek_original(key_storage_t *keys, void *out_rsa_kek, bool is_dev); 44 | 45 | bool decrypt_eticket_rsa_key(key_storage_t *keys, void *buffer, bool is_dev); 46 | 47 | void es_decode_tickets(u32 buf_size, titlekey_buffer_t *titlekey_buffer, u32 remaining, u32 total, u32 *titlekey_count, u32 x, u32 y, u32 *pct, u32 *last_pct, bool is_personalized); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /bdk/input/joycon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ambient light sensor driver for Nintendo Switch's Rohm BH1730 3 | * 4 | * Copyright (c) 2018 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __JOYCON_H_ 20 | #define __JOYCON_H_ 21 | 22 | #include 23 | 24 | #define JC_BTNS_DIRECTION_PAD 0xF0000 25 | #define JC_BTNS_PREV_NEXT 0x800080 26 | #define JC_BTNS_ENTER 0x400008 27 | #define JC_BTNS_ESC 0x4 28 | 29 | #define JC_BTNS_ALL (JC_BTNS_PREV_NEXT | JC_BTNS_ENTER | JC_BTNS_DIRECTION_PAD | JC_BTNS_ESC) 30 | 31 | typedef struct _jc_bt_conn_t 32 | { 33 | u8 type; 34 | u8 mac[6]; 35 | u8 host_mac[6]; 36 | u8 ltk[16]; 37 | } jc_bt_conn_t; 38 | 39 | typedef struct _jc_gamepad_rpt_t 40 | { 41 | union 42 | { 43 | struct 44 | { 45 | // Joy-Con (R). 46 | u32 y:1; 47 | u32 x:1; 48 | u32 b:1; 49 | u32 a:1; 50 | u32 sr_r:1; 51 | u32 sl_r:1; 52 | u32 r:1; 53 | u32 zr:1; 54 | 55 | // Shared 56 | u32 minus:1; 57 | u32 plus:1; 58 | u32 r3:1; 59 | u32 l3:1; 60 | u32 home:1; 61 | u32 cap:1; 62 | u32 pad:1; 63 | u32 wired:1; 64 | 65 | // Joy-Con (L). 66 | u32 down:1; 67 | u32 up:1; 68 | u32 right:1; 69 | u32 left:1; 70 | u32 sr_l:1; 71 | u32 sl_l:1; 72 | u32 l:1; 73 | u32 zl:1; 74 | }; 75 | u32 buttons; 76 | }; 77 | 78 | u16 lstick_x; 79 | u16 lstick_y; 80 | u16 rstick_x; 81 | u16 rstick_y; 82 | bool center_stick_l; 83 | bool center_stick_r; 84 | bool conn_l; 85 | bool conn_r; 86 | u8 batt_info_l; 87 | u8 batt_info_r; 88 | jc_bt_conn_t bt_conn_l; 89 | jc_bt_conn_t bt_conn_r; 90 | } jc_gamepad_rpt_t; 91 | 92 | void jc_power_supply(u8 uart, bool enable); 93 | void jc_init_hw(); 94 | void jc_deinit(); 95 | jc_gamepad_rpt_t *joycon_poll(); 96 | jc_gamepad_rpt_t *jc_get_bt_pairing_info(bool *is_l_hos, bool *is_r_hos); 97 | 98 | #endif -------------------------------------------------------------------------------- /bdk/ianos/elfload/elfreloc_aarch64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014, Owen Shepherd 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 | * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | * PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "elfload.h" 18 | 19 | #if defined(__aarch64__) 20 | 21 | #define R_AARCH64_NONE 0 22 | #define R_AARCH64_RELATIVE 1027 23 | 24 | el_status el_applyrela(el_ctx *ctx, Elf_RelA *rel) 25 | { 26 | uintptr_t *p = (uintptr_t *)(rel->r_offset + ctx->base_load_paddr); 27 | uint32_t type = ELF_R_TYPE(rel->r_info); 28 | uint32_t sym = ELF_R_SYM(rel->r_info); 29 | 30 | switch (type) 31 | { 32 | case R_AARCH64_NONE: 33 | EL_DEBUG("R_AARCH64_NONE\n"); 34 | break; 35 | case R_AARCH64_RELATIVE: 36 | if (sym) 37 | { 38 | EL_DEBUG("R_AARCH64_RELATIVE with symbol ref!\n"); 39 | return EL_BADREL; 40 | } 41 | 42 | EL_DEBUG("Applying R_AARCH64_RELATIVE reloc @%p\n", p); 43 | *p = rel->r_addend + ctx->base_load_vaddr; 44 | break; 45 | 46 | default: 47 | EL_DEBUG("Bad relocation %u\n", type); 48 | return EL_BADREL; 49 | } 50 | 51 | return EL_OK; 52 | } 53 | 54 | el_status el_applyrel(el_ctx *ctx, Elf_Rel *rel) 55 | { 56 | uintptr_t *p = (uintptr_t *)(rel->r_offset + ctx->base_load_paddr); 57 | uint32_t type = ELF_R_TYPE(rel->r_info); 58 | uint32_t sym = ELF_R_SYM(rel->r_info); 59 | 60 | switch (type) 61 | { 62 | case R_AARCH64_NONE: 63 | EL_DEBUG("R_AARCH64_NONE\n"); 64 | break; 65 | case R_AARCH64_RELATIVE: 66 | if (sym) 67 | { 68 | EL_DEBUG("R_AARCH64_RELATIVE with symbol ref!\n"); 69 | return EL_BADREL; 70 | } 71 | 72 | EL_DEBUG("Applying R_AARCH64_RELATIVE reloc @%p\n", p); 73 | *p += ctx->base_load_vaddr; 74 | break; 75 | 76 | default: 77 | EL_DEBUG("Bad relocation %u\n", type); 78 | return EL_BADREL; 79 | } 80 | 81 | return EL_OK; 82 | } 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /bdk/libs/nx_savedata/integrity_verification_storage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /* 18 | ISC License 19 | 20 | hactool Copyright (c) 2018, SciresM 21 | 22 | Permission to use, copy, modify, and/or distribute this software for any 23 | purpose with or without fee is hereby granted, provided that the above 24 | copyright notice and this permission notice appear in all copies. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 27 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 28 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 29 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 30 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 31 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 32 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 | */ 34 | 35 | #ifndef _IVFC_H_ 36 | #define _IVFC_H_ 37 | 38 | #include "storage.h" 39 | 40 | #include 41 | 42 | typedef struct { 43 | substorage hash_storage; 44 | int integrity_check_level; 45 | validity_t *block_validities; 46 | uint8_t salt[0x20]; 47 | sector_storage base_storage; 48 | } integrity_verification_storage_ctx_t; 49 | 50 | typedef struct { 51 | substorage data; 52 | uint32_t block_size; 53 | uint8_t salt[0x20]; 54 | } integrity_verification_info_ctx_t; 55 | 56 | void save_ivfc_storage_init(integrity_verification_storage_ctx_t *ctx, integrity_verification_info_ctx_t *info, substorage *hash_storage, int integrity_check_level); 57 | bool save_ivfc_storage_read(integrity_verification_storage_ctx_t *ctx, void *buffer, uint64_t offset, uint64_t count); 58 | bool save_ivfc_storage_write(integrity_verification_storage_ctx_t *ctx, const void *buffer, uint64_t offset, uint64_t count); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /tools/lz/lz77.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "lz.h" 23 | 24 | char filename[1024]; 25 | 26 | int main(int argc, char *argv[]) 27 | { 28 | int nbytes; 29 | int filename_len; 30 | struct stat statbuf; 31 | FILE *in_file, *out_file; 32 | 33 | if(stat(argv[1], &statbuf)) 34 | goto error; 35 | 36 | if((in_file=fopen(argv[1], "rb")) == NULL) 37 | goto error; 38 | 39 | strcpy(filename, argv[1]); 40 | filename_len = strlen(filename); 41 | 42 | uint32_t in_size = statbuf.st_size; 43 | uint8_t *in_buf = (uint8_t *)malloc(in_size); 44 | 45 | uint32_t out_size = statbuf.st_size + 257; 46 | uint8_t *out_buf = (uint8_t *)malloc(out_size); 47 | 48 | if(!(in_buf && out_buf)) 49 | goto error; 50 | 51 | if(fread(in_buf, 1, in_size, in_file) != in_size) 52 | goto error; 53 | 54 | fclose(in_file); 55 | 56 | uint32_t *work = (uint32_t*)malloc(sizeof(uint32_t) * (in_size + 65536)); 57 | for (int i = 0; i < 2; i++) 58 | { 59 | uint32_t in_size_tmp; 60 | if (!i) 61 | { 62 | in_size_tmp = in_size / 2; 63 | strcpy(filename + filename_len, ".00.lz"); 64 | } 65 | else 66 | { 67 | in_size_tmp = in_size - (in_size / 2); 68 | strcpy(filename + filename_len, ".01.lz"); 69 | } 70 | 71 | if (work) 72 | nbytes = LZ_CompressFast(in_buf + (in_size / 2) * i, out_buf, in_size_tmp, work); 73 | else 74 | goto error; 75 | 76 | if (nbytes > out_size) 77 | goto error; 78 | 79 | if((out_file = fopen(filename,"wb")) == NULL) 80 | goto error; 81 | 82 | if (fwrite(out_buf, 1, nbytes, out_file) != nbytes) 83 | goto error; 84 | 85 | fclose(out_file); 86 | } 87 | 88 | return 0; 89 | 90 | error: 91 | fprintf(stderr, "Failed to compress: %s\n", argv[1]); 92 | exit(1); 93 | } 94 | -------------------------------------------------------------------------------- /bdk/libs/nx_savedata/save_data_directory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /* 18 | ISC License 19 | 20 | hactool Copyright (c) 2018, SciresM 21 | 22 | Permission to use, copy, modify, and/or distribute this software for any 23 | purpose with or without fee is hereby granted, provided that the above 24 | copyright notice and this permission notice appear in all copies. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 27 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 28 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 29 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 30 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 31 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 32 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 | */ 34 | 35 | #ifndef _SAVE_DATA_DIRECTORY_H_ 36 | #define _SAVE_DATA_DIRECTORY_H_ 37 | 38 | #include "directory_entry.h" 39 | #include "hierarchical_save_file_table.h" 40 | #include "save_data_directory.h" 41 | #include "save_fs_entry.h" 42 | 43 | #include 44 | 45 | typedef struct { 46 | hierarchical_save_file_table_ctx_t *parent_file_table; 47 | open_directory_mode_t mode; 48 | save_find_position_t *initial_position; 49 | save_find_position_t *_current_position; 50 | } save_data_directory_ctx_t; 51 | 52 | void save_data_directory_init(save_data_directory_ctx_t *ctx, hierarchical_save_file_table_ctx_t *table, save_find_position_t *position, open_directory_mode_t mode); 53 | bool save_data_directory_read(save_data_directory_ctx_t *ctx, uint64_t *out_entries_read, directory_entry_t *entry_buffer, uint64_t entry_count); 54 | bool save_data_directory_get_entry_count(save_data_directory_ctx_t *ctx, uint64_t *out_entry_count); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_core/lv_refr.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_refr.h 3 | * 4 | */ 5 | 6 | #ifndef LV_REFR_H 7 | #define LV_REFR_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_obj.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * STATIC PROTOTYPES 28 | **********************/ 29 | 30 | /********************** 31 | * STATIC VARIABLES 32 | **********************/ 33 | 34 | /********************** 35 | * MACROS 36 | **********************/ 37 | 38 | /********************** 39 | * GLOBAL FUNCTIONS 40 | **********************/ 41 | 42 | /** 43 | * Initialize the screen refresh subsystem 44 | */ 45 | void lv_refr_init(void); 46 | 47 | /** 48 | * Redraw the invalidated areas now. 49 | * Normally the redrawing is periodically executed in `lv_task_handler` but a long blocking process can 50 | * prevent the call of `lv_task_handler`. In this case if the the GUI is updated in the process (e.g. progress bar) 51 | * this function can be called when the screen should be updated. 52 | */ 53 | void lv_refr_now(void); 54 | 55 | /** 56 | * Invalidate an area 57 | * @param area_p pointer to area which should be invalidated 58 | */ 59 | void lv_inv_area(const lv_area_t * area_p); 60 | 61 | /** 62 | * Set a function to call after every refresh to announce the refresh time and the number of refreshed pixels 63 | * @param cb pointer to a callback function (void my_refr_cb(uint32_t time_ms, uint32_t px_num)) 64 | */ 65 | void lv_refr_set_monitor_cb(void (*cb)(uint32_t, uint32_t)); 66 | 67 | /** 68 | * Called when an area is invalidated to modify the coordinates of the area. 69 | * Special display controllers may require special coordinate rounding 70 | * @param cb pointer to the a function which will modify the area 71 | */ 72 | void lv_refr_set_round_cb(void(*cb)(lv_area_t*)); 73 | 74 | /** 75 | * Get the number of areas in the buffer 76 | * @return number of invalid areas 77 | */ 78 | uint16_t lv_refr_get_buf_size(void); 79 | 80 | /** 81 | * Pop (delete) the last 'num' invalidated areas from the buffer 82 | * @param num number of areas to delete 83 | */ 84 | void lv_refr_pop_from_buf(uint16_t num); 85 | /********************** 86 | * STATIC FUNCTIONS 87 | **********************/ 88 | 89 | 90 | #ifdef __cplusplus 91 | } /* extern "C" */ 92 | #endif 93 | 94 | #endif /*LV_REFR_H*/ 95 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_fonts/hekate_symbol_120.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include "../lv_misc/lv_font.h" 18 | 19 | #include 20 | 21 | #if USE_HEKATE_SYMBOL_120 != 0 /*Can be enabled in lv_conf.h*/ 22 | 23 | /*********************************************************************************** 24 | * hekate-symbols-huge.ttf 120 px Font in U+f002 () .. U+f007 () range with all bpp 25 | * Sparse font with only these characters:  26 | ***********************************************************************************/ 27 | 28 | /*Store the glyph descriptions*/ 29 | static const lv_font_glyph_dsc_t hekate_symbol_120_glyph_dsc[] = 30 | { 31 | #if USE_HEKATE_SYMBOL_120 == 8 32 | {.w_px = 103, .glyph_index = 0}, /*Unicode: U+f002 ()*/ 33 | {.w_px = 103, .glyph_index = 12360}, /*Unicode: U+f003 ()*/ 34 | {.w_px = 103, .glyph_index = 24720}, /*Unicode: U+f005 ()*/ 35 | {.w_px = 103, .glyph_index = 37080}, /*Unicode: U+f007 ()*/ 36 | 37 | #endif 38 | }; 39 | 40 | lv_font_t hekate_symbol_120 = 41 | { 42 | .unicode_first = LV_SYMBOL_GLYPH_FIRST, /*First Unicode letter in this font*/ 43 | .unicode_last = LV_SYMBOL_GLYPH_LAST, /*Last Unicode letter in this font*/ 44 | .h_px = 120, /*Font height in pixels*/ 45 | .glyph_bitmap = (const uint8_t *)(NYX_RES_ADDR + 0x36E00), /*Bitmap of glyphs*/ 46 | .glyph_dsc = hekate_symbol_120_glyph_dsc, /*Description of glyphs*/ 47 | .glyph_cnt = 4, /*Number of glyphs in the font*/ 48 | .unicode_list = NULL, /*List of unicode characters*/ 49 | .get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/ 50 | .get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/ 51 | #if USE_HEKATE_SYMBOL_120 == 8 52 | .bpp = 8, /*Bit per pixel*/ 53 | #endif 54 | .monospace = 0, /*Fix width (0: if not used)*/ 55 | .next_page = NULL, /*Pointer to a font extension*/ 56 | }; 57 | 58 | #endif /*USE_HEKATE_SYMBOL_100*/ 59 | -------------------------------------------------------------------------------- /source/frontend/gui.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2021 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include "../gfx/gfx.h" 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | int save_fb_to_bmp() 26 | { 27 | // Disallow screenshots if less than 2s passed. 28 | static u32 timer = 0; 29 | if (get_tmr_ms() < timer) 30 | return 1; 31 | 32 | const u32 file_size = 0x384000 + 0x36; 33 | u8 *bitmap = malloc(file_size); 34 | u32 *fb = malloc(0x384000); 35 | u32 *fb_ptr = gfx_ctxt.fb; 36 | 37 | // Reconstruct FB for bottom-top, portrait bmp. 38 | for (int y = 1279; y > -1; y--) 39 | { 40 | for (u32 x = 0; x < 720; x++) 41 | fb[y * 720 + x] = *fb_ptr++; 42 | } 43 | 44 | memcpy(bitmap + 0x36, fb, 0x384000); 45 | 46 | typedef struct _bmp_t 47 | { 48 | u16 magic; 49 | u32 size; 50 | u32 rsvd; 51 | u32 data_off; 52 | u32 hdr_size; 53 | u32 width; 54 | u32 height; 55 | u16 planes; 56 | u16 pxl_bits; 57 | u32 comp; 58 | u32 img_size; 59 | u32 res_h; 60 | u32 res_v; 61 | u64 rsvd2; 62 | } __attribute__((packed)) bmp_t; 63 | 64 | bmp_t *bmp = (bmp_t *)bitmap; 65 | 66 | bmp->magic = 0x4D42; 67 | bmp->size = file_size; 68 | bmp->rsvd = 0; 69 | bmp->data_off = 0x36; 70 | bmp->hdr_size = 40; 71 | bmp->width = 720; 72 | bmp->height = 1280; 73 | bmp->planes = 1; 74 | bmp->pxl_bits = 32; 75 | bmp->comp = 0; 76 | bmp->img_size = 0x384000; 77 | bmp->res_h = 2834; 78 | bmp->res_v = 2834; 79 | bmp->rsvd2 = 0; 80 | 81 | sd_mount(); 82 | 83 | f_mkdir("sd:/switch"); 84 | 85 | char path[0x80] = "sd:/switch/lockpick_rcm.bmp"; 86 | 87 | // Save screenshot and log. 88 | int res = sd_save_to_file(bitmap, file_size, path); 89 | 90 | // sd_unmount(); 91 | 92 | free(bitmap); 93 | free(fb); 94 | 95 | // Set timer to 2s. 96 | timer = get_tmr_ms() + 2000; 97 | 98 | return res; 99 | } 100 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_fonts/lv_font_builtin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /** 18 | * @file lv_font_built_in.c 19 | * 20 | */ 21 | 22 | /********************* 23 | * INCLUDES 24 | *********************/ 25 | #include "lv_font_builtin.h" 26 | 27 | /********************* 28 | * DEFINES 29 | *********************/ 30 | 31 | /********************** 32 | * TYPEDEFS 33 | **********************/ 34 | 35 | /********************** 36 | * STATIC PROTOTYPES 37 | **********************/ 38 | 39 | /********************** 40 | * STATIC VARIABLES 41 | **********************/ 42 | 43 | /********************** 44 | * MACROS 45 | **********************/ 46 | 47 | /********************** 48 | * GLOBAL FUNCTIONS 49 | **********************/ 50 | 51 | /** 52 | * Initialize the built-in fonts 53 | */ 54 | void lv_font_builtin_init(void) 55 | { 56 | /*InterUI 20*/ 57 | #if USE_INTERUI_20 != 0 58 | lv_font_add(&interui_20, NULL); 59 | #endif 60 | 61 | /*SYMBOL 20*/ 62 | #if USE_HEKATE_SYMBOL_20 != 0 63 | #if USE_INTERUI_20 != 0 64 | lv_font_add(&hekate_symbol_20, &interui_20); 65 | #else 66 | lv_font_add(&hekate_symbol_20, NULL); 67 | #endif 68 | #endif 69 | 70 | /*InterUI 30*/ 71 | #if USE_INTERUI_30 != 0 72 | lv_font_add(&interui_30, NULL); 73 | #endif 74 | 75 | /*SYMBOL 30*/ 76 | #if USE_HEKATE_SYMBOL_30 != 0 77 | #if USE_INTERUI_30 != 0 78 | lv_font_add(&hekate_symbol_30, &interui_30); 79 | #else 80 | lv_font_add(&hekate_symbol_30, NULL); 81 | #endif 82 | #endif 83 | 84 | /*MONO 12*/ 85 | #if USE_UBUNTU_MONO != 0 86 | lv_font_add(&ubuntu_mono, NULL); 87 | #if USE_INTERUI_20 != 0 88 | lv_font_add(&hekate_symbol_20, &ubuntu_mono); 89 | #endif 90 | #endif 91 | 92 | /*Symbol 120*/ 93 | #if USE_HEKATE_SYMBOL_120 != 0 94 | lv_font_add(&hekate_symbol_120, NULL); 95 | #endif 96 | } 97 | 98 | /********************** 99 | * STATIC FUNCTIONS 100 | **********************/ 101 | -------------------------------------------------------------------------------- /bdk/libs/nx_savedata/allocation_table_storage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /* 18 | ISC License 19 | 20 | hactool Copyright (c) 2018, SciresM 21 | 22 | Permission to use, copy, modify, and/or distribute this software for any 23 | purpose with or without fee is hereby granted, provided that the above 24 | copyright notice and this permission notice appear in all copies. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 27 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 28 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 29 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 30 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 31 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 32 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 | */ 34 | 35 | #ifndef _ALLOCATION_TABLE_STORAGE_H_ 36 | #define _ALLOCATION_TABLE_STORAGE_H_ 37 | 38 | #include "allocation_table.h" 39 | #include "storage.h" 40 | 41 | #include 42 | 43 | typedef struct { 44 | substorage *base_storage; 45 | uint32_t block_size; 46 | uint32_t initial_block; 47 | allocation_table_ctx_t *fat; 48 | uint64_t _length; 49 | } allocation_table_storage_ctx_t; 50 | 51 | static ALWAYS_INLINE void save_allocation_table_storage_get_size(allocation_table_storage_ctx_t *ctx, uint64_t *out_size) { 52 | *out_size = ctx->_length; 53 | } 54 | 55 | bool save_allocation_table_storage_init(allocation_table_storage_ctx_t *ctx, substorage *data, allocation_table_ctx_t *table, uint32_t block_size, uint32_t initial_block); 56 | uint32_t save_allocation_table_storage_read(allocation_table_storage_ctx_t *ctx, void *buffer, uint64_t offset, uint64_t count); 57 | uint32_t save_allocation_table_storage_write(allocation_table_storage_ctx_t *ctx, const void *buffer, uint64_t offset, uint64_t count); 58 | bool save_allocation_table_storage_set_size(allocation_table_storage_ctx_t *ctx, uint64_t size); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /bdk/libs/nx_savedata/journal_map.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /* 18 | ISC License 19 | 20 | hactool Copyright (c) 2018, SciresM 21 | 22 | Permission to use, copy, modify, and/or distribute this software for any 23 | purpose with or without fee is hereby granted, provided that the above 24 | copyright notice and this permission notice appear in all copies. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 27 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 28 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 29 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 30 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 31 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 32 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 | */ 34 | 35 | #include "journal_map.h" 36 | 37 | #include "journal_storage.h" 38 | #include "storage.h" 39 | 40 | #include 41 | #include 42 | 43 | static journal_map_entry_t *read_map_entries(uint8_t *map_table, uint32_t count) { 44 | journal_map_entry_t *reader = (journal_map_entry_t *)map_table; 45 | journal_map_entry_t *map = malloc(count * sizeof(journal_map_entry_t)); 46 | 47 | for (uint32_t i = 0; i < count; i++) { 48 | map[i].virtual_index = i; 49 | map[i].physical_index = save_journal_map_entry_get_physical_index(reader->physical_index); 50 | reader++; 51 | } 52 | 53 | return map; 54 | } 55 | 56 | void save_journal_map_init(journal_map_ctx_t *ctx, journal_map_header_t *header, journal_map_params_t *map_info) { 57 | ctx->header = header; 58 | ctx->map_storage = map_info->map_storage; 59 | ctx->modified_physical_blocks = map_info->physical_block_bitmap; 60 | ctx->modified_virtual_blocks = map_info->virtual_block_bitmap; 61 | ctx->free_blocks = map_info->free_block_bitmap; 62 | ctx->entries = read_map_entries(ctx->map_storage, header->main_data_block_count); 63 | } 64 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_hal/lv_hal_tick.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file systick.c 3 | * Provide access to the system tick with 1 millisecond resolution 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #ifdef LV_CONF_INCLUDE_SIMPLE 10 | #include "lv_conf.h" 11 | #else 12 | #include "../../lv_conf.h" 13 | #endif 14 | 15 | #include "lv_hal_tick.h" 16 | #include 17 | 18 | #if LV_TICK_CUSTOM == 1 19 | #include LV_TICK_CUSTOM_INCLUDE 20 | #endif 21 | 22 | /********************* 23 | * DEFINES 24 | *********************/ 25 | 26 | /********************** 27 | * TYPEDEFS 28 | **********************/ 29 | 30 | /********************** 31 | * STATIC PROTOTYPES 32 | **********************/ 33 | 34 | /********************** 35 | * STATIC VARIABLES 36 | **********************/ 37 | static uint32_t sys_time = 0; 38 | static volatile uint8_t tick_irq_flag; 39 | 40 | /********************** 41 | * MACROS 42 | **********************/ 43 | 44 | /********************** 45 | * GLOBAL FUNCTIONS 46 | **********************/ 47 | 48 | /** 49 | * You have to call this function periodically 50 | * @param tick_period the call period of this function in milliseconds 51 | */ 52 | LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period) 53 | { 54 | tick_irq_flag = 0; 55 | sys_time += tick_period; 56 | } 57 | 58 | /** 59 | * Get the elapsed milliseconds since start up 60 | * @return the elapsed milliseconds 61 | */ 62 | uint32_t lv_tick_get(void) 63 | { 64 | #if LV_TICK_CUSTOM == 0 65 | uint32_t result; 66 | do { 67 | tick_irq_flag = 1; 68 | result = sys_time; 69 | } while(!tick_irq_flag); /*'lv_tick_inc()' clears this flag which can be in an interrupt. Continue until make a non interrupted cycle */ 70 | 71 | return result; 72 | #else 73 | return LV_TICK_CUSTOM_SYS_TIME_EXPR; 74 | #endif 75 | } 76 | 77 | /** 78 | * Get the elapsed milliseconds since a previous time stamp 79 | * @param prev_tick a previous time stamp (return value of systick_get() ) 80 | * @return the elapsed milliseconds since 'prev_tick' 81 | */ 82 | uint32_t lv_tick_elaps(uint32_t prev_tick) 83 | { 84 | uint32_t act_time = lv_tick_get(); 85 | 86 | /*If there is no overflow in sys_time simple subtract*/ 87 | if(act_time >= prev_tick) { 88 | prev_tick = act_time - prev_tick; 89 | } else { 90 | prev_tick = UINT32_MAX - prev_tick + 1; 91 | prev_tick += act_time; 92 | } 93 | 94 | return prev_tick; 95 | } 96 | 97 | /********************** 98 | * STATIC FUNCTIONS 99 | **********************/ 100 | 101 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_misc/lv_log.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_log.h 3 | * 4 | */ 5 | 6 | #ifndef LV_LOG_H 7 | #define LV_LOG_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "../../lv_conf.h" 20 | #endif 21 | #include 22 | 23 | /********************* 24 | * DEFINES 25 | *********************/ 26 | 27 | /*Possible log level. For compatibility declare it independently from `USE_LV_LOG`*/ 28 | 29 | #define LV_LOG_LEVEL_TRACE 0 /*A lot of logs to give detailed information*/ 30 | #define LV_LOG_LEVEL_INFO 1 /*Log important events*/ 31 | #define LV_LOG_LEVEL_WARN 2 /*Log if something unwanted happened but didn't caused problem*/ 32 | #define LV_LOG_LEVEL_ERROR 3 /*Only critical issue, when the system may fail*/ 33 | #define _LV_LOG_LEVEL_NUM 4 34 | 35 | typedef int8_t lv_log_level_t; 36 | 37 | #if USE_LV_LOG 38 | /********************** 39 | * TYPEDEFS 40 | **********************/ 41 | 42 | 43 | /********************** 44 | * GLOBAL PROTOTYPES 45 | **********************/ 46 | 47 | /** 48 | * Register custom print (or anything else) function to call when log is added 49 | * @param f a function pointer: 50 | * `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)` 51 | */ 52 | void lv_log_register_print(void f(lv_log_level_t, const char *, uint32_t, const char *)); 53 | 54 | /** 55 | * Add a log 56 | * @param level the level of log. (From `lv_log_level_t` enum) 57 | * @param file name of the file when the log added 58 | * @param line line number in the source code where the log added 59 | * @param dsc description of the log 60 | */ 61 | void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc); 62 | 63 | /********************** 64 | * MACROS 65 | **********************/ 66 | 67 | #define LV_LOG_TRACE(dsc) lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, dsc); 68 | #define LV_LOG_INFO(dsc) lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, dsc); 69 | #define LV_LOG_WARN(dsc) lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, dsc); 70 | #define LV_LOG_ERROR(dsc) lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, dsc); 71 | 72 | #else /*USE_LV_LOG*/ 73 | 74 | /*Do nothing if `USE_LV_LOG 0`*/ 75 | #define lv_log_add(level, file, line, dsc) {;} 76 | #define LV_LOG_TRACE(dsc) {;} 77 | #define LV_LOG_INFO(dsc) {;} 78 | #define LV_LOG_WARN(dsc) {;} 79 | #define LV_LOG_ERROR(dsc) {;} 80 | #endif /*USE_LV_LOG*/ 81 | 82 | #ifdef __cplusplus 83 | } /* extern "C" */ 84 | #endif 85 | 86 | #endif /*LV_LOG_H*/ 87 | -------------------------------------------------------------------------------- /bdk/libs/nx_savedata/save_data_file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /* 18 | ISC License 19 | 20 | hactool Copyright (c) 2018, SciresM 21 | 22 | Permission to use, copy, modify, and/or distribute this software for any 23 | purpose with or without fee is hereby granted, provided that the above 24 | copyright notice and this permission notice appear in all copies. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 27 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 28 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 29 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 30 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 31 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 32 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 | */ 34 | 35 | #ifndef _SAVE_DATA_FILE_H_ 36 | #define _SAVE_DATA_FILE_H_ 37 | 38 | #include "allocation_table_storage.h" 39 | #include "hierarchical_save_file_table.h" 40 | 41 | #include 42 | 43 | #include 44 | 45 | typedef struct { 46 | allocation_table_storage_ctx_t base_storage; 47 | const char *path; 48 | hierarchical_save_file_table_ctx_t *file_table; 49 | uint64_t size; 50 | open_mode_t mode; 51 | } save_data_file_ctx_t; 52 | 53 | static ALWAYS_INLINE void save_data_file_get_size(save_data_file_ctx_t *ctx, uint64_t *out_size) { 54 | *out_size = ctx->size; 55 | } 56 | 57 | void save_data_file_init(save_data_file_ctx_t *ctx, allocation_table_storage_ctx_t *base_storage, const char *path, hierarchical_save_file_table_ctx_t *file_table, uint64_t size, open_mode_t mode); 58 | bool save_data_file_read(save_data_file_ctx_t *ctx, uint64_t *out_bytes_read, uint64_t offset, void *buffer, uint64_t count); 59 | bool save_data_file_write(save_data_file_ctx_t *ctx, uint64_t *out_bytes_written, uint64_t offset, const void *buffer, uint64_t count); 60 | bool save_data_file_set_size(save_data_file_ctx_t *ctx, uint64_t size); 61 | 62 | #endif -------------------------------------------------------------------------------- /bdk/libs/nx_savedata/cached_storage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /* 18 | ISC License 19 | 20 | hactool Copyright (c) 2018, SciresM 21 | 22 | Permission to use, copy, modify, and/or distribute this software for any 23 | purpose with or without fee is hereby granted, provided that the above 24 | copyright notice and this permission notice appear in all copies. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 27 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 28 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 29 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 30 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 31 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 32 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 | */ 34 | 35 | #ifndef _CACHED_STORAGE_H_ 36 | #define _CACHED_STORAGE_H_ 37 | 38 | #include "storage.h" 39 | 40 | #include 41 | #include 42 | 43 | #include 44 | 45 | typedef struct { 46 | uint64_t index; 47 | uint8_t *buffer; 48 | uint32_t length; 49 | bool dirty; 50 | link_t link; 51 | } cache_block_t; 52 | 53 | typedef struct { 54 | substorage base_storage; 55 | uint32_t block_size; 56 | uint64_t length; 57 | uint32_t cache_size; 58 | link_t blocks; 59 | } cached_storage_ctx_t; 60 | 61 | void save_cached_storage_init(cached_storage_ctx_t *ctx, substorage *base_storage, uint32_t block_size, uint32_t cache_size); 62 | void save_cached_storage_init_from_sector_storage(cached_storage_ctx_t *ctx, sector_storage *base_storage, uint32_t cache_size); 63 | void save_cached_storage_finalize(cached_storage_ctx_t *ctx); 64 | uint32_t save_cached_storage_read(cached_storage_ctx_t *ctx, void *buffer, uint64_t offset, uint64_t count); 65 | uint32_t save_cached_storage_write(cached_storage_ctx_t *ctx, const void *buffer, uint64_t offset, uint64_t count); 66 | bool save_cached_storage_flush(cached_storage_ctx_t *ctx); 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /bdk/utils/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2020 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _LIST_H_ 19 | #define _LIST_H_ 20 | 21 | #include 22 | 23 | /*! Initialize list. */ 24 | #define LIST_INIT(name) link_t name = {&name, &name} 25 | 26 | /*! Initialize static list. */ 27 | #define LIST_INIT_STATIC(name) static link_t name = {&name, &name} 28 | 29 | /*! Iterate over all list links. */ 30 | #define LIST_FOREACH(iter, list) \ 31 | for(link_t *iter = (list)->next; iter != (list); iter = iter->next) 32 | 33 | /*! Safely iterate over all list links. */ 34 | #define LIST_FOREACH_SAFE(iter, list) \ 35 | for(link_t *iter = (list)->next, *safe = iter->next; iter != (list); iter = safe, safe = iter->next) 36 | 37 | /*! Iterate over all list members and make sure that the list has at least one entry. */ 38 | #define LIST_FOREACH_ENTRY(etype, iter, list, mn) \ 39 | if ((list)->next != (list)) \ 40 | for(etype *iter = CONTAINER_OF((list)->next, etype, mn); &iter->mn != (list); iter = CONTAINER_OF(iter->mn.next, etype, mn)) 41 | 42 | typedef struct _link_t 43 | { 44 | struct _link_t *prev; 45 | struct _link_t *next; 46 | } link_t; 47 | 48 | static inline void link_init(link_t *l) 49 | { 50 | l->prev = NULL; 51 | l->next = NULL; 52 | } 53 | 54 | static inline int link_used(link_t *l) 55 | { 56 | if(l->next == NULL) 57 | return 1; 58 | return 0; 59 | } 60 | 61 | static inline void list_init(link_t *lh) 62 | { 63 | lh->prev = lh; 64 | lh->next = lh; 65 | } 66 | 67 | static inline void list_prepend(link_t *lh, link_t *l) 68 | { 69 | l->next = lh->next; 70 | l->prev = lh; 71 | lh->next->prev = l; 72 | lh->next = l; 73 | } 74 | 75 | static inline void list_append(link_t *lh, link_t *l) 76 | { 77 | l->prev = lh->prev; 78 | l->next = lh; 79 | lh->prev->next = l; 80 | lh->prev = l; 81 | } 82 | 83 | static inline void list_remove(link_t *l) 84 | { 85 | l->next->prev = l->prev; 86 | l->prev->next = l->next; 87 | link_init(l); 88 | } 89 | 90 | static inline int list_empty(link_t *lh) 91 | { 92 | if(lh->next == lh) 93 | return 1; 94 | return 0; 95 | } 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /source/keys/nfc_crypto.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include "nfc_crypto.h" 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | void nfc_decrypt_amiibo_keys(key_storage_t *keys, nfc_save_key_t out_nfc_save_keys[2], bool is_dev) { 25 | const u8 *encrypted_keys = is_dev ? encrypted_nfc_keys_dev : encrypted_nfc_keys; 26 | u32 kek[SE_KEY_128_SIZE / 4] = {0}; 27 | decrypt_aes_key(KS_AES_ECB, keys, kek, nfc_key_source, 0, 0); 28 | 29 | nfc_keyblob_t __attribute__((aligned(4))) nfc_keyblob; 30 | static const u8 nfc_iv[SE_AES_IV_SIZE] = { 31 | 0xB9, 0x1D, 0xC1, 0xCF, 0x33, 0x5F, 0xA6, 0x13, 0x2A, 0xEF, 0x90, 0x99, 0xAA, 0xCA, 0x93, 0xC8}; 32 | se_aes_key_set(KS_AES_CTR, kek, SE_KEY_128_SIZE); 33 | se_aes_crypt_ctr(KS_AES_CTR, &nfc_keyblob, sizeof(nfc_keyblob), encrypted_keys, sizeof(nfc_keyblob), &nfc_iv); 34 | 35 | minerva_periodic_training(); 36 | 37 | u32 xor_pad[0x20 / 4] = {0}; 38 | se_aes_key_set(KS_AES_CTR, nfc_keyblob.ctr_key, SE_KEY_128_SIZE); 39 | se_aes_crypt_ctr(KS_AES_CTR, xor_pad, sizeof(xor_pad), xor_pad, sizeof(xor_pad), nfc_keyblob.ctr_iv); 40 | 41 | minerva_periodic_training(); 42 | 43 | memcpy(out_nfc_save_keys[0].hmac_key, nfc_keyblob.hmac_key, sizeof(nfc_keyblob.hmac_key)); 44 | memcpy(out_nfc_save_keys[0].phrase, nfc_keyblob.phrase, sizeof(nfc_keyblob.phrase)); 45 | out_nfc_save_keys[0].seed_size = sizeof(nfc_keyblob.seed); 46 | memcpy(out_nfc_save_keys[0].seed, nfc_keyblob.seed, sizeof(nfc_keyblob.seed)); 47 | memcpy(out_nfc_save_keys[0].xor_pad, xor_pad, sizeof(xor_pad)); 48 | 49 | memcpy(out_nfc_save_keys[1].hmac_key, nfc_keyblob.hmac_key_for_verif, sizeof(nfc_keyblob.hmac_key_for_verif)); 50 | memcpy(out_nfc_save_keys[1].phrase, nfc_keyblob.phrase_for_verif, sizeof(nfc_keyblob.phrase_for_verif)); 51 | out_nfc_save_keys[1].seed_size = sizeof(nfc_keyblob.seed_for_verif); 52 | memcpy(out_nfc_save_keys[1].seed, nfc_keyblob.seed_for_verif, sizeof(nfc_keyblob.seed_for_verif)); 53 | memcpy(out_nfc_save_keys[1].xor_pad, xor_pad, sizeof(xor_pad)); 54 | } 55 | -------------------------------------------------------------------------------- /bdk/libs/nx_savedata/journal_storage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /* 18 | ISC License 19 | 20 | hactool Copyright (c) 2018, SciresM 21 | 22 | Permission to use, copy, modify, and/or distribute this software for any 23 | purpose with or without fee is hereby granted, provided that the above 24 | copyright notice and this permission notice appear in all copies. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 27 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 28 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 29 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 30 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 31 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 32 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 | */ 34 | 35 | #ifndef _JOURNAL_STORAGE_H_ 36 | #define _JOURNAL_STORAGE_H_ 37 | 38 | #include "hierarchical_integrity_verification_storage.h" 39 | #include "journal_map.h" 40 | #include "storage.h" 41 | 42 | #include 43 | #include 44 | 45 | typedef struct { 46 | uint32_t magic; /* JNGL */ 47 | uint32_t version; 48 | uint64_t total_size; 49 | uint64_t journal_size; 50 | uint64_t block_size; 51 | journal_map_header_t map_header; 52 | uint8_t reserved[0x1D0]; 53 | } journal_header_t; 54 | 55 | static_assert(sizeof(journal_header_t) == 0x200, "Journal storage header size is wrong!"); 56 | 57 | typedef struct { 58 | journal_map_ctx_t map; 59 | journal_header_t *header; 60 | uint32_t block_size; 61 | uint64_t length; 62 | substorage base_storage; 63 | } journal_storage_ctx_t; 64 | 65 | void save_journal_storage_init(journal_storage_ctx_t *ctx, substorage *base_storage, journal_header_t *header, journal_map_params_t *map_info); 66 | uint32_t save_journal_storage_read(journal_storage_ctx_t *ctx, void *buffer, uint64_t offset, uint64_t count); 67 | uint32_t save_journal_storage_write(journal_storage_ctx_t *ctx, const void *buffer, uint64_t offset, uint64_t count); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /bdk/rtc/max77620-rtc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PMIC Real Time Clock driver for Nintendo Switch's MAX77620-RTC 3 | * 4 | * Copyright (c) 2018 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _MFD_MAX77620_RTC_H_ 20 | #define _MFD_MAX77620_RTC_H_ 21 | 22 | #include 23 | 24 | #define MAX77620_RTC_I2C_ADDR 0x68 25 | 26 | #define MAX77620_RTC_NR_TIME_REGS 7 27 | 28 | #define MAX77620_RTC_CONTROLM_REG 0x02 29 | #define MAX77620_RTC_CONTROL_REG 0x03 30 | #define MAX77620_RTC_BIN_FORMAT BIT(0) 31 | #define MAX77620_RTC_24H BIT(1) 32 | 33 | #define MAX77620_RTC_UPDATE0_REG 0x04 34 | #define MAX77620_RTC_WRITE_UPDATE BIT(0) 35 | #define MAX77620_RTC_READ_UPDATE BIT(4) 36 | 37 | #define MAX77620_RTC_SEC_REG 0x07 38 | #define MAX77620_RTC_MIN_REG 0x08 39 | #define MAX77620_RTC_HOUR_REG 0x09 40 | #define MAX77620_RTC_HOUR_PM_MASK BIT(6) 41 | #define MAX77620_RTC_WEEKDAY_REG 0x0A 42 | #define MAX77620_RTC_MONTH_REG 0x0B 43 | #define MAX77620_RTC_YEAR_REG 0x0C 44 | #define MAX77620_RTC_DATE_REG 0x0D 45 | 46 | #define MAX77620_ALARM1_SEC_REG 0x0E 47 | #define MAX77620_ALARM1_MIN_REG 0x0F 48 | #define MAX77620_ALARM1_HOUR_REG 0x10 49 | #define MAX77620_ALARM1_WEEKDAY_REG 0x11 50 | #define MAX77620_ALARM1_MONTH_REG 0x12 51 | #define MAX77620_ALARM1_YEAR_REG 0x13 52 | #define MAX77620_ALARM1_DATE_REG 0x14 53 | #define MAX77620_ALARM2_SEC_REG 0x15 54 | #define MAX77620_ALARM2_MIN_REG 0x16 55 | #define MAX77620_ALARM2_HOUR_REG 0x17 56 | #define MAX77620_ALARM2_WEEKDAY_REG 0x18 57 | #define MAX77620_ALARM2_MONTH_REG 0x19 58 | #define MAX77620_ALARM2_YEAR_REG 0x1A 59 | #define MAX77620_ALARM2_DATE_REG 0x1B 60 | #define MAX77620_RTC_ALARM_EN_MASK BIT(7) 61 | 62 | typedef struct _rtc_time_t { 63 | u8 weekday; 64 | u8 sec; 65 | u8 min; 66 | u8 hour; 67 | u8 day; 68 | u8 month; 69 | u16 year; 70 | } rtc_time_t; 71 | 72 | void max77620_rtc_get_time(rtc_time_t *time); 73 | void max77620_rtc_stop_alarm(); 74 | void max77620_rtc_epoch_to_date(u32 epoch, rtc_time_t *time); 75 | u32 max77620_rtc_date_to_epoch(const rtc_time_t *time); 76 | 77 | #endif /* _MFD_MAX77620_RTC_H_ */ 78 | -------------------------------------------------------------------------------- /bdk/thermal/tmp451.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SOC/PCB Temperature driver for Nintendo Switch's TI TMP451 3 | * 4 | * Copyright (c) 2018-2020 CTCaer 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | u16 tmp451_get_soc_temp(bool intenger) 25 | { 26 | u8 val; 27 | u16 temp = 0; 28 | 29 | val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TEMP_REG); 30 | if (intenger) 31 | return val; 32 | 33 | temp = val << 8; 34 | val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TMP_DEC_REG); 35 | temp |= ((val >> 4) * 625) / 100; 36 | 37 | return temp; 38 | } 39 | 40 | u16 tmp451_get_pcb_temp(bool intenger) 41 | { 42 | u8 val; 43 | u16 temp = 0; 44 | 45 | val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_PCB_TEMP_REG); 46 | if (intenger) 47 | return val; 48 | 49 | temp = val << 8; 50 | val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_PCB_TMP_DEC_REG); 51 | temp |= ((val >> 4) * 625) / 100; 52 | 53 | return temp; 54 | } 55 | 56 | void tmp451_init() 57 | { 58 | // Disable ALARM and Range to 0 - 127 oC. 59 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_CONFIG_REG, 0x80); 60 | 61 | // Set remote sensor offsets based on SoC. 62 | if (hw_get_chip_id() == GP_HIDREV_MAJOR_T210) 63 | { 64 | // Set offset to 0 oC for Erista. 65 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TMP_OFH_REG, 0); 66 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TMP_OFL_REG, 0); 67 | } 68 | else 69 | { 70 | // Set offset to -12.5 oC for Mariko. 71 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TMP_OFH_REG, 0xF3); // - 13 oC. 72 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TMP_OFL_REG, 0x80); // + 0.5 oC. 73 | } 74 | 75 | // Set conversion rate to 32/s and make a read to update the reg. 76 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_CNV_RATE_REG, 9); 77 | tmp451_get_soc_temp(false); 78 | 79 | // Set rate to every 4 seconds. 80 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_CNV_RATE_REG, 2); 81 | } 82 | 83 | void tmp451_end() 84 | { 85 | // Place into shutdown mode to conserve power. 86 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_CONFIG_REG, 0xC0); 87 | } 88 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_draw/lv_draw_vbasic.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_vbasic.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_VBASIC_H 7 | #define LV_DRAW_VBASIC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "../../lv_conf.h" 20 | #endif 21 | 22 | #if LV_VDB_SIZE != 0 23 | 24 | #include "../lv_misc/lv_color.h" 25 | #include "../lv_misc/lv_area.h" 26 | #include "../lv_misc/lv_font.h" 27 | 28 | /********************* 29 | * DEFINES 30 | *********************/ 31 | 32 | /********************** 33 | * TYPEDEFS 34 | **********************/ 35 | 36 | /********************** 37 | * GLOBAL PROTOTYPES 38 | **********************/ 39 | 40 | void lv_vpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa); 41 | /** 42 | * Fill an area in the Virtual Display Buffer 43 | * @param cords_p coordinates of the area to fill 44 | * @param mask_p fill only o this mask 45 | * @param color fill color 46 | * @param opa opacity of the area (0..255) 47 | */ 48 | void lv_vfill(const lv_area_t * cords_p, const lv_area_t * mask_p, 49 | lv_color_t color, lv_opa_t opa); 50 | 51 | /** 52 | * Draw a letter in the Virtual Display Buffer 53 | * @param pos_p left-top coordinate of the latter 54 | * @param mask_p the letter will be drawn only on this area 55 | * @param font_p pointer to font 56 | * @param letter a letter to draw 57 | * @param color color of letter 58 | * @param opa opacity of letter (0..255) 59 | */ 60 | void lv_vletter(const lv_point_t * pos_p, const lv_area_t * mask_p, 61 | const lv_font_t * font_p, uint32_t letter, 62 | lv_color_t color, lv_opa_t opa); 63 | 64 | /** 65 | * Draw a color map to the display (image) 66 | * @param cords_p coordinates the color map 67 | * @param mask_p the map will drawn only on this area (truncated to VDB area) 68 | * @param map_p pointer to a lv_color_t array 69 | * @param opa opacity of the map 70 | * @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels 71 | * @param alpha_byte true: extra alpha byte is inserted for every pixel 72 | * @param recolor mix the pixels with this color 73 | * @param recolor_opa the intense of recoloring 74 | */ 75 | void lv_vmap(const lv_area_t * cords_p, const lv_area_t * mask_p, 76 | const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, 77 | lv_color_t recolor, lv_opa_t recolor_opa); 78 | 79 | /********************** 80 | * MACROS 81 | **********************/ 82 | 83 | #endif /*LV_VDB_SIZE != 0*/ 84 | 85 | #ifdef __cplusplus 86 | } /* extern "C" */ 87 | #endif 88 | 89 | #endif /*LV_DRAW_RBASIC_H*/ 90 | -------------------------------------------------------------------------------- /bdk/sec/se.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2019-2021 CTCaer 4 | * Copyright (c) 2019-2021 shchmue 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _SE_H_ 20 | #define _SE_H_ 21 | 22 | #include 23 | 24 | void se_rsa_acc_ctrl(u32 rs, u32 flags); 25 | void se_rsa_key_set(u32 ks, const void *mod, u32 mod_size, const void *exp, u32 exp_size); 26 | void se_rsa_key_clear(u32 ks); 27 | int se_rsa_exp_mod(u32 ks, void *dst, u32 dst_size, const void *src, u32 src_size); 28 | void se_key_acc_ctrl(u32 ks, u32 flags); 29 | u32 se_key_acc_ctrl_get(u32 ks); 30 | void se_get_aes_keys(u8 *buf, u8 *keys, u32 keysize); 31 | void se_aes_key_set(u32 ks, const void *key, u32 size); 32 | void se_aes_iv_set(u32 ks, const void *iv); 33 | void se_aes_key_partial_set(u32 ks, u32 index, u32 data); 34 | void se_aes_key_get(u32 ks, void *key, u32 size); 35 | void se_aes_key_clear(u32 ks); 36 | void se_aes_iv_clear(u32 ks); 37 | int se_initialize_rng(); 38 | int se_generate_random(void *dst, u32 size); 39 | int se_generate_random_key(u32 ks_dst, u32 ks_src); 40 | int se_aes_unwrap_key(u32 ks_dst, u32 ks_src, const void *input); 41 | int se_aes_crypt_cbc(u32 ks, u32 enc, void *dst, u32 dst_size, const void *src, u32 src_size); 42 | int se_aes_crypt_ecb(u32 ks, u32 enc, void *dst, u32 dst_size, const void *src, u32 src_size); 43 | int se_aes_crypt_block_ecb(u32 ks, u32 enc, void *dst, const void *src); 44 | int se_aes_crypt_ctr(u32 ks, void *dst, u32 dst_size, const void *src, u32 src_size, const void *ctr); 45 | int se_aes_xts_crypt_sec(u32 tweak_ks, u32 crypt_ks, u32 enc, u64 sec, void *dst, const void *src, u32 sec_size); 46 | int se_aes_xts_crypt(u32 tweak_ks, u32 crypt_ks, u32 enc, u64 sec, void *dst, const void *src, u32 sec_size, u32 num_secs); 47 | int se_aes_cmac(u32 ks, void *dst, u32 dst_size, const void *src, u32 src_size); 48 | int se_calc_sha256(void *hash, u32 *msg_left, const void *src, u32 src_size, u64 total_size, u32 sha_cfg, bool is_oneshot); 49 | int se_calc_sha256_oneshot(void *hash, const void *src, u32 src_size); 50 | int se_calc_sha256_finalize(void *hash, u32 *msg_left); 51 | int se_calc_hmac_sha256(void *dst, const void *src, u32 src_size, const void *key, u32 key_size); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /bdk/utils/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2021 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _UTIL_H_ 19 | #define _UTIL_H_ 20 | 21 | #include 22 | #include 23 | 24 | #define NYX_NEW_INFO 0x3058594E 25 | 26 | typedef enum 27 | { 28 | REBOOT_RCM, // PMC reset. Enter RCM mode. 29 | REBOOT_BYPASS_FUSES, // PMC reset via watchdog. Enter Normal mode. Bypass fuse programming in package1. 30 | 31 | POWER_OFF, // Power off PMIC. Do not reset regulators. 32 | POWER_OFF_RESET, // Power off PMIC. Reset regulators. 33 | POWER_OFF_REBOOT, // Power off PMIC. Reset regulators. Power on. 34 | } power_state_t; 35 | 36 | typedef enum 37 | { 38 | NYX_CFG_UMS = BIT(6), 39 | 40 | NYX_CFG_EXTRA = 0xFF << 24 41 | } nyx_cfg_t; 42 | 43 | typedef enum 44 | { 45 | ERR_LIBSYS_LP0 = BIT(0), 46 | ERR_SYSOLD_NYX = BIT(1), 47 | ERR_LIBSYS_MTC = BIT(2), 48 | ERR_SD_BOOT_EN = BIT(3), 49 | ERR_PANIC_CODE = BIT(4), 50 | ERR_L4T_KERNEL = BIT(24), 51 | ERR_EXCEPTION = BIT(31), 52 | } hekate_errors_t; 53 | 54 | typedef struct _cfg_op_t 55 | { 56 | u32 off; 57 | u32 val; 58 | } cfg_op_t; 59 | 60 | typedef struct _nyx_info_t 61 | { 62 | u32 magic; 63 | u32 sd_init; 64 | u32 sd_errors[3]; 65 | u8 rsvd[0x1000]; 66 | u32 disp_id; 67 | u32 errors; 68 | } nyx_info_t; 69 | 70 | typedef struct _nyx_storage_t 71 | { 72 | u32 version; 73 | u32 cfg; 74 | u8 irama[0x8000]; 75 | u8 hekate[0x30000]; 76 | u8 rsvd[SZ_8M - sizeof(nyx_info_t)]; 77 | nyx_info_t info; 78 | mtc_config_t mtc_cfg; 79 | emc_table_t mtc_table[10]; 80 | } nyx_storage_t; 81 | 82 | u8 bit_count(u32 val); 83 | u32 bit_count_mask(u8 bits); 84 | 85 | void exec_cfg(u32 *base, const cfg_op_t *ops, u32 num_ops); 86 | u16 crc16_calc(const u8 *buf, u32 len); 87 | u32 crc32_calc(u32 crc, const u8 *buf, u32 len); 88 | 89 | u32 get_tmr_us(); 90 | u32 get_tmr_ms(); 91 | u32 get_tmr_s(); 92 | void usleep(u32 us); 93 | void msleep(u32 ms); 94 | 95 | void panic(u32 val); 96 | void power_set_state(power_state_t state); 97 | void power_set_state_ex(void *param); 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /source/gfx/gfx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-2021 CTCaer 4 | * Copyright (c) 2019-2021 shchmue 5 | * Copyright (c) 2018 M4xw 6 | * 7 | * This program is free software; you can redistribute it and/or modify it 8 | * under the terms and conditions of the GNU General Public License, 9 | * version 2, as published by the Free Software Foundation. 10 | * 11 | * This program is distributed in the hope it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | * more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _GFX_H_ 21 | #define _GFX_H_ 22 | 23 | #include 24 | 25 | #define EPRINTF(text) gfx_printf("%k"text"%k\n", 0xFFFF0000, 0xFFCCCCCC) 26 | #define EPRINTFARGS(text, args...) gfx_printf("%k"text"%k\n", 0xFFFF0000, args, 0xFFCCCCCC) 27 | #define WPRINTF(text) gfx_printf("%k"text"%k\n", 0xFFFFDD00, 0xFFCCCCCC) 28 | #define WPRINTFARGS(text, args...) gfx_printf("%k"text"%k\n", 0xFFFFDD00, args, 0xFFCCCCCC) 29 | 30 | typedef struct _gfx_ctxt_t 31 | { 32 | u32 *fb; 33 | u32 width; 34 | u32 height; 35 | u32 stride; 36 | } gfx_ctxt_t; 37 | 38 | typedef struct _gfx_con_t 39 | { 40 | gfx_ctxt_t *gfx_ctxt; 41 | u32 fntsz; 42 | u32 x; 43 | u32 y; 44 | u32 savedx; 45 | u32 savedy; 46 | u32 fgcol; 47 | int fillbg; 48 | u32 bgcol; 49 | bool mute; 50 | } gfx_con_t; 51 | 52 | // Global gfx console and context. 53 | extern gfx_ctxt_t gfx_ctxt; 54 | extern gfx_con_t gfx_con; 55 | 56 | void gfx_init_ctxt(u32 *fb, u32 width, u32 height, u32 stride); 57 | void gfx_clear_grey(u8 color); 58 | void gfx_clear_partial_grey(u8 color, u32 pos_x, u32 height); 59 | void gfx_clear_color(u32 color); 60 | void gfx_con_init(); 61 | void gfx_con_setcol(u32 fgcol, int fillbg, u32 bgcol); 62 | void gfx_con_getpos(u32 *x, u32 *y); 63 | void gfx_con_setpos(u32 x, u32 y); 64 | void gfx_putc(char c); 65 | void gfx_puts(const char *s); 66 | void gfx_printf(const char *fmt, ...); 67 | void gfx_hexdump(u32 base, const void *buf, u32 len); 68 | void gfx_hexdiff(u32 base, const void *buf1, const void *buf2, u32 len); 69 | 70 | void gfx_set_pixel(u32 x, u32 y, u32 color); 71 | void gfx_line(int x0, int y0, int x1, int y1, u32 color); 72 | void gfx_put_small_sep(); 73 | void gfx_put_big_sep(); 74 | void gfx_set_rect_grey(const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); 75 | void gfx_set_rect_rgb(const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); 76 | void gfx_set_rect_argb(const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); 77 | void gfx_render_bmp_argb(const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /bdk/soc/gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2019 CTCaer 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef _GPIO_H_ 19 | #define _GPIO_H_ 20 | 21 | #include 22 | 23 | #define GPIO_MODE_SPIO 0 24 | #define GPIO_MODE_GPIO 1 25 | 26 | #define GPIO_OUTPUT_DISABLE 0 27 | #define GPIO_OUTPUT_ENABLE 1 28 | 29 | #define GPIO_IRQ_DISABLE 0 30 | #define GPIO_IRQ_ENABLE 1 31 | 32 | #define GPIO_LOW 0 33 | #define GPIO_HIGH 1 34 | #define GPIO_FALLING 0 35 | #define GPIO_RISING 1 36 | 37 | #define GPIO_LEVEL 0 38 | #define GPIO_EDGE 1 39 | 40 | #define GPIO_CONFIGURED_EDGE 0 41 | #define GPIO_ANY_EDGE_CHANGE 1 42 | 43 | /*! GPIO pins (0-7 for each port). */ 44 | #define GPIO_PIN_0 BIT(0) 45 | #define GPIO_PIN_1 BIT(1) 46 | #define GPIO_PIN_2 BIT(2) 47 | #define GPIO_PIN_3 BIT(3) 48 | #define GPIO_PIN_4 BIT(4) 49 | #define GPIO_PIN_5 BIT(5) 50 | #define GPIO_PIN_6 BIT(6) 51 | #define GPIO_PIN_7 BIT(7) 52 | 53 | /*! GPIO ports (A-EE). */ 54 | #define GPIO_PORT_A 0 55 | #define GPIO_PORT_B 1 56 | #define GPIO_PORT_C 2 57 | #define GPIO_PORT_D 3 58 | #define GPIO_PORT_E 4 59 | #define GPIO_PORT_F 5 60 | #define GPIO_PORT_G 6 61 | #define GPIO_PORT_H 7 62 | #define GPIO_PORT_I 8 63 | #define GPIO_PORT_J 9 64 | #define GPIO_PORT_K 10 65 | #define GPIO_PORT_L 11 66 | #define GPIO_PORT_M 12 67 | #define GPIO_PORT_N 13 68 | #define GPIO_PORT_O 14 69 | #define GPIO_PORT_P 15 70 | #define GPIO_PORT_Q 16 71 | #define GPIO_PORT_R 17 72 | #define GPIO_PORT_S 18 73 | #define GPIO_PORT_T 19 74 | #define GPIO_PORT_U 20 75 | #define GPIO_PORT_V 21 76 | #define GPIO_PORT_W 22 77 | #define GPIO_PORT_X 23 78 | #define GPIO_PORT_Y 24 79 | #define GPIO_PORT_Z 25 80 | #define GPIO_PORT_AA 26 81 | #define GPIO_PORT_BB 27 82 | #define GPIO_PORT_CC 28 83 | #define GPIO_PORT_DD 29 84 | #define GPIO_PORT_EE 30 85 | 86 | void gpio_config(u32 port, u32 pins, int mode); 87 | void gpio_output_enable(u32 port, u32 pins, int enable); 88 | void gpio_write(u32 port, u32 pins, int high); 89 | int gpio_read(u32 port, u32 pins); 90 | int gpio_interrupt_status(u32 port, u32 pins); 91 | void gpio_interrupt_enable(u32 port, u32 pins, int enable); 92 | void gpio_interrupt_level(u32 port, u32 pins, int high, int edge, int delta); 93 | u32 gpio_get_bank_irq_id(u32 port); 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /bdk/utils/dirlist.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 CTCaer 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #define MAX_ENTRIES 64 25 | 26 | char *dirlist(const char *directory, const char *pattern, bool includeHiddenFiles, bool parse_dirs) 27 | { 28 | int res = 0; 29 | u32 i = 0, j = 0, k = 0; 30 | DIR dir; 31 | FILINFO fno; 32 | 33 | char *dir_entries = (char *)calloc(MAX_ENTRIES, 256); 34 | char *temp = (char *)calloc(1, 256); 35 | 36 | if (!pattern && !f_opendir(&dir, directory)) 37 | { 38 | for (;;) 39 | { 40 | res = f_readdir(&dir, &fno); 41 | if (res || !fno.fname[0]) 42 | break; 43 | 44 | bool curr_parse = parse_dirs ? (fno.fattrib & AM_DIR) : !(fno.fattrib & AM_DIR); 45 | 46 | if (curr_parse) 47 | { 48 | if ((fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID))) 49 | { 50 | strcpy(dir_entries + (k * 256), fno.fname); 51 | k++; 52 | if (k > (MAX_ENTRIES - 1)) 53 | break; 54 | } 55 | } 56 | } 57 | f_closedir(&dir); 58 | } 59 | else if (pattern && !f_findfirst(&dir, &fno, directory, pattern) && fno.fname[0]) 60 | { 61 | do 62 | { 63 | if (!(fno.fattrib & AM_DIR) && (fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID))) 64 | { 65 | strcpy(dir_entries + (k * 256), fno.fname); 66 | k++; 67 | if (k > (MAX_ENTRIES - 1)) 68 | break; 69 | } 70 | res = f_findnext(&dir, &fno); 71 | } while (fno.fname[0] && !res); 72 | f_closedir(&dir); 73 | } 74 | 75 | if (!k) 76 | { 77 | free(temp); 78 | free(dir_entries); 79 | 80 | return NULL; 81 | } 82 | 83 | // Reorder ini files by ASCII ordering. 84 | for (i = 0; i < k - 1 ; i++) 85 | { 86 | for (j = i + 1; j < k; j++) 87 | { 88 | if (strcmp(&dir_entries[i * 256], &dir_entries[j * 256]) > 0) 89 | { 90 | strcpy(temp, &dir_entries[i * 256]); 91 | strcpy(&dir_entries[i * 256], &dir_entries[j * 256]); 92 | strcpy(&dir_entries[j * 256], temp); 93 | } 94 | } 95 | } 96 | 97 | free(temp); 98 | 99 | return dir_entries; 100 | } 101 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_objx/lv_led.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_led.h 3 | * 4 | */ 5 | 6 | #ifndef LV_LED_H 7 | #define LV_LED_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "../../lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_LED != 0 23 | 24 | #include "../lv_core/lv_obj.h" 25 | 26 | /********************* 27 | * DEFINES 28 | *********************/ 29 | 30 | /********************** 31 | * TYPEDEFS 32 | **********************/ 33 | 34 | /*Data of led*/ 35 | typedef struct 36 | { 37 | /*No inherited ext.*/ 38 | /*New data for this type */ 39 | uint8_t bright; /*Current brightness of the LED (0..255)*/ 40 | } lv_led_ext_t; 41 | 42 | /********************** 43 | * GLOBAL PROTOTYPES 44 | **********************/ 45 | 46 | /** 47 | * Create a led objects 48 | * @param par pointer to an object, it will be the parent of the new led 49 | * @param copy pointer to a led object, if not NULL then the new object will be copied from it 50 | * @return pointer to the created led 51 | */ 52 | lv_obj_t * lv_led_create(lv_obj_t * par, const lv_obj_t * copy); 53 | 54 | /** 55 | * Set the brightness of a LED object 56 | * @param led pointer to a LED object 57 | * @param bright 0 (max. dark) ... 255 (max. light) 58 | */ 59 | void lv_led_set_bright(lv_obj_t * led, uint8_t bright); 60 | 61 | /** 62 | * Light on a LED 63 | * @param led pointer to a LED object 64 | */ 65 | void lv_led_on(lv_obj_t * led); 66 | 67 | /** 68 | * Light off a LED 69 | * @param led pointer to a LED object 70 | */ 71 | void lv_led_off(lv_obj_t * led); 72 | 73 | /** 74 | * Toggle the state of a LED 75 | * @param led pointer to a LED object 76 | */ 77 | void lv_led_toggle(lv_obj_t * led); 78 | 79 | /** 80 | * Set the style of a led 81 | * @param led pointer to a led object 82 | * @param style pointer to a style 83 | */ 84 | static inline void lv_led_set_style(lv_obj_t *led, lv_style_t *style) 85 | { 86 | lv_obj_set_style(led, style); 87 | } 88 | 89 | /** 90 | * Get the brightness of a LEd object 91 | * @param led pointer to LED object 92 | * @return bright 0 (max. dark) ... 255 (max. light) 93 | */ 94 | uint8_t lv_led_get_bright(const lv_obj_t * led); 95 | 96 | /** 97 | * Get the style of an led object 98 | * @param led pointer to an led object 99 | * @return pointer to the led's style 100 | */ 101 | static inline lv_style_t* lv_led_get_style(const lv_obj_t *led) 102 | { 103 | return lv_obj_get_style(led); 104 | } 105 | 106 | /********************** 107 | * MACROS 108 | **********************/ 109 | 110 | #endif /*USE_LV_LED*/ 111 | 112 | #ifdef __cplusplus 113 | } /* extern "C" */ 114 | #endif 115 | 116 | #endif /*LV_LED_H*/ 117 | -------------------------------------------------------------------------------- /bdk/libs/nx_savedata/journal_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020 shchmue 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /* 18 | ISC License 19 | 20 | hactool Copyright (c) 2018, SciresM 21 | 22 | Permission to use, copy, modify, and/or distribute this software for any 23 | purpose with or without fee is hereby granted, provided that the above 24 | copyright notice and this permission notice appear in all copies. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 27 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 28 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 29 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 30 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 31 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 32 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 | */ 34 | 35 | #ifndef _JOURNAL_MAP_H_ 36 | #define _JOURNAL_MAP_H_ 37 | 38 | #include "storage.h" 39 | 40 | #include 41 | 42 | #include 43 | 44 | #define JOURNAL_MAP_ENTRY_SIZE 8 45 | 46 | typedef struct { 47 | uint32_t version; 48 | uint32_t main_data_block_count; 49 | uint32_t journal_block_count; 50 | uint32_t _0x0C; 51 | } journal_map_header_t; 52 | 53 | typedef struct { 54 | uint8_t *map_storage; 55 | uint8_t *physical_block_bitmap; 56 | uint8_t *virtual_block_bitmap; 57 | uint8_t *free_block_bitmap; 58 | } journal_map_params_t; 59 | 60 | typedef struct { 61 | uint32_t physical_index; 62 | uint32_t virtual_index; 63 | } journal_map_entry_t; 64 | 65 | typedef struct { 66 | journal_map_header_t *header; 67 | journal_map_entry_t *entries; 68 | uint8_t *map_storage; 69 | uint8_t *modified_physical_blocks; 70 | uint8_t *modified_virtual_blocks; 71 | uint8_t *free_blocks; 72 | } journal_map_ctx_t; 73 | 74 | static ALWAYS_INLINE uint32_t save_journal_map_entry_make_physical_index(uint32_t index) { 75 | return index | 0x80000000; 76 | } 77 | 78 | static ALWAYS_INLINE uint32_t save_journal_map_entry_get_physical_index(uint32_t index) { 79 | return index & 0x7FFFFFFF; 80 | } 81 | 82 | void save_journal_map_init(journal_map_ctx_t *ctx, journal_map_header_t *header, journal_map_params_t *map_info); 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /bdk/libs/lvgl/lv_objx/lv_objx_templ.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_templ.h 3 | * 4 | */ 5 | 6 | 7 | /* TODO Remove these instructions 8 | * Search an replace: template -> object normal name with lower case (e.g. button, label etc.) 9 | * templ -> object short name with lower case(e.g. btn, label etc) 10 | * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) 11 | * 12 | */ 13 | 14 | #ifndef LV_TEMPL_H 15 | #define LV_TEMPL_H 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /********************* 22 | * INCLUDES 23 | *********************/ 24 | #ifdef LV_CONF_INCLUDE_SIMPLE 25 | #include "lv_conf.h" 26 | #else 27 | #include "../../lv_conf.h" 28 | #endif 29 | 30 | #if USE_LV_TEMPL != 0 31 | 32 | #include "../lv_core/lv_obj.h" 33 | 34 | /********************* 35 | * DEFINES 36 | *********************/ 37 | 38 | /********************** 39 | * TYPEDEFS 40 | **********************/ 41 | /*Data of template*/ 42 | typedef struct { 43 | lv_ANCESTOR_ext_t ANCESTOR; /*Ext. of ancestor*/ 44 | /*New data for this type */ 45 | } lv_templ_ext_t; 46 | 47 | 48 | /*Styles*/ 49 | enum { 50 | LV_TEMPL_STYLE_X, 51 | LV_TEMPL_STYLE_Y, 52 | }; 53 | typedef uint8_t lv_templ_style_t; 54 | 55 | 56 | /********************** 57 | * GLOBAL PROTOTYPES 58 | **********************/ 59 | 60 | /** 61 | * Create a template objects 62 | * @param par pointer to an object, it will be the parent of the new template 63 | * @param copy pointer to a template object, if not NULL then the new object will be copied from it 64 | * @return pointer to the created template 65 | */ 66 | lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy); 67 | 68 | /*====================== 69 | * Add/remove functions 70 | *=====================*/ 71 | 72 | 73 | /*===================== 74 | * Setter functions 75 | *====================*/ 76 | 77 | /** 78 | * Set a style of a template. 79 | * @param templ pointer to template object 80 | * @param type which style should be set 81 | * @param style pointer to a style 82 | */ 83 | void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, lv_style_t *style); 84 | 85 | /*===================== 86 | * Getter functions 87 | *====================*/ 88 | 89 | /** 90 | * Get style of a template. 91 | * @param templ pointer to template object 92 | * @param type which style should be get 93 | * @return style pointer to the style 94 | */ 95 | lv_style_t * lv_templ_get_style(const lv_obj_t * templ, lv_templ_style_t type); 96 | 97 | /*===================== 98 | * Other functions 99 | *====================*/ 100 | 101 | /********************** 102 | * MACROS 103 | **********************/ 104 | 105 | #endif /*USE_LV_TEMPL*/ 106 | 107 | #ifdef __cplusplus 108 | } /* extern "C" */ 109 | #endif 110 | 111 | #endif /*LV_TEMPL_H*/ 112 | --------------------------------------------------------------------------------