├── .github └── workflows │ └── builder.yml ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── bdk ├── display │ ├── di.c │ ├── di.h │ └── di.inl ├── exception_handlers.S ├── fatfs_cfg.h ├── gfx_utils.h ├── ianos │ ├── elfload │ │ ├── elf.h │ │ ├── elfarch.h │ │ ├── elfload.c │ │ ├── elfload.h │ │ ├── elfreloc_aarch64.c │ │ └── elfreloc_arm.c │ ├── ianos.c │ └── ianos.h ├── input │ ├── als.c │ ├── als.h │ ├── joycon.c │ ├── joycon.h │ ├── touch.c │ └── touch.h ├── libs │ ├── compr │ │ ├── blz.c │ │ ├── blz.h │ │ ├── lz.c │ │ ├── lz.h │ │ ├── lz4.c │ │ └── lz4.h │ ├── fatfs │ │ ├── diskio.h │ │ ├── ff.c │ │ ├── ff.h │ │ └── ffunicode.c │ ├── lv_conf.h │ ├── lvgl │ │ ├── docs │ │ │ ├── CODE_OF_CONDUCT.md │ │ │ ├── CONTRIBUTING.md │ │ │ ├── astyle_c │ │ │ └── astyle_h │ │ ├── licence.txt │ │ ├── lv_core │ │ │ ├── lv_core.mk │ │ │ ├── lv_group.c │ │ │ ├── lv_group.h │ │ │ ├── lv_indev.c │ │ │ ├── lv_indev.h │ │ │ ├── lv_lang.c │ │ │ ├── lv_lang.h │ │ │ ├── lv_obj.c │ │ │ ├── lv_obj.h │ │ │ ├── lv_refr.c │ │ │ ├── lv_refr.h │ │ │ ├── lv_style.c │ │ │ ├── lv_style.h │ │ │ ├── lv_vdb.c │ │ │ └── lv_vdb.h │ │ ├── lv_draw │ │ │ ├── lv_draw.c │ │ │ ├── lv_draw.h │ │ │ ├── lv_draw.mk │ │ │ ├── lv_draw_arc.c │ │ │ ├── lv_draw_arc.h │ │ │ ├── lv_draw_img.c │ │ │ ├── lv_draw_img.h │ │ │ ├── lv_draw_label.c │ │ │ ├── lv_draw_label.h │ │ │ ├── lv_draw_line.c │ │ │ ├── lv_draw_line.h │ │ │ ├── lv_draw_rbasic.c │ │ │ ├── lv_draw_rbasic.h │ │ │ ├── lv_draw_rect.c │ │ │ ├── lv_draw_rect.h │ │ │ ├── lv_draw_triangle.c │ │ │ ├── lv_draw_triangle.h │ │ │ ├── lv_draw_vbasic.c │ │ │ └── lv_draw_vbasic.h │ │ ├── lv_fonts │ │ │ ├── hekate_symbol_120.c │ │ │ ├── hekate_symbol_20.c │ │ │ ├── hekate_symbol_30.c │ │ │ ├── interui_20.c │ │ │ ├── interui_30.c │ │ │ ├── lv_font_builtin.c │ │ │ ├── lv_font_builtin.h │ │ │ ├── lv_fonts.mk │ │ │ └── ubuntu_mono.c │ │ ├── lv_hal │ │ │ ├── lv_hal.h │ │ │ ├── lv_hal.mk │ │ │ ├── lv_hal_disp.c │ │ │ ├── lv_hal_disp.h │ │ │ ├── lv_hal_indev.c │ │ │ ├── lv_hal_indev.h │ │ │ ├── lv_hal_tick.c │ │ │ └── lv_hal_tick.h │ │ ├── lv_misc │ │ │ ├── lv_anim.c │ │ │ ├── lv_anim.h │ │ │ ├── lv_area.c │ │ │ ├── lv_area.h │ │ │ ├── lv_circ.c │ │ │ ├── lv_circ.h │ │ │ ├── lv_color.c │ │ │ ├── lv_color.h │ │ │ ├── lv_font.c │ │ │ ├── lv_font.h │ │ │ ├── lv_fs.c │ │ │ ├── lv_fs.h │ │ │ ├── lv_gc.c │ │ │ ├── lv_gc.h │ │ │ ├── lv_ll.c │ │ │ ├── lv_ll.h │ │ │ ├── lv_log.c │ │ │ ├── lv_log.h │ │ │ ├── lv_math.c │ │ │ ├── lv_math.h │ │ │ ├── lv_mem.c │ │ │ ├── lv_mem.h │ │ │ ├── lv_misc.mk │ │ │ ├── lv_symbol_def.h │ │ │ ├── lv_task.c │ │ │ ├── lv_task.h │ │ │ ├── lv_templ.c │ │ │ ├── lv_templ.h │ │ │ ├── lv_txt.c │ │ │ ├── lv_txt.h │ │ │ ├── lv_ufs.c │ │ │ └── lv_ufs.h │ │ ├── lv_objx │ │ │ ├── lv_arc.c │ │ │ ├── lv_arc.h │ │ │ ├── lv_bar.c │ │ │ ├── lv_bar.h │ │ │ ├── lv_btn.c │ │ │ ├── lv_btn.h │ │ │ ├── lv_btnm.c │ │ │ ├── lv_btnm.h │ │ │ ├── lv_calendar.c │ │ │ ├── lv_calendar.h │ │ │ ├── lv_canvas.c │ │ │ ├── lv_canvas.h │ │ │ ├── lv_cb.c │ │ │ ├── lv_cb.h │ │ │ ├── lv_chart.c │ │ │ ├── lv_chart.h │ │ │ ├── lv_cont.c │ │ │ ├── lv_cont.h │ │ │ ├── lv_ddlist.c │ │ │ ├── lv_ddlist.h │ │ │ ├── lv_gauge.c │ │ │ ├── lv_gauge.h │ │ │ ├── lv_img.c │ │ │ ├── lv_img.h │ │ │ ├── lv_imgbtn.c │ │ │ ├── lv_imgbtn.h │ │ │ ├── lv_kb.c │ │ │ ├── lv_kb.h │ │ │ ├── lv_label.c │ │ │ ├── lv_label.h │ │ │ ├── lv_led.c │ │ │ ├── lv_led.h │ │ │ ├── lv_line.c │ │ │ ├── lv_line.h │ │ │ ├── lv_list.c │ │ │ ├── lv_list.h │ │ │ ├── lv_lmeter.c │ │ │ ├── lv_lmeter.h │ │ │ ├── lv_mbox.c │ │ │ ├── lv_mbox.h │ │ │ ├── lv_objx.mk │ │ │ ├── lv_objx_templ.c │ │ │ ├── lv_objx_templ.h │ │ │ ├── lv_page.c │ │ │ ├── lv_page.h │ │ │ ├── lv_preload.c │ │ │ ├── lv_preload.h │ │ │ ├── lv_roller.c │ │ │ ├── lv_roller.h │ │ │ ├── lv_slider.c │ │ │ ├── lv_slider.h │ │ │ ├── lv_spinbox.c │ │ │ ├── lv_spinbox.h │ │ │ ├── lv_sw.c │ │ │ ├── lv_sw.h │ │ │ ├── lv_ta.c │ │ │ ├── lv_ta.h │ │ │ ├── lv_table.c │ │ │ ├── lv_table.h │ │ │ ├── lv_tabview.c │ │ │ ├── lv_tabview.h │ │ │ ├── lv_tileview.c │ │ │ ├── lv_tileview.h │ │ │ ├── lv_win.c │ │ │ └── lv_win.h │ │ ├── lv_themes │ │ │ ├── lv_theme.c │ │ │ ├── lv_theme.h │ │ │ ├── lv_theme_hekate.c │ │ │ ├── lv_theme_hekate.h │ │ │ └── lv_themes.mk │ │ ├── lv_version.h │ │ ├── lvgl.h │ │ └── lvgl.mk │ └── nx_savedata │ │ ├── allocation_table.c │ │ ├── allocation_table.h │ │ ├── allocation_table_iterator.c │ │ ├── allocation_table_iterator.h │ │ ├── allocation_table_storage.c │ │ ├── allocation_table_storage.h │ │ ├── cached_storage.c │ │ ├── cached_storage.h │ │ ├── directory_entry.h │ │ ├── duplex_storage.c │ │ ├── duplex_storage.h │ │ ├── fs_int64.h │ │ ├── header.h │ │ ├── hierarchical_duplex_storage.c │ │ ├── hierarchical_duplex_storage.h │ │ ├── hierarchical_integrity_verification_storage.c │ │ ├── hierarchical_integrity_verification_storage.h │ │ ├── hierarchical_save_file_table.c │ │ ├── hierarchical_save_file_table.h │ │ ├── integrity_verification_storage.c │ │ ├── integrity_verification_storage.h │ │ ├── journal_map.c │ │ ├── journal_map.h │ │ ├── journal_storage.c │ │ ├── journal_storage.h │ │ ├── path_parser.c │ │ ├── path_parser.h │ │ ├── remap_storage.c │ │ ├── remap_storage.h │ │ ├── save.c │ │ ├── save.h │ │ ├── save_data_directory.c │ │ ├── save_data_directory.h │ │ ├── save_data_file.c │ │ ├── save_data_file.h │ │ ├── save_data_file_system_core.c │ │ ├── save_data_file_system_core.h │ │ ├── save_fs_entry.h │ │ ├── save_fs_list.c │ │ ├── save_fs_list.h │ │ ├── storage.c │ │ └── storage.h ├── mem │ ├── emc.h │ ├── heap.c │ ├── heap.h │ ├── mc.c │ ├── mc.h │ ├── mc_t210.h │ ├── minerva.c │ ├── minerva.h │ ├── mtc_table.h │ ├── sdram.c │ ├── sdram.h │ ├── sdram_config.inl │ ├── sdram_config_lz.inl │ ├── sdram_config_t210b01.inl │ ├── sdram_lp0.c │ ├── sdram_lp0_param_t210.h │ ├── sdram_lp0_param_t210b01.h │ ├── sdram_param_t210.h │ ├── sdram_param_t210b01.h │ ├── smmu.c │ └── smmu.h ├── memory_map.h ├── module.h ├── power │ ├── bm92t36.c │ ├── bm92t36.h │ ├── bq24193.c │ ├── bq24193.h │ ├── max17050.c │ ├── max17050.h │ ├── max77620.h │ ├── max7762x.c │ ├── max7762x.h │ ├── max77812.h │ ├── regulator_5v.c │ └── regulator_5v.h ├── rtc │ ├── max77620-rtc.c │ └── max77620-rtc.h ├── sec │ ├── se.c │ ├── se.h │ ├── se_t210.h │ ├── tsec.c │ ├── tsec.h │ └── tsec_t210.h ├── soc │ ├── bpmp.c │ ├── bpmp.h │ ├── ccplex.c │ ├── ccplex.h │ ├── clock.c │ ├── clock.h │ ├── fuse.c │ ├── fuse.h │ ├── gpio.c │ ├── gpio.h │ ├── hw_init.c │ ├── hw_init.h │ ├── i2c.c │ ├── i2c.h │ ├── irq.c │ ├── irq.h │ ├── kfuse.c │ ├── kfuse.h │ ├── pinmux.c │ ├── pinmux.h │ ├── pmc.c │ ├── pmc.h │ ├── pmc_lp0_t210.h │ ├── t210.h │ ├── uart.c │ └── uart.h ├── storage │ ├── mbr_gpt.h │ ├── mmc.h │ ├── nx_sd.h │ ├── ramdisk.c │ ├── ramdisk.h │ ├── sd.h │ ├── sdmmc.c │ ├── sdmmc.h │ ├── sdmmc_driver.c │ ├── sdmmc_driver.h │ └── sdmmc_t210.h ├── thermal │ ├── fan.c │ ├── fan.h │ ├── tmp451.c │ └── tmp451.h ├── usb │ ├── usb_descriptor_types.h │ ├── usb_descriptors.c │ ├── usb_gadget_hid.c │ ├── usb_gadget_ums.c │ ├── usb_t210.h │ ├── usbd.c │ ├── usbd.h │ └── xusbd.c └── utils │ ├── aarch64_util.h │ ├── btn.c │ ├── btn.h │ ├── dirlist.c │ ├── dirlist.h │ ├── ini.c │ ├── ini.h │ ├── list.h │ ├── sprintf.c │ ├── sprintf.h │ ├── types.h │ ├── util.c │ └── util.h └── source ├── config.c ├── config.h ├── cpr ├── cpr.c └── cpr.h ├── err.c ├── err.h ├── fs ├── fscopy.c ├── fscopy.h ├── fstypes.h ├── fsutils.c ├── fsutils.h ├── menus │ ├── explorer.c │ ├── explorer.h │ ├── filemenu.c │ ├── filemenu.h │ ├── foldermenu.c │ └── foldermenu.h └── readers │ ├── folderReader.c │ └── folderReader.h ├── gfx ├── gfx.c ├── gfx.h ├── gfxutils.c ├── gfxutils.h ├── menu.c └── menu.h ├── hid ├── hid.c └── hid.h ├── hos ├── fss.c ├── fss.h ├── hos.h ├── pkg1.c ├── pkg1.h ├── pkg2.c ├── pkg2.h ├── sept.c └── sept.h ├── keys ├── key_sources.inl ├── keyfile.c ├── keyfile.h ├── keys.c ├── keys.h ├── nca.c ├── nca.h ├── save.c └── save.h ├── libs └── fatfs │ ├── diskio.c │ ├── ffconf.h │ └── ffsystem.c ├── link.ld ├── main.c ├── script ├── args.c ├── args.h ├── functions.c ├── functions.h ├── lexer.c ├── lexer.h ├── parser.c ├── parser.h ├── types.h ├── variables.c └── variables.h ├── start.S ├── storage ├── emmcfile.c ├── emmcfile.h ├── emummc.c ├── emummc.h ├── gptmenu.c ├── gptmenu.h ├── mountmanager.c ├── mountmanager.h ├── nx_emmc.c ├── nx_emmc.h ├── nx_emmc_bis.c ├── nx_emmc_bis.h └── nx_sd.c ├── tegraexplorer ├── mainmenu.c ├── mainmenu.h ├── tconf.c ├── tconf.h ├── tools.c └── tools.h └── utils ├── utils.c ├── utils.h ├── vector.c └── vector.h /.github/workflows/builder.yml: -------------------------------------------------------------------------------- 1 | name: PCR builder 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | container: devkitpro/devkita64_devkitarm 9 | 10 | steps: 11 | - uses: actions/checkout@v1 12 | 13 | - name: Build PCR 14 | run: make -j$(nproc) 15 | 16 | - uses: actions/upload-artifact@master 17 | with: 18 | name: CommonProblemResolver 19 | path: output/CommonProblemResolver.bin 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | build 3 | output 4 | research 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CommonProblemResolver (CPR) 2 | 3 | Rescue your switch without a pc! 4 | 5 | ## Usage 6 | 1. Get your favorite payload injector 7 | 2. Inject CPR as a payload 8 | 9 | Navigate around the menus using the joycons. 10 | - A: Select 11 | - B: Back 12 | - Left Joystick up/down (Dpad or joystick): navigate menus up/down 13 | - Right Joystick up/down: fast menu navigation up/down 14 | - Capture (Minerva only): Take a screenshot 15 | - L3/R3 (Press joysticks in): Recalibrate centerpoint 16 | 17 | If you do not have your joycons connected: 18 | - Power -> A 19 | - Vol+ -> Left Joystick up 20 | - Vol- -> Left Joystick down 21 | 22 | ## Functions 23 | - Disables all sysmodules on your switch (might fix booting issues after update) 24 | - Delete installed themes (will fix booting issues after update) 25 | - Reverts changes made by clingwrap 26 | 27 | ## Support 28 | 29 | Join [our discord](https://discord.gg/VkaRjYN) for help. 30 | 31 | ## Credits 32 | 33 | This is heavily based on [TegraExplorer](https://github.com/suchmememanyskill/TegraExplorer) by suchmememanyskill, 34 | which itself is based on [Lockpick_RCM](https://github.com/shchmue/Lockpick_RCM), and thus also based on [Hekate](https://github.com/CTCaer/hekate) 35 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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_table_t 52 | { 53 | float lux; 54 | bool over_limit; 55 | u32 vi_light; 56 | u32 ir_light; 57 | u8 gain; 58 | u8 itime; 59 | } als_table_t; 60 | 61 | void set_als_cfg(als_table_t *als_val, u8 gain, u8 itime); 62 | void get_als_lux(als_table_t *als_val); 63 | u8 als_init(als_table_t *als_val); 64 | 65 | #endif /* __ALS_H_ */ 66 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/docs/astyle_h: -------------------------------------------------------------------------------- 1 | --convert-tabs --indent=spaces=4 2 | -------------------------------------------------------------------------------- /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/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/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/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_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_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/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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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_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_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_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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 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 | -------------------------------------------------------------------------------- /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/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_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.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/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 | -------------------------------------------------------------------------------- /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/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/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/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_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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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(); 27 | void mc_disable_ahb_redirect(); 28 | void mc_enable(); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /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 | s32 rate_to; 31 | s32 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_periodic_training(); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /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 | // Module Callback 25 | typedef void (*cbMainModule_t)(const char *s); 26 | typedef void (*memcpy_t)(void *, void *, size_t); 27 | typedef void (*memset_t)(void *, int, size_t); 28 | 29 | typedef struct _bdkParams_t 30 | { 31 | void *gfxCon; 32 | void *gfxCtx; 33 | heap_t *sharedHeap; 34 | memcpy_t memcpy; 35 | memset_t memset; 36 | } *bdkParams_t; 37 | 38 | // Module Entrypoint 39 | typedef void (*moduleEntrypoint_t)(void *, bdkParams_t); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /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/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_batt_src_enable(bool enable); 34 | 35 | #endif -------------------------------------------------------------------------------- /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/sec/se.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 _SE_H_ 18 | #define _SE_H_ 19 | 20 | #include 21 | 22 | void se_rsa_acc_ctrl(u32 rs, u32 flags); 23 | void se_rsa_key_set(u32 ks, const void *mod, u32 mod_size, const void *exp, u32 exp_size); 24 | void se_rsa_key_clear(u32 ks); 25 | int se_rsa_exp_mod(u32 ks, void *dst, u32 dst_size, const void *src, u32 src_size); 26 | void se_key_acc_ctrl(u32 ks, u32 flags); 27 | u32 se_key_acc_ctrl_get(u32 ks); 28 | void se_aes_key_set(u32 ks, const void *key, u32 size); 29 | void se_aes_iv_set(u32 ks, const void *iv); 30 | void se_aes_key_partial_set(u32 ks, u32 index, u32 data); 31 | void se_aes_key_get(u32 ks, void *key, u32 size); 32 | void se_aes_key_clear(u32 ks); 33 | void se_aes_iv_clear(u32 ks); 34 | int se_initialize_rng(); 35 | int se_generate_random(void *dst, u32 size); 36 | int se_generate_random_key(u32 ks_dst, u32 ks_src); 37 | int se_aes_unwrap_key(u32 ks_dst, u32 ks_src, const void *input); 38 | int se_aes_crypt_ecb(u32 ks, u32 enc, void *dst, u32 dst_size, const void *src, u32 src_size); 39 | int se_aes_crypt_block_ecb(u32 ks, u32 enc, void *dst, const void *src); 40 | int se_aes_crypt_ctr(u32 ks, void *dst, u32 dst_size, const void *src, u32 src_size, void *ctr); 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_xts_crypt_sec(u32 tweak_ks, u32 crypt_ks, u32 enc, u64 sec, void *dst, const void *src, u32 sec_size); 43 | 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); 44 | int se_aes_cmac(u32 ks, void *dst, u32 dst_size, const void *src, u32 src_size); 45 | int se_calc_sha256(void *hash, u32 *msg_left, const void *src, u32 src_size, u64 total_size, u32 sha_cfg, bool is_oneshot); 46 | int se_calc_sha256_oneshot(void *hash, const void *src, u32 src_size); 47 | int se_calc_sha256_finalize(void *hash, u32 *msg_left); 48 | int se_calc_hmac_sha256(void *dst, const void *src, u32 src_size, const void *key, u32 key_size); 49 | u32 se_rsa_oaep_decode(void *dst, u32 dst_size, const void *label_digest, u32 label_digest_size, u8 *buf, u32 buf_size); 50 | void se_get_aes_keys(u8 *buf, u8 *keys, u32 keysize); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /bdk/sec/tsec.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 _TSEC_H_ 19 | #define _TSEC_H_ 20 | 21 | #include 22 | 23 | #define TSEC_KEY_DATA_OFFSET 0x300 24 | 25 | typedef struct _tsec_ctxt_t 26 | { 27 | void *fw; 28 | u32 size; 29 | void *pkg1; 30 | } tsec_ctxt_t; 31 | 32 | typedef struct _tsec_key_data_t 33 | { 34 | u8 debug_key[0x10]; 35 | u8 blob0_auth_hash[0x10]; 36 | u8 blob1_auth_hash[0x10]; 37 | u8 blob2_auth_hash[0x10]; 38 | u8 blob2_aes_iv[0x10]; 39 | u8 hovi_eks_seed[0x10]; 40 | u8 hovi_common_seed[0x10]; 41 | u32 blob0_size; 42 | u32 blob1_size; 43 | u32 blob2_size; 44 | u32 blob3_size; 45 | u32 blob4_size; 46 | u8 reserved[0x7C]; 47 | } tsec_key_data_t; 48 | 49 | int tsec_query(u8 *tsec_keys, u8 kb, tsec_ctxt_t *tsec_ctxt); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /bdk/soc/bpmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BPMP-Lite Cache/MMU and Frequency driver for Tegra X1 3 | * 4 | * Copyright (c) 2019-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 _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_DEFAULT_BOOST BPMP_CLK_HYPER_BOOST 57 | 58 | void bpmp_mmu_maintenance(u32 op, bool force); 59 | void bpmp_mmu_set_entry(int idx, bpmp_mmu_entry_t *entry, bool apply); 60 | void bpmp_mmu_enable(); 61 | void bpmp_mmu_disable(); 62 | void bpmp_clk_rate_get(); 63 | void bpmp_clk_rate_set(bpmp_freq_t fid); 64 | void bpmp_usleep(u32 us); 65 | void bpmp_msleep(u32 ms); 66 | void bpmp_halt(); 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/soc/hw_init.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 _HW_INIT_H_ 19 | #define _HW_INIT_H_ 20 | 21 | #include 22 | 23 | void hw_init(); 24 | void hw_reinit_workaround(bool coreboot, u32 magic); 25 | u32 hw_get_chip_id(); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /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/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/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/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/soc/uart.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 _UART_H_ 19 | #define _UART_H_ 20 | 21 | #include 22 | 23 | #define UART_A 0 24 | #define UART_B 1 25 | #define UART_C 2 26 | #define UART_D 3 27 | #define UART_E 4 28 | 29 | #define BAUD_115200 115200 30 | 31 | #define UART_TX_IDLE 0x1 32 | #define UART_RX_IDLE 0x2 33 | 34 | #define UART_TX_FIFO_FULL 0x100 35 | #define UART_RX_FIFO_EMPTY 0x200 36 | 37 | #define UART_INVERT_RXD 0x01 38 | #define UART_INVERT_TXD 0x02 39 | #define UART_INVERT_CTS 0x04 40 | #define UART_INVERT_RTS 0x08 41 | 42 | #define UART_IER_DLAB_IE_EORD 0x20 43 | 44 | #define UART_LCR_DLAB 0x80 45 | #define UART_LCR_STOP 0x4 46 | #define UART_LCR_WORD_LENGTH_8 0x3 47 | 48 | #define UART_LSR_RDR 0x1 49 | #define UART_LSR_THRE 0x20 50 | #define UART_LSR_TMTY 0x40 51 | #define UART_LSR_FIFOE 0x80 52 | 53 | #define UART_IIR_FCR_TX_CLR 0x4 54 | #define UART_IIR_FCR_RX_CLR 0x2 55 | #define UART_IIR_FCR_EN_FIFO 0x1 56 | 57 | #define UART_MCR_RTS 0x2 58 | #define UART_MCR_DTR 0x1 59 | 60 | typedef struct _uart_t 61 | { 62 | /* 0x00 */ vu32 UART_THR_DLAB; 63 | /* 0x04 */ vu32 UART_IER_DLAB; 64 | /* 0x08 */ vu32 UART_IIR_FCR; 65 | /* 0x0C */ vu32 UART_LCR; 66 | /* 0x10 */ vu32 UART_MCR; 67 | /* 0x14 */ vu32 UART_LSR; 68 | /* 0x18 */ vu32 UART_MSR; 69 | /* 0x1C */ vu32 UART_SPR; 70 | /* 0x20 */ vu32 UART_IRDA_CSR; 71 | /* 0x24 */ vu32 UART_RX_FIFO_CFG; 72 | /* 0x28 */ vu32 UART_MIE; 73 | /* 0x2C */ vu32 UART_VENDOR_STATUS; 74 | /* 0x30 */ u8 _pad_30[0xC]; 75 | /* 0x3C */ vu32 UART_ASR; 76 | } uart_t; 77 | 78 | void uart_init(u32 idx, u32 baud); 79 | void uart_wait_idle(u32 idx, u32 which); 80 | void uart_send(u32 idx, const u8 *buf, u32 len); 81 | u32 uart_recv(u32 idx, u8 *buf, u32 len); 82 | void uart_invert(u32 idx, bool enable, u32 invert_mask); 83 | u32 uart_get_IIR(u32 idx); 84 | void uart_set_IIR(u32 idx); 85 | void uart_empty_fifo(u32 idx, u32 which); 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /bdk/storage/nx_sd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018-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 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 | u32 sd_get_mode(); 49 | int sd_init_retry(bool power_cycle); 50 | bool sd_initialize(bool power_cycle); 51 | bool sd_mount(); 52 | void sd_unmount(); 53 | void sd_end(); 54 | void *sd_file_read(const char *path, u32 *fsize); 55 | int sd_save_to_file(void *buf, u32 size, const char *filename); 56 | 57 | #endif -------------------------------------------------------------------------------- /bdk/storage/ramdisk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Ramdisk driver for Tegra X1 3 | * 4 | * Copyright (c) 2019 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 | 25 | #include 26 | 27 | int ram_disk_init(FATFS *ram_fs) 28 | { 29 | int res; 30 | u8 *buf = malloc(0x400000); 31 | 32 | f_mount(NULL, "ram:", 1); // Unmount ramdisk. 33 | 34 | res = f_mkfs("ram:", FM_EXFAT, RAMDISK_CLUSTER_SZ, buf, 0x400000); // Format as exFAT w/ 32KB cluster. 35 | if (!res) 36 | res = f_mount(ram_fs, "ram:", 1); // Mount ramdisk. 37 | 38 | free(buf); 39 | 40 | return res; 41 | } 42 | 43 | int ram_disk_read(u32 sector, u32 sector_count, void *buf) 44 | { 45 | u32 sector_off = RAM_DISK_ADDR + (sector << 9); 46 | u32 bytes_count = sector_count << 9; 47 | 48 | if ((sector_off - RAM_DISK_ADDR) > RAM_DISK_SZ) 49 | return 1; 50 | 51 | memcpy(buf, (void *)sector_off, bytes_count); 52 | 53 | return 0; 54 | } 55 | 56 | int ram_disk_write(u32 sector, u32 sector_count, const void *buf) 57 | { 58 | u32 sector_off = RAM_DISK_ADDR + (sector << 9); 59 | u32 bytes_count = sector_count << 9; 60 | 61 | if ((sector_off - RAM_DISK_ADDR) > RAM_DISK_SZ) 62 | return 1; 63 | 64 | memcpy((void *)sector_off, buf, bytes_count); 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /bdk/storage/ramdisk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ramdisk driver for Tegra X1 3 | * 4 | * Copyright (c) 2019 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); 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/thermal/tmp451.c: -------------------------------------------------------------------------------- 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 | #include 20 | #include 21 | 22 | u16 tmp451_get_soc_temp(bool intenger) 23 | { 24 | u8 val; 25 | u16 temp = 0; 26 | 27 | val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TEMP_REG); 28 | if (intenger) 29 | return val; 30 | 31 | temp = val << 8; 32 | val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_SOC_TMP_DEC_REG); 33 | temp |= ((val >> 4) * 625) / 100; 34 | 35 | return temp; 36 | } 37 | 38 | u16 tmp451_get_pcb_temp(bool intenger) 39 | { 40 | u8 val; 41 | u16 temp = 0; 42 | 43 | val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_PCB_TEMP_REG); 44 | if (intenger) 45 | return val; 46 | 47 | temp = val << 8; 48 | val = i2c_recv_byte(I2C_1, TMP451_I2C_ADDR, TMP451_PCB_TMP_DEC_REG); 49 | temp |= ((val >> 4) * 625) / 100; 50 | 51 | return temp; 52 | } 53 | 54 | void tmp451_init() 55 | { 56 | // Disable ALARM and Range to 0 - 127 oC. 57 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_CONFIG_REG, 0x80); 58 | 59 | // Set conversion rate to 32/s and make a read to update the reg. 60 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_CNV_RATE_REG, 9); 61 | tmp451_get_soc_temp(false); 62 | 63 | // Set rate to every 4 seconds. 64 | i2c_send_byte(I2C_1, TMP451_I2C_ADDR, TMP451_CNV_RATE_REG, 2); 65 | } 66 | -------------------------------------------------------------------------------- /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 | // If input is false, the return value is packed. MSByte is the integer in oC 36 | // and the LSByte is the decimal point truncated to 2 decimal places. 37 | // Otherwise it's an integer oC. 38 | u16 tmp451_get_soc_temp(bool integer); 39 | u16 tmp451_get_pcb_temp(bool integer); 40 | void tmp451_init(); 41 | 42 | #endif /* __TMP451_H_ */ 43 | -------------------------------------------------------------------------------- /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/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/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 | char *dirlist(const char *directory, const char *pattern, bool includeHiddenFiles, bool parse_dirs) 25 | { 26 | u8 max_entries = 61; 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/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/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/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 | -------------------------------------------------------------------------------- /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 sprintf(char *buffer, const char *fmt, ...); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /bdk/utils/util.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 _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_BIS = BIT(5), 39 | NYX_CFG_UMS = BIT(6), 40 | NYX_CFG_DUMP = BIT(7), 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_L4T_KERNEL = BIT(24), 50 | ERR_EXCEPTION = BIT(31), 51 | } hekate_errors_t; 52 | 53 | #define byte_swap_32(num) ((((num) >> 24) & 0xff) | (((num) << 8) & 0xff0000) | \ 54 | (((num) >> 8 )& 0xff00) | (((num) << 24) & 0xff000000)) 55 | 56 | typedef struct _cfg_op_t 57 | { 58 | u32 off; 59 | u32 val; 60 | } cfg_op_t; 61 | 62 | typedef struct _nyx_info_t 63 | { 64 | u32 magic; 65 | u32 sd_init; 66 | u32 sd_errors[3]; 67 | u8 rsvd[0x1000]; 68 | u32 disp_id; 69 | u32 errors; 70 | } nyx_info_t; 71 | 72 | typedef struct _nyx_storage_t 73 | { 74 | u32 version; 75 | u32 cfg; 76 | u8 irama[0x8000]; 77 | u8 hekate[0x30000]; 78 | u8 rsvd[0x800000 - sizeof(nyx_info_t)]; 79 | nyx_info_t info; 80 | mtc_config_t mtc_cfg; 81 | emc_table_t mtc_table[10]; 82 | } nyx_storage_t; 83 | 84 | void exec_cfg(u32 *base, const cfg_op_t *ops, u32 num_ops); 85 | u32 crc32_calc(u32 crc, const u8 *buf, u32 len); 86 | 87 | u32 get_tmr_us(); 88 | u32 get_tmr_ms(); 89 | u32 get_tmr_s(); 90 | void usleep(u32 us); 91 | void msleep(u32 ms); 92 | 93 | void panic(u32 val); 94 | void power_set_state(power_state_t state); 95 | void power_set_state_ex(void *param); 96 | 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /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 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | extern hekate_config h_cfg; 34 | 35 | void set_default_configuration() 36 | { 37 | h_cfg.autoboot = 0; 38 | h_cfg.autoboot_list = 0; 39 | h_cfg.bootwait = 3; 40 | h_cfg.se_keygen_done = 0; 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.eks = NULL; 48 | h_cfg.sept_run = EMC(EMC_SCRATCH0) & EMC_SEPT_RUN; 49 | h_cfg.aes_slots_new = false; 50 | h_cfg.rcm_patched = fuse_check_patched_rcm(); 51 | h_cfg.emummc_force_disable = false; 52 | h_cfg.t210b01 = hw_get_chip_id() == GP_HIDREV_MAJOR_T210B01; 53 | 54 | sd_power_cycle_time_start = 0; 55 | } 56 | -------------------------------------------------------------------------------- /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 "hos/hos.h" 21 | #include 22 | 23 | typedef struct _hekate_config 24 | { 25 | // Non-volatile config. 26 | u32 autoboot; 27 | u32 autoboot_list; 28 | u32 bootwait; 29 | u32 backlight; 30 | u32 autohosoff; 31 | u32 autonogc; 32 | u32 updater2p; 33 | u32 bootprotect; 34 | // Global temporary config. 35 | bool t210b01; 36 | bool se_keygen_done; 37 | bool sept_run; 38 | bool aes_slots_new; 39 | bool emummc_force_disable; 40 | bool rcm_patched; 41 | u32 errors; 42 | hos_eks_mbr_t *eks; 43 | } hekate_config; 44 | 45 | void set_default_configuration(); 46 | int create_config_entry(); 47 | void config_autoboot(); 48 | void config_bootdelay(); 49 | void config_backlight(); 50 | void config_auto_hos_poweroff(); 51 | void config_nogc(); 52 | 53 | #endif /* _CONFIG_H_ */ 54 | -------------------------------------------------------------------------------- /source/cpr/cpr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | void m_entry_fixArchiveBit(u32 type); 5 | void m_entry_fixAIOUpdate(); 6 | void m_entry_fixClingWrap(); 7 | void m_entry_deleteInstalledThemes(); 8 | void m_entry_deleteBootFlags(); 9 | void m_entry_ViewCredits(); 10 | void m_entry_fixAll(); 11 | void m_entry_stillNoBootInfo(); 12 | void m_entry_fixMacSpecialFolders(); -------------------------------------------------------------------------------- /source/err.c: -------------------------------------------------------------------------------- 1 | #include "err.h" 2 | #include "gfx/gfx.h" 3 | #include "hid/hid.h" 4 | #include "gfx/gfxutils.h" 5 | 6 | const char *TEErrors[] = { 7 | "I/O ERROR", 8 | "NO DISK", 9 | "NOT READY", 10 | "NO FILE", 11 | "NO PATH", 12 | "PATH INVALID", 13 | "ACCESS DENIED", 14 | "ACCESS DENIED", 15 | "INVALID PTR", 16 | "PROTECTED", 17 | "INVALID DRIVE", 18 | "NO MEM", 19 | "NO FAT", 20 | "MKFS ABORT", 21 | [TE_ERR_UNIMPLEMENTED - 1] = "Unimplemented", 22 | [TE_EXCEPTION_RESET - 1] = "E Reset", 23 | [TE_EXCEPTION_UNDEFINED - 1] = "E Undefined", 24 | [TE_EXCEPTION_PREF_ABORT - 1] = "E Pref abort", 25 | [TE_EXCEPTION_DATA_ABORT - 1] = "E Data abort", 26 | [TE_ERR_SAME_LOC - 1] = "Same copy location", 27 | [TE_ERR_KEYDUMP_FAIL - 1] = "Keydump failed", 28 | [TE_ERR_PARTITION_NOT_FOUND - 1] = "Failed to find partition", 29 | [TE_ERR_PATH_IN_PATH - 1] = "Can't move/copy folder into itself", 30 | [TE_ERR_EMMC_READ_FAIL - 1] = "Emmc/Emummc read failed", 31 | [TE_ERR_EMMC_WRITE_FAIL - 1] = "Emmc/Emummc write failed", 32 | [TE_ERR_NO_SD - 1] = "No sd detected", 33 | [TE_ERR_FILE_TOO_BIG_FOR_DEST - 1] = "File is too big for dest", 34 | }; 35 | 36 | const char *GetErrStr(u32 err){ 37 | --err; // obv error codes cannot be 0 38 | if (err >= 0 && err < ARRAY_SIZE(TEErrors)) 39 | return TEErrors[err]; 40 | 41 | return "(Unknown)"; 42 | } 43 | 44 | #define lx 256 45 | #define ly 240 46 | #define lenx 768 47 | #define leny 240 48 | 49 | void DrawError(ErrCode_t err){ 50 | if (err.err == 0) 51 | return; 52 | 53 | SETCOLOR(COLOR_ORANGE, COLOR_DARKGREY); 54 | gfx_box(lx, ly, lx + lenx, ly + leny, COLOR_ORANGE); 55 | gfx_boxGrey(lx + 16, ly + 16, lx + lenx - 16, ly + leny - 16, 0x33); 56 | gfx_con_setpos(lx + ((lenx - 17 * 16) / 2), ly + 32); 57 | gfx_printf("An error occured!\n\n%bErr : %d\nLine: %d\nFile: %s\nDesc: %s%b", lx + 48, err.err, err.loc, err.file, GetErrStr(err.err), 0); 58 | gfx_con_setpos(lx + ((lenx - 19 * 16) / 2), ly + leny - 48); 59 | gfx_printf("Press A to continue"); 60 | 61 | hidWaitMask((JoyA | JoyB)); 62 | } -------------------------------------------------------------------------------- /source/err.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | typedef struct { 5 | u16 err; 6 | u16 loc; 7 | char* file; 8 | } ErrCode_t; 9 | 10 | enum { 11 | TE_ERR_UNIMPLEMENTED = 15, 12 | TE_EXCEPTION_RESET, 13 | TE_EXCEPTION_UNDEFINED, 14 | TE_EXCEPTION_PREF_ABORT, 15 | TE_EXCEPTION_DATA_ABORT, 16 | TE_ERR_SAME_LOC, 17 | TE_ERR_KEYDUMP_FAIL, 18 | TE_ERR_PARTITION_NOT_FOUND, 19 | TE_ERR_PATH_IN_PATH, 20 | TE_ERR_EMMC_READ_FAIL, 21 | TE_ERR_EMMC_WRITE_FAIL, 22 | TE_ERR_NO_SD, 23 | TE_ERR_FILE_TOO_BIG_FOR_DEST, 24 | TE_ERR_MEM_ALLOC_FAIL, 25 | TE_WARN_FILE_EXISTS, 26 | TE_WARN_FILE_TOO_SMALL_FOR_DEST, 27 | }; 28 | 29 | #define newErrCode(err) (ErrCode_t) {err, __LINE__, __FILE__} 30 | void DrawError(ErrCode_t err); -------------------------------------------------------------------------------- /source/fs/fscopy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "../err.h" 4 | 5 | #define COPY_MODE_CANCEL BIT(0) 6 | #define COPY_MODE_PRINT BIT(1) 7 | 8 | ErrCode_t FileCopy(const char *locin, const char *locout, u8 options); 9 | ErrCode_t FolderDelete(const char *path); 10 | ErrCode_t FolderCopy(const char *locin, const char *locout); -------------------------------------------------------------------------------- /source/fs/fstypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | typedef struct { 5 | char *name; 6 | union { 7 | struct { 8 | u8 readOnly:1; 9 | u8 hidden:1; 10 | u8 system:1; 11 | u8 volume:1; 12 | u8 isDir:1; 13 | u8 archive:1; 14 | }; 15 | u8 optionUnion; 16 | }; 17 | union { 18 | struct { 19 | u16 size:12; 20 | u16 showSize:1; 21 | u16 sizeDef:3; 22 | }; 23 | u16 sizeUnion; 24 | }; 25 | } FSEntry_t; 26 | 27 | #define newFSEntry(filename) (FSEntry_t) {.name = filename} -------------------------------------------------------------------------------- /source/fs/fsutils.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "fsutils.h" 4 | #include "../utils/utils.h" 5 | #include 6 | #include 7 | #include "readers/folderReader.h" 8 | 9 | char *CombinePaths(const char *current, const char *add){ 10 | char *ret; 11 | 12 | size_t size = strlen(current) + strlen(add) + 2; 13 | ret = (char*) malloc (size); 14 | 15 | sprintf(ret, (current[strlen(current) - 1] == '/') ? "%s%s" : "%s/%s", current, add); 16 | 17 | return ret; 18 | } 19 | 20 | char *EscapeFolder(const char *current){ 21 | char *ret; 22 | char *temp; 23 | 24 | ret = CpyStr(current); 25 | temp = strrchr(ret, '/'); 26 | 27 | if (*(temp - 1) == ':') 28 | temp++; 29 | 30 | *temp = '\0'; 31 | 32 | return ret; 33 | } 34 | 35 | FSEntry_t GetFileInfo(const char *path){ 36 | FILINFO fno; 37 | f_stat(path, &fno); 38 | FSEntry_t entry = {.optionUnion = fno.fattrib, .name = strrchr(path, '/') + 1}; 39 | if (!(*entry.name)) 40 | entry.name = "Root"; 41 | return entry; 42 | } 43 | 44 | char *GetFileAttribs(FSEntry_t entry){ 45 | char *ret = CpyStr("RHSVDA"); 46 | MaskIn(ret, entry.optionUnion, '-'); 47 | return ret; 48 | } 49 | 50 | bool FileExists(const char* path){ 51 | FRESULT fr; 52 | FILINFO fno; 53 | 54 | fr = f_stat(path, &fno); 55 | 56 | return !(fr & FR_NO_FILE); 57 | } 58 | -------------------------------------------------------------------------------- /source/fs/fsutils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "fstypes.h" 4 | 5 | FSEntry_t GetFileInfo(const char *path); 6 | char *EscapeFolder(const char *current); 7 | char *CombinePaths(const char *current, const char *add); 8 | char *GetFileAttribs(FSEntry_t entry); 9 | bool FileExists(const char* path); -------------------------------------------------------------------------------- /source/fs/menus/explorer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../utils/vector.h" 3 | 4 | void FileExplorer(char *path); -------------------------------------------------------------------------------- /source/fs/menus/filemenu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../fstypes.h" 3 | 4 | typedef void (*fileMenuPath)(char *path, FSEntry_t entry); 5 | 6 | void FileMenu(char *path, FSEntry_t entry); 7 | void RunScript(char *path, FSEntry_t entry); -------------------------------------------------------------------------------- /source/fs/menus/foldermenu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef int (*folderMenuPath)(const char *path); 4 | int FolderMenu(const char *path); -------------------------------------------------------------------------------- /source/fs/readers/folderReader.c: -------------------------------------------------------------------------------- 1 | #include "folderReader.h" 2 | #include 3 | #include "../../utils/utils.h" 4 | #include 5 | 6 | void clearFileVector(Vector_t *v){ 7 | vecPDefArray(FSEntry_t*, entries, v); 8 | for (int i = 0; i < v->count; i++) 9 | free(entries[i].name); 10 | 11 | free(v->data); 12 | } 13 | 14 | Vector_t /* of type FSEntry_t */ ReadFolder(const char *path, int *res){ 15 | Vector_t out = newVec(sizeof(FSEntry_t), 16); // we may want to prealloc with the same size as the folder 16 | DIR dir; 17 | FILINFO fno; 18 | 19 | if ((*res = f_opendir(&dir, path))){ 20 | // Err! 21 | return out; 22 | } 23 | 24 | while (!(*res = f_readdir(&dir, &fno)) && fno.fname[0]) { 25 | FSEntry_t newEntry = {.optionUnion = fno.fattrib, .name = CpyStr(fno.fname)}; 26 | 27 | if (!newEntry.isDir){ 28 | u64 total = fno.fsize; 29 | u8 type = 0; 30 | while (total > 1024){ 31 | total /= 1024; 32 | type++; 33 | } 34 | 35 | if (type > 3) 36 | type = 3; 37 | 38 | newEntry.showSize = 1; 39 | newEntry.size = total; 40 | newEntry.sizeDef = type; 41 | } 42 | vecAddElem(&out, newEntry); 43 | } 44 | 45 | f_closedir(&dir); 46 | 47 | return out; 48 | } 49 | -------------------------------------------------------------------------------- /source/fs/readers/folderReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "../../utils/vector.h" 4 | #include "../fstypes.h" 5 | 6 | void clearFileVector(Vector_t *v); 7 | Vector_t /* of type FSEntry_t */ ReadFolder(const char *path, int *res); -------------------------------------------------------------------------------- /source/gfx/gfxutils.c: -------------------------------------------------------------------------------- 1 | #include "gfx.h" 2 | #include "gfxutils.h" 3 | #include 4 | #include 5 | #include 6 | #include "../hid/hid.h" 7 | 8 | void gfx_printTopInfo() { 9 | int battery = 0; 10 | max17050_get_property(MAX17050_RepSOC, &battery); 11 | 12 | int current_charge_status = 0; 13 | bq24193_get_property(BQ24193_ChargeStatus, ¤t_charge_status); 14 | SETCOLOR(COLOR_DEFAULT, COLOR_WHITE); 15 | gfx_con_setpos(0, 0); 16 | gfx_printf("CPR %d.%d.%d | Battery: %d%% %c\n", LP_VER_MJ, LP_VER_MN, LP_VER_BF, battery >> 8, ((current_charge_status) ? 129 : 32)); 17 | RESETCOLOR; 18 | } 19 | 20 | void gfx_clearscreen(){ 21 | gfx_boxGrey(0, 16, 1279, 703, 0x1b); 22 | 23 | gfx_boxGrey(0, 703, 1279, 719, 0xFF); 24 | gfx_boxGrey(0, 0, 1279, 15, 0xFF); 25 | 26 | 27 | gfx_printTopInfo(); 28 | } 29 | 30 | MenuEntry_t YesNoEntries[] = { 31 | {.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "No"}, 32 | {.R = 255, .name = "Yes"} 33 | }; 34 | 35 | int MakeYesNoHorzMenu(int spacesBetween, u32 bg){ 36 | return MakeHorizontalMenu(YesNoEntries, ARR_LEN(YesNoEntries), spacesBetween, bg, 0); 37 | } 38 | 39 | int MakeHorizontalMenu(MenuEntry_t *entries, int len, int spacesBetween, u32 bg, int startPos){ 40 | u32 initialX = 0, initialY = 0; 41 | u32 highlight = startPos; 42 | gfx_con_getpos(&initialX, &initialY); 43 | 44 | while (1){ 45 | for (int i = 0; i < len; i++){ 46 | (highlight == i) ? SETCOLOR(bg, entries[i].optionUnion) : SETCOLOR(entries[i].optionUnion, bg); 47 | gfx_puts(entries[i].name); 48 | gfx_con.y -= spacesBetween * 16; 49 | } 50 | gfx_con_setpos(initialX, initialY); 51 | Input_t *input = hidWait(); 52 | if (input->a) 53 | return highlight; 54 | else if (input->b) 55 | return 0; 56 | else if ((input->left || input->down) && highlight > 0) 57 | highlight--; 58 | else if ((input->right || input->up) && highlight < len - 1) 59 | highlight++; 60 | } 61 | } -------------------------------------------------------------------------------- /source/gfx/gfxutils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "gfx.h" 3 | #include "menu.h" 4 | 5 | #define COLOR_WHITE 0xFFFFFFFF 6 | #define COLOR_DEFAULT 0xFF1B1B1B 7 | #define COLOR_GREY 0xFF888888 8 | #define COLOR_DARKGREY 0xFF333333 9 | 10 | #define COLORTORGB(color) (color & 0x00FFFFFF) 11 | #define SETCOLOR(fg, bg) gfx_con_setcol(fg, 1, bg) 12 | #define RESETCOLOR SETCOLOR(COLOR_WHITE, COLOR_DEFAULT); 13 | 14 | #define RGBUnionToU32(optionUnion) (optionUnion | 0xFF000000) 15 | 16 | void gfx_clearscreen(); 17 | int MakeHorizontalMenu(MenuEntry_t *entries, int len, int spacesBetween, u32 bg, int startPos); 18 | int MakeYesNoHorzMenu(int spacesBetween, u32 bg); 19 | void gfx_printTopInfo(); -------------------------------------------------------------------------------- /source/gfx/menu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "../utils/vector.h" 4 | 5 | typedef void (*menuEntriesGatherer)(Vector_t* vec, void* data); 6 | typedef void (*menuPaths)(); 7 | 8 | typedef struct _menuEntry { 9 | union { 10 | struct { 11 | u32 B:8; 12 | u32 G:8; 13 | u32 R:8; 14 | u32 skip:1; 15 | u32 hide:1; 16 | }; 17 | u32 optionUnion; 18 | }; 19 | char *name; 20 | u8 icon; 21 | union { 22 | struct { 23 | u16 size:12; 24 | u16 showSize:1; 25 | u16 sizeDef:3; 26 | }; 27 | u16 sizeUnion; 28 | }; 29 | } MenuEntry_t; 30 | 31 | #define SKIPHIDEBITS 0x3000000 32 | #define RGBCOLOR(r, g, b) (b << 16 | g << 8 | r) 33 | 34 | #define SKIPBIT BIT(24) 35 | #define HIDEBIT BIT(25) 36 | 37 | #define ENABLEB BIT(0) 38 | #define ENABLEPAGECOUNT BIT(1) 39 | #define ALWAYSREDRAW BIT(2) 40 | #define USELIGHTGREY BIT(3) 41 | 42 | #define ScreenDefaultLenX 79 43 | #define ScreenDefaultLenY 30 44 | 45 | #define ARR_LEN(x) (sizeof(x) / sizeof(*x)) 46 | 47 | int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, u8 options, int entryCount); -------------------------------------------------------------------------------- /source/hid/hid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | //#define BIT(n) (1U << n) 5 | 6 | #define JoyY BIT(0) 7 | #define JoyX BIT(1) 8 | #define JoyB BIT(2) 9 | #define JoyA BIT(3) 10 | #define JoyRB BIT(6) 11 | #define JoyMenu BIT(12) 12 | #define JoyLDown BIT(16) 13 | #define JoyLUp BIT(17) 14 | #define JoyLRight BIT(18) 15 | #define JoyLLeft BIT(19) 16 | #define JoyLB BIT(22) 17 | #define BtnPow BIT(24) 18 | #define BtnVolP BIT(25) 19 | #define BtnVolM BIT(26) 20 | #define JoyRDown BIT(27) 21 | #define JoyRUp BIT(28) 22 | #define JoyRRight BIT(29) 23 | #define JoyRLeft BIT(30) 24 | 25 | #define WAITBUTTONS (JoyY | JoyX | JoyB | JoyA | JoyLDown | JoyLUp | JoyLRight | JoyLLeft) 26 | 27 | typedef struct _inputs { 28 | union { 29 | struct { 30 | // Joy-Con (R). 31 | u32 y:1; 32 | u32 x:1; 33 | u32 b:1; 34 | u32 a:1; 35 | u32 sr_r:1; 36 | u32 sl_r:1; 37 | u32 r:1; 38 | u32 zr:1; 39 | 40 | // Shared 41 | u32 minus:1; 42 | u32 plus:1; 43 | u32 r3:1; 44 | u32 l3:1; 45 | u32 home:1; 46 | u32 cap:1; 47 | u32 pad:1; 48 | u32 wired:1; 49 | 50 | // Joy-Con (L). 51 | u32 down:1; 52 | u32 up:1; 53 | u32 right:1; 54 | u32 left:1; 55 | u32 sr_l:1; 56 | u32 sl_l:1; 57 | u32 l:1; 58 | u32 zl:1; 59 | 60 | u32 power:1; 61 | u32 volp:1; 62 | u32 volm:1; 63 | 64 | u32 rDown:1; 65 | u32 rUp:1; 66 | u32 rRight:1; 67 | u32 rLeft:1; 68 | }; 69 | u32 buttons; 70 | }; 71 | } Input_t; 72 | 73 | void hidInit(); 74 | Input_t *hidRead(); 75 | Input_t *hidWait(); 76 | Input_t *hidWaitMask(u32 mask); 77 | bool hidConnected(); -------------------------------------------------------------------------------- /source/hos/fss.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 _FSS_H_ 18 | #define _FSS_H_ 19 | 20 | #include "hos.h" 21 | 22 | typedef struct _fss0_sept_t 23 | { 24 | u32 kb; 25 | ini_sec_t *cfg_sec; 26 | void *sept_primary; 27 | void *sept_secondary; 28 | 29 | } fss0_sept_t; 30 | 31 | int parse_fss(launch_ctxt_t *ctxt, const char *path, fss0_sept_t *sept_ctxt); 32 | int load_sept_from_ffs0(fss0_sept_t *sept_ctxt); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /source/hos/pkg1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 naehrwert 3 | * Copyright (c) 2018 st4rk 4 | * Copyright (c) 2018-2019 CTCaer 5 | * Copyright (c) 2018 balika011 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 | #include 21 | 22 | #include "pkg1.h" 23 | #include 24 | 25 | static const pkg1_id_t _pkg1_ids[] = { 26 | { "20161121183008", 0 }, //1.0.0 27 | { "20170210155124", 0 }, //2.0.0 - 2.3.0 28 | { "20170519101410", 1 }, //3.0.0 29 | { "20170710161758", 2 }, //3.0.1 - 3.0.2 30 | { "20170921172629", 3 }, //4.0.0 - 4.1.0 31 | { "20180220163747", 4 }, //5.0.0 - 5.1.0 32 | { "20180802162753", 5 }, //6.0.0 - 6.1.0 33 | { "20181107105733", 6 }, //6.2.0 34 | { "20181218175730", 7 }, //7.0.0 35 | { "20190208150037", 7 }, //7.0.1 36 | { "20190314172056", 7 }, //8.0.0 - 8.0.1 37 | { "20190531152432", 8 }, //8.1.0 38 | { "20190809135709", 9 }, //9.0.0 - 9.0.1 39 | { "20191021113848", 10}, //9.1.0 40 | { "20200303104606", 10}, //10.0.0 - 10.2.0 41 | { "20201030110855", 10}, //11.0.0 42 | { "20210129111626", 10}, //12.0.0 43 | { "20210422145837", 10}, //12.0.2 44 | { NULL } //End. 45 | }; 46 | 47 | const pkg1_id_t *pkg1_identify(u8 *pkg1) 48 | { 49 | for (u32 i = 0; _pkg1_ids[i].id; i++) 50 | if (!memcmp(pkg1 + 0x10, _pkg1_ids[i].id, 8)) 51 | return &_pkg1_ids[i]; 52 | return NULL; 53 | } 54 | -------------------------------------------------------------------------------- /source/hos/pkg1.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 _PKG1_H_ 18 | #define _PKG1_H_ 19 | 20 | #include 21 | 22 | #define PKG1_MAX_SIZE 0x40000 23 | #define PKG1_OFFSET 0x100000 24 | #define KEYBLOB_OFFSET 0x180000 25 | 26 | typedef struct _bl_hdr_t210b01_t 27 | { 28 | u8 aes_mac[0x10]; 29 | u8 rsa_sig[0x100]; 30 | u8 salt[0x20]; 31 | u8 sha256[0x20]; 32 | u32 version; 33 | u32 size; 34 | u32 load_addr; 35 | u32 entrypoint; 36 | u8 rsvd[0x10]; 37 | } bl_hdr_t210b01_t; 38 | 39 | typedef struct _pkg1_id_t 40 | { 41 | const char *id; 42 | u32 kb; 43 | } pkg1_id_t; 44 | 45 | const pkg1_id_t *pkg1_identify(u8 *pkg1); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /source/hos/pkg2.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 _PKG2_H_ 19 | #define _PKG2_H_ 20 | 21 | #include 22 | #include 23 | 24 | #define PKG2_MAGIC 0x31324B50 25 | #define PKG2_SEC_BASE 0x80000000 26 | #define PKG2_SEC_KERNEL 0 27 | #define PKG2_SEC_INI1 1 28 | 29 | #define PKG2_NEWKERN_GET_INI1_HEURISTIC 0xD2800015 // Offset of OP + 12 is the INI1 offset. 30 | 31 | extern u32 pkg2_newkern_ini1_val; 32 | extern u32 pkg2_newkern_ini1_start; 33 | extern u32 pkg2_newkern_ini1_end; 34 | 35 | typedef struct _kernel_patch_t 36 | { 37 | u32 id; 38 | u32 off; 39 | u32 val; 40 | u32 *ptr; 41 | } kernel_patch_t; 42 | 43 | typedef struct _pkg2_hdr_t 44 | { 45 | u8 ctr[0x10]; 46 | u8 sec_ctr[0x40]; 47 | u32 magic; 48 | u32 base; 49 | u32 pad0; 50 | u8 pkg2_ver; 51 | u8 bl_ver; 52 | u16 pad1; 53 | u32 sec_size[4]; 54 | u32 sec_off[4]; 55 | u8 sec_sha256[0x80]; 56 | u8 data[]; 57 | } pkg2_hdr_t; 58 | 59 | typedef struct _pkg2_ini1_t 60 | { 61 | u32 magic; 62 | u32 size; 63 | u32 num_procs; 64 | u32 pad; 65 | } pkg2_ini1_t; 66 | 67 | typedef struct _pkg2_kip1_sec_t 68 | { 69 | u32 offset; 70 | u32 size_decomp; 71 | u32 size_comp; 72 | u32 attrib; 73 | } pkg2_kip1_sec_t; 74 | 75 | #define KIP1_NUM_SECTIONS 6 76 | 77 | typedef struct _pkg2_kip1_t 78 | { 79 | u32 magic; 80 | u8 name[12]; 81 | u64 tid; 82 | u32 proc_cat; 83 | u8 main_thrd_prio; 84 | u8 def_cpu_core; 85 | u8 res; 86 | u8 flags; 87 | pkg2_kip1_sec_t sections[KIP1_NUM_SECTIONS]; 88 | u32 caps[0x20]; 89 | u8 data[]; 90 | } pkg2_kip1_t; 91 | 92 | typedef struct _pkg2_kip1_info_t 93 | { 94 | pkg2_kip1_t *kip1; 95 | u32 size; 96 | link_t link; 97 | } pkg2_kip1_info_t; 98 | 99 | typedef struct _pkg2_kernel_id_t 100 | { 101 | u8 hash[8]; 102 | kernel_patch_t *kernel_patchset; 103 | } pkg2_kernel_id_t; 104 | 105 | bool pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2); 106 | int pkg2_decompress_kip(pkg2_kip1_info_t* ki, u32 sectsToDecomp); 107 | pkg2_hdr_t *pkg2_decrypt(void *data); 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /source/hos/sept.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 _SEPT_H_ 18 | #define _SEPT_H_ 19 | 20 | #include 21 | 22 | int reboot_to_sept(const u8 *tsec_fw, const u32 tsec_size, const u32 kb); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /source/keys/keyfile.c: -------------------------------------------------------------------------------- 1 | #include "keys.h" 2 | #include "keyfile.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "../tegraexplorer/tconf.h" 8 | #include 9 | #include "../gfx/gfx.h" 10 | 11 | #define GetHexFromChar(c) ((c & 0x0F) + (c >= 'A' ? 9 : 0)) 12 | 13 | char *getKey(const char *search, link_t *inilist){ 14 | LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, inilist, link){ 15 | if (ini_sec->type == INI_CHOICE){ 16 | LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link) 17 | { 18 | if (!strcmp(search, kv->key)) 19 | return kv->val; 20 | } 21 | } 22 | } 23 | return NULL; 24 | } 25 | 26 | void AddKey(u8 *buff, char *in, u32 len){ 27 | if (in == NULL || strlen(in) != len * 2) 28 | return; 29 | 30 | for (int i = 0; i < len; i++) 31 | buff[i] = (u8)((GetHexFromChar(in[i * 2]) << 4) | GetHexFromChar(in[i * 2 + 1])); 32 | } 33 | 34 | int GetKeysFromFile(char *path){ 35 | gfx_puts("Grabbing keys from prod.keys..."); 36 | if (!sd_mount()) 37 | return 1; 38 | 39 | LIST_INIT(iniList); // Whatever we'll just let this die in memory hell 40 | if (!ini_parse(&iniList, path, false)) 41 | return 1; 42 | 43 | // add biskeys, mkey 0, header_key, save_mac_key 44 | AddKey(dumpedKeys.bis_key[0], getKey("bis_key_00", &iniList), AES_128_KEY_SIZE * 2); 45 | AddKey(dumpedKeys.bis_key[1], getKey("bis_key_01", &iniList), AES_128_KEY_SIZE * 2); 46 | AddKey(dumpedKeys.bis_key[2], getKey("bis_key_02", &iniList), AES_128_KEY_SIZE * 2); 47 | AddKey(dumpedKeys.master_key, getKey("master_key_00", &iniList), AES_128_KEY_SIZE); 48 | AddKey(dumpedKeys.header_key, getKey("header_key", &iniList), AES_128_KEY_SIZE * 2); 49 | AddKey(dumpedKeys.save_mac_key, getKey("save_mac_key", &iniList), AES_128_KEY_SIZE); 50 | 51 | gfx_puts(" Done"); 52 | return 0; 53 | } -------------------------------------------------------------------------------- /source/keys/keyfile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | int GetKeysFromFile(char *path); -------------------------------------------------------------------------------- /source/keys/keys.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "../hos/hos.h" 4 | 5 | #define AES_128_KEY_SIZE 16 6 | #define RSA_2048_KEY_SIZE 256 7 | 8 | // only tickets of type Rsa2048Sha256 are expected 9 | typedef struct { 10 | u32 signature_type; // always 0x10004 11 | u8 signature[RSA_2048_KEY_SIZE]; 12 | u8 sig_padding[0x3C]; 13 | char issuer[0x40]; 14 | u8 titlekey_block[RSA_2048_KEY_SIZE]; 15 | u8 format_version; 16 | u8 titlekey_type; 17 | u16 ticket_version; 18 | u8 license_type; 19 | u8 common_key_id; 20 | u16 property_mask; 21 | u64 reserved; 22 | u64 ticket_id; 23 | u64 device_id; 24 | u8 rights_id[0x10]; 25 | u32 account_id; 26 | u32 sect_total_size; 27 | u32 sect_hdr_offset; 28 | u16 sect_hdr_count; 29 | u16 sect_hdr_entry_size; 30 | u8 padding[0x140]; 31 | } ticket_t; 32 | 33 | typedef struct { 34 | u8 rights_id[0x10]; 35 | u64 ticket_id; 36 | u32 account_id; 37 | u16 property_mask; 38 | u16 reserved; 39 | } ticket_record_t; 40 | 41 | typedef struct { 42 | u8 read_buffer[0x40000]; 43 | u8 rights_ids[0x40000 / 0x10][0x10]; 44 | u8 titlekeys[0x40000 / 0x10][0x10]; 45 | } titlekey_buffer_t; 46 | 47 | typedef struct { 48 | u8 private_exponent[RSA_2048_KEY_SIZE]; 49 | u8 modulus[RSA_2048_KEY_SIZE]; 50 | u8 public_exponent[4]; 51 | u8 reserved[0x14]; 52 | u64 device_id; 53 | u8 gmac[0x10]; 54 | } rsa_keypair_t; 55 | 56 | typedef struct { 57 | u8 master_kek[AES_128_KEY_SIZE]; 58 | u8 data[0x70]; 59 | u8 package1_key[AES_128_KEY_SIZE]; 60 | } keyblob_t; 61 | 62 | typedef struct { 63 | u8 cmac[0x10]; 64 | u8 iv[0x10]; 65 | keyblob_t key_data; 66 | u8 unused[0x150]; 67 | } encrypted_keyblob_t; 68 | 69 | typedef struct { 70 | u8 temp_key[AES_128_KEY_SIZE], 71 | bis_key[3][AES_128_KEY_SIZE * 2], 72 | device_key[AES_128_KEY_SIZE], 73 | device_key_4x[AES_128_KEY_SIZE], 74 | // FS-related keys 75 | header_key[AES_128_KEY_SIZE * 2], 76 | save_mac_key[AES_128_KEY_SIZE], 77 | // keyblob-derived families 78 | keyblob_key[AES_128_KEY_SIZE], 79 | keyblob_mac_key[AES_128_KEY_SIZE], 80 | package1_key[AES_128_KEY_SIZE], 81 | // master key-derived families, 82 | master_kek[AES_128_KEY_SIZE], 83 | master_key[AES_128_KEY_SIZE], 84 | tsec_keys[AES_128_KEY_SIZE * 2]; 85 | u32 sbk[4]; 86 | keyblob_t keyblob; 87 | } key_derivation_ctx_t; 88 | 89 | int DumpKeys(); 90 | void PrintKey(u8 *key, u32 len); 91 | 92 | extern key_derivation_ctx_t __attribute__((aligned(4))) dumpedKeys; -------------------------------------------------------------------------------- /source/keys/nca.c: -------------------------------------------------------------------------------- 1 | #include "nca.h" 2 | #include "keys.h" 3 | #include 4 | #include 5 | #include 6 | 7 | // Thanks switchbrew https://switchbrew.org/wiki/NCA_Format 8 | // This function is hacky, should change it but am lazy 9 | int GetNcaType(char *path){ 10 | FIL fp; 11 | u32 read_bytes = 0; 12 | 13 | if (f_open(&fp, path, FA_READ | FA_OPEN_EXISTING)) 14 | return -1; 15 | 16 | u8 *dec_header = (u8*)malloc(0x400); 17 | 18 | if (f_lseek(&fp, 0x200) || f_read(&fp, dec_header, 32, &read_bytes) || read_bytes != 32){ 19 | f_close(&fp); 20 | free(dec_header); 21 | return -1; 22 | } 23 | 24 | se_aes_xts_crypt(7,6,0,1, dec_header + 0x200, dec_header, 32, 1); 25 | 26 | u8 ContentType = dec_header[0x205]; 27 | 28 | f_close(&fp); 29 | free(dec_header); 30 | return ContentType; 31 | } -------------------------------------------------------------------------------- /source/keys/nca.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum NcaTypes { 4 | Porgram = 0, 5 | Meta, 6 | Control, 7 | Manual, 8 | Data, 9 | PublicData 10 | }; 11 | 12 | int GetNcaType(char *path); -------------------------------------------------------------------------------- /source/keys/save.c: -------------------------------------------------------------------------------- 1 | #include "save.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "../err.h" 7 | 8 | ErrCode_t saveCommit(const char *path){ 9 | FIL file; 10 | int res; 11 | u8 *buf, hash[0x20], *cmac_data, cmac[0x10]; 12 | const u32 hashed_data_size = 0x3D00, cmac_data_size = 0x200; 13 | 14 | buf = malloc(hashed_data_size); 15 | cmac_data = malloc(cmac_data_size); 16 | 17 | if ((res = f_open(&file, path, FA_OPEN_EXISTING | FA_READ | FA_WRITE))){ 18 | goto out_free; 19 | } 20 | 21 | f_lseek(&file, 0x300); 22 | if ((res = f_read(&file, buf, hashed_data_size, NULL))){ 23 | goto out_free; 24 | } 25 | 26 | se_calc_sha256_oneshot(hash, buf, hashed_data_size); 27 | 28 | f_lseek(&file, 0x108); 29 | if ((res = f_write(&file, hash, sizeof(hash), NULL))){ 30 | goto out_free; 31 | } 32 | 33 | f_lseek(&file, 0x100); 34 | if ((res = f_read(&file, cmac_data, cmac_data_size, NULL))){ 35 | goto out_free; 36 | } 37 | 38 | se_aes_cmac(8, cmac, 0x10, cmac_data, cmac_data_size); 39 | 40 | f_lseek(&file, 0); 41 | 42 | if ((res = f_write(&file, cmac, sizeof(cmac), NULL))){ 43 | goto out_free; 44 | } 45 | 46 | out_free:; 47 | free(buf); 48 | free(cmac_data); 49 | f_close(&file); 50 | return newErrCode(res); 51 | } -------------------------------------------------------------------------------- /source/keys/save.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../err.h" 3 | 4 | ErrCode_t saveCommit(const char *path); -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /source/link.ld: -------------------------------------------------------------------------------- 1 | ENTRY(_start) 2 | 3 | SECTIONS { 4 | PROVIDE(__ipl_start = IPL_LOAD_ADDR); 5 | . = __ipl_start; 6 | .text : { 7 | *(.text._start); 8 | *(._boot_cfg); 9 | *(.text*); 10 | } 11 | .data : { 12 | *(.data*); 13 | *(.rodata*); 14 | } 15 | . = ALIGN(0x10); 16 | __ipl_end = .; 17 | .bss : { 18 | __bss_start = .; 19 | *(COMMON) 20 | *(.bss*) 21 | __bss_end = .; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /source/script/args.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | 4 | char* utils_copyStringSize(const char* in, int size); 5 | Variable_t solveEquation(scriptCtx_t* ctx, lexarToken_t* tokens, u32 len, u8 shouldFree); 6 | int distanceBetweenTokens(lexarToken_t* tokens, u32 len, int openToken, int closeToken); 7 | Vector_t extractVars(scriptCtx_t* ctx, lexarToken_t* tokens, u32 len); -------------------------------------------------------------------------------- /source/script/functions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "variables.h" 3 | 4 | Variable_t executeFunction(scriptCtx_t* ctx, char* func_name, lexarToken_t* start, u32 len); -------------------------------------------------------------------------------- /source/script/lexer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | 4 | Vector_t runLexer(const char* in, u32 len); 5 | char lexarDebugGetTokenC(u8 tokenN); 6 | void lexarVectorClear(Vector_t *v); -------------------------------------------------------------------------------- /source/script/parser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | scriptResult_t mainLoop(scriptCtx_t* ctx); 6 | void printError(scriptResult_t res); -------------------------------------------------------------------------------- /source/script/variables.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | 4 | void dictVectorAdd(Vector_t* v, dict_t add); 5 | Variable_t* dictVectorFind(Vector_t* v, const char* key); 6 | void freeDictVector(Vector_t* v); 7 | void freeVariableVector(Vector_t* v); 8 | void freeVariable(Variable_t dv); 9 | scriptCtx_t createScriptCtx(); 10 | 11 | u8 setIndentInstruction(scriptCtx_t* ctx, u8 level, u8 skip, u8 func, int jumpLoc); 12 | indentInstructor_t* getCurIndentInstruction(scriptCtx_t* ctx); 13 | 14 | static inline u8 setCurIndentInstruction(scriptCtx_t* ctx, u8 skip, u8 func, int jumpLoc) { 15 | return setIndentInstruction(ctx, ctx->indentIndex, skip, func, jumpLoc); 16 | } -------------------------------------------------------------------------------- /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 _irq_setup 27 | .type _irq_setup, %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, =0x4003FF00 65 | LDR R0, =__bss_start 66 | EOR R1, R1, R1 67 | LDR R2, =__bss_end 68 | SUB R2, R2, R0 69 | BL memset 70 | BL _irq_setup 71 | B . 72 | 73 | .globl pivot_stack 74 | .type pivot_stack, %function 75 | pivot_stack: 76 | MOV SP, R0 77 | BX LR 78 | -------------------------------------------------------------------------------- /source/storage/emmcfile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../err.h" 3 | 4 | ErrCode_t DumpOrWriteEmmcPart(const char *path, const char *part, u8 write, u8 force); -------------------------------------------------------------------------------- /source/storage/emummc.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 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 | u16 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(sdmmc_storage_t *storage, sdmmc_t *sdmmc); 55 | int emummc_storage_end(sdmmc_storage_t *storage); 56 | int emummc_storage_read(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf); 57 | int emummc_storage_write(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf); 58 | int emummc_storage_set_mmc_partition(sdmmc_storage_t *storage, u32 partition); 59 | 60 | #endif -------------------------------------------------------------------------------- /source/storage/gptmenu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | void GptMenu(u8 MMCType); -------------------------------------------------------------------------------- /source/storage/mountmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "../err.h" 5 | 6 | enum { 7 | MMC_CONN_None = 0, 8 | MMC_CONN_EMMC, 9 | MMC_CONN_EMUMMC 10 | }; 11 | 12 | int connectMMC(u8 mmcType); 13 | ErrCode_t mountMMCPart(const char *partition); 14 | void SetKeySlots(); 15 | void unmountMMCPart(); 16 | link_t *GetCurGPT(); 17 | void disconnectMMC(); -------------------------------------------------------------------------------- /source/storage/nx_emmc.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 | 19 | #include "nx_emmc.h" 20 | #include "emummc.h" 21 | #include 22 | #include 23 | #include 24 | 25 | sdmmc_t emmc_sdmmc; 26 | sdmmc_storage_t emmc_storage; 27 | FATFS emmc_fs; 28 | 29 | void nx_emmc_gpt_parse(link_t *gpt, sdmmc_storage_t *storage) 30 | { 31 | gpt_t *gpt_buf = (gpt_t *)calloc(NX_GPT_NUM_BLOCKS, NX_EMMC_BLOCKSIZE); 32 | 33 | emummc_storage_read(storage, NX_GPT_FIRST_LBA, NX_GPT_NUM_BLOCKS, gpt_buf); 34 | 35 | for (u32 i = 0; i < gpt_buf->header.num_part_ents; i++) 36 | { 37 | emmc_part_t *part = (emmc_part_t *)calloc(sizeof(emmc_part_t), 1); 38 | 39 | if (gpt_buf->entries[i].lba_start < gpt_buf->header.first_use_lba) 40 | continue; 41 | 42 | part->index = i; 43 | part->lba_start = gpt_buf->entries[i].lba_start; 44 | part->lba_end = gpt_buf->entries[i].lba_end; 45 | part->attrs = gpt_buf->entries[i].attrs; 46 | 47 | // ASCII conversion. Copy only the LSByte of the UTF-16LE name. 48 | for (u32 j = 0; j < 36; j++) 49 | part->name[j] = gpt_buf->entries[i].name[j]; 50 | part->name[35] = 0; 51 | 52 | list_append(gpt, &part->link); 53 | } 54 | 55 | free(gpt_buf); 56 | } 57 | 58 | void nx_emmc_gpt_free(link_t *gpt) 59 | { 60 | LIST_FOREACH_SAFE(iter, gpt) 61 | free(CONTAINER_OF(iter, emmc_part_t, link)); 62 | } 63 | 64 | emmc_part_t *nx_emmc_part_find(link_t *gpt, const char *name) 65 | { 66 | LIST_FOREACH_ENTRY(emmc_part_t, part, gpt, link) 67 | if (!strcmp(part->name, name)) 68 | return part; 69 | return NULL; 70 | } 71 | 72 | int nx_emmc_part_read(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf) 73 | { 74 | // The last LBA is inclusive. 75 | if (part->lba_start + sector_off > part->lba_end) 76 | return 0; 77 | return emummc_storage_read(storage, part->lba_start + sector_off, num_sectors, buf); 78 | } 79 | 80 | int nx_emmc_part_write(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf) 81 | { 82 | // The last LBA is inclusive. 83 | if (part->lba_start + sector_off > part->lba_end) 84 | return 0; 85 | return emummc_storage_write(storage, part->lba_start + sector_off, num_sectors, buf); 86 | } 87 | -------------------------------------------------------------------------------- /source/storage/nx_emmc.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 _NX_EMMC_H_ 18 | #define _NX_EMMC_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #define NX_GPT_FIRST_LBA 1 26 | #define NX_GPT_NUM_BLOCKS 33 27 | #define NX_EMMC_BLOCKSIZE 512 28 | 29 | typedef struct _emmc_part_t 30 | { 31 | u32 index; 32 | u32 lba_start; 33 | u32 lba_end; 34 | u64 attrs; 35 | char name[37]; 36 | link_t link; 37 | } emmc_part_t; 38 | 39 | extern sdmmc_t emmc_sdmmc; 40 | extern sdmmc_storage_t emmc_storage; 41 | extern FATFS emmc_fs; 42 | 43 | void nx_emmc_gpt_parse(link_t *gpt, sdmmc_storage_t *storage); 44 | void nx_emmc_gpt_free(link_t *gpt); 45 | emmc_part_t *nx_emmc_part_find(link_t *gpt, const char *name); 46 | int nx_emmc_part_read(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf); 47 | int nx_emmc_part_write(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /source/tegraexplorer/mainmenu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void EnterMainMenu(); -------------------------------------------------------------------------------- /source/tegraexplorer/tconf.c: -------------------------------------------------------------------------------- 1 | #include "tconf.h" 2 | #include 3 | #include "../utils/utils.h" 4 | TConf_t TConf = {0}; 5 | 6 | void ResetCopyParams(){ 7 | TConf.heldExplorerCopyLoc = LOC_None; 8 | FREE(TConf.srcCopy); 9 | TConf.explorerCopyMode = CMODE_None; 10 | } 11 | 12 | void SetCopyParams(const char *path, u8 mode){ 13 | ResetCopyParams(); 14 | TConf.heldExplorerCopyLoc = TConf.curExplorerLoc; 15 | TConf.explorerCopyMode = mode; 16 | TConf.srcCopy = CpyStr(path); 17 | } -------------------------------------------------------------------------------- /source/tegraexplorer/tconf.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "../keys/keys.h" 4 | 5 | enum { 6 | LOC_None = 0, 7 | LOC_SD, 8 | LOC_EMMC, 9 | LOC_EMUMMC 10 | }; 11 | 12 | enum { 13 | CMODE_None = 0, 14 | CMODE_Copy, 15 | CMODE_Move, 16 | CMODE_CopyFolder, 17 | CMODE_MoveFolder 18 | }; 19 | 20 | typedef struct { 21 | u32 FSBuffSize; 22 | char *srcCopy; 23 | union { 24 | struct { 25 | u16 minervaEnabled:1; 26 | u16 keysDumped:1; 27 | u16 curExplorerLoc:2; 28 | u16 heldExplorerCopyLoc:2; 29 | u16 explorerCopyMode:4; 30 | u16 currentMMCConnected:2; 31 | u16 connectedMMCMounted:1; 32 | }; 33 | u16 optionUnion; 34 | }; 35 | const char *pkg1ID; 36 | u8 pkg1ver; 37 | } TConf_t; 38 | 39 | extern TConf_t TConf; 40 | 41 | void ResetCopyParams(); 42 | void SetCopyParams(const char *path, u8 mode); -------------------------------------------------------------------------------- /source/tegraexplorer/tools.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | typedef struct _bmp_t 5 | { 6 | u16 magic; 7 | u32 size; 8 | u32 rsvd; 9 | u32 data_off; 10 | u32 hdr_size; 11 | u32 width; 12 | u32 height; 13 | u16 planes; 14 | u16 pxl_bits; 15 | u32 comp; 16 | u32 img_size; 17 | u32 res_h; 18 | u32 res_v; 19 | u64 rsvd2; 20 | } __attribute__((packed)) bmp_t; 21 | 22 | void DumpSysFw(); 23 | void FormatSD(); 24 | void TakeScreenshot(); -------------------------------------------------------------------------------- /source/utils/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | char *CpyStr(const char* in); 5 | void MaskIn(char *mod, u32 bitstream, char mask); 6 | bool StrEndsWith(char *begin, char *end); 7 | void WaitFor(u32 ms); 8 | void RebootToPayloadOrRcm(); 9 | 10 | #define FREE(x) free(x); x = NULL; 11 | char *ShowKeyboard(const char *toEdit, u8 alwaysRet); 12 | 13 | void power_off(); 14 | void reboot_rcm(); 15 | void reboot_normal(); -------------------------------------------------------------------------------- /source/utils/vector.c: -------------------------------------------------------------------------------- 1 | #include "vector.h" 2 | #include 3 | #include 4 | 5 | Vector_t newVec(u32 typesz, u32 preallocate) 6 | { 7 | Vector_t res = { 8 | .data = calloc(preallocate, typesz), 9 | .capacity = preallocate * typesz, 10 | .count = 0, 11 | .elemSz = typesz 12 | }; 13 | // check .data != null; 14 | return res; 15 | } 16 | 17 | Vector_t vecFromArray(void* array, u32 count, u32 typesz) 18 | { 19 | Vector_t res = { 20 | .data = array, 21 | .capacity = count * typesz, 22 | .count = count, 23 | .elemSz = typesz 24 | }; 25 | return res; 26 | } 27 | 28 | bool vecAdd(Vector_t* v, void* elem, u32 sz) 29 | { 30 | if (!v || !elem || v->elemSz != sz) 31 | return false; 32 | 33 | u32 usedbytes = v->count * sz; 34 | if (usedbytes >= v->capacity) 35 | { 36 | v->capacity *= 2; 37 | void *buff = malloc(v->capacity); 38 | if (!buff) 39 | return false; 40 | memcpy(buff, v->data, v->capacity / 2); 41 | free(v->data); 42 | v->data = buff; 43 | } 44 | 45 | memcpy((char*)v->data + usedbytes, elem, sz); 46 | v->count++; 47 | return true; 48 | } 49 | 50 | Vector_t vecCopyOffset(Vector_t* orig, u32 offset) { 51 | Vector_t dst = newVec(orig->elemSz, orig->count - offset); 52 | memcpy(dst.data, ((u8*)orig->data + orig->elemSz * offset), (orig->count - offset) * orig->elemSz); 53 | dst.count = orig->count - offset; 54 | return dst; 55 | } 56 | 57 | Vector_t vecCopy(Vector_t* orig) { 58 | return vecCopyOffset(orig, 0); 59 | } 60 | 61 | -------------------------------------------------------------------------------- /source/utils/vector.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | typedef struct { 5 | void* data; 6 | u32 capacity; 7 | u32 count; 8 | u32 elemSz; 9 | // u32 typeTag; 10 | } Vector_t; 11 | 12 | #define FREE(x) free(x); x = NULL; 13 | 14 | #define vecAddElem(v, elem) vecAdd(v, &elem, sizeof(elem)) 15 | #define vecAddElement(v, elem) vecAdd(v, &elem, sizeof(elem)) 16 | #define vecDefArray(type, varName, vec) type varName = (type)((vec).data) 17 | #define vecGetArray(type, vec) (type)((vec).data) 18 | #define vecPDefArray(type, varName, vec) type varName = (type)((vec)->data) 19 | #define vecPGetArray(type, vec) (type)((vec)->data) 20 | #define vecFreePtr(vec) FREE(vec->data) 21 | #define vecFree(vec) FREE(vec.data) 22 | #define vecGetCapacity(vec) (vec.capacity / vec.elemSz) 23 | 24 | #define vecGetArrayPtr(vec, type) (type)((vec)->data) 25 | 26 | Vector_t newVec(u32 typesz, u32 preallocate); 27 | Vector_t vecFromArray(void* array, u32 count, u32 typesz); 28 | bool vecAdd(Vector_t* v, void* elem, u32 sz); 29 | Vector_t vecCopy(Vector_t* orig); 30 | Vector_t vecCopyOffset(Vector_t* orig, u32 offset); --------------------------------------------------------------------------------