From 1392e6eaf49b4f593e5b3ee42c76993c45f638d8 Mon Sep 17 00:00:00 2001 From: Kostas Missos Date: Mon, 24 Sep 2018 23:47:35 +0300 Subject: [PATCH] Add use of wildcard "*" for loading kips from a folder --- README.md | 2 ++ bootloader/config/ini.c | 2 +- bootloader/hos/hos.c | 64 +++++++++++++++++++++++++++++----- bootloader/libs/fatfs/ffconf.h | 2 +- bootloader/main.c | 2 +- bootloader/utils/dirlist.c | 32 ++++++++++------- bootloader/utils/dirlist.h | 2 +- 7 files changed, 82 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index abf0080..ba9389f 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ There are four possible type of entries. "**[ ]**": Boot entry, "**{ }**": Capti | bootwait=3 | 0: Disable (It also disables bootlogo. Having **VOL-** pressed since injection goes to menu.), #: Time to wait for **VOL-** to enter menu. | | customlogo=0 | 0: Use default hekate bootlogo, 1: Use bootlogo.bmp. | | verification=2 | 0: Disable Backup/Restore verification, 1: Sparse (block based, fast and not 100% reliable), 2: Full (sha256 based, slow and 100% reliable). | +| autohosoff=1 | If woke up from HOS via an rtc alarm, power off completely.| | backlight=100 | Screen backlight level. 0-255. | @@ -49,6 +50,7 @@ There are four possible type of entries. "**[ ]**": Boot entry, "**{ }**": Capti | secmon={SD path} | Replaces the security monitor binary | | kernel={SD path} | Replaces the kernel binary | | kip1={SD path} | Replaces/Adds kernel initial process. Multiple can be set. | +| kip1={SD folder}/* | Loads every .kip/.kip1 inside a folder. Compatible with single kip1 keys. | | kip1patch=patchname| Enables a kip1 patch. Specify with multiple lines and/or as CSV. Implemented patches right now are nosigchk,nogc | | fullsvcperm=1 | Disables SVC verification (full services permission) | | debugmode=1 | Enables Debug mode | diff --git a/bootloader/config/ini.c b/bootloader/config/ini.c index 37b38d3..283022d 100644 --- a/bootloader/config/ini.c +++ b/bootloader/config/ini.c @@ -45,7 +45,7 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir) if (is_dir) { - filelist = dirlist(filename); + filelist = dirlist(filename, "*.ini"); if (!filelist) { free(filename); diff --git a/bootloader/hos/hos.c b/bootloader/hos/hos.c index 3e29593..b3d85c2 100644 --- a/bootloader/hos/hos.c +++ b/bootloader/hos/hos.c @@ -38,6 +38,7 @@ #include "../config/config.h" #include "../mem/mc.h" #include "../soc/fuse.h" +#include "../utils/dirlist.h" #include "../gfx/gfx.h" extern gfx_ctxt_t gfx_ctxt; @@ -367,14 +368,61 @@ static int _config_kernel(launch_ctxt_t *ctxt, const char *value) static int _config_kip1(launch_ctxt_t *ctxt, const char *value) { FIL fp; - if (f_open(&fp, value, FA_READ) != FR_OK) - return 0; - merge_kip_t *mkip1 = (merge_kip_t *)malloc(sizeof(merge_kip_t)); - mkip1->kip1 = malloc(f_size(&fp)); - f_read(&fp, mkip1->kip1, f_size(&fp), NULL); - DPRINTF("Loaded kip1 from SD (size %08X)\n", f_size(&fp)); - f_close(&fp); - list_append(&ctxt->kip1_list, &mkip1->link); + + if (!memcmp(value + strlen(value) - 1, "*", 1)) + { + char *dir = (char *)malloc(256); + memcpy(dir, value, strlen(value) + 1); + + u32 dirlen = 0; + dir[strlen(dir) - 2] = 0; + char *filelist = dirlist(dir, "*.kip*"); + + memcpy(dir + strlen(dir), "/", 2); + dirlen = strlen(dir); + + u32 i = 0; + if (filelist) + { + while (true) + { + if (!filelist[i * 256]) + break; + + memcpy(dir + dirlen, &filelist[i * 256], strlen(&filelist[i * 256]) + 1); + if (f_open(&fp, dir, FA_READ)) + { + free(dir); + free(filelist); + + return 0; + } + merge_kip_t *mkip1 = (merge_kip_t *)malloc(sizeof(merge_kip_t)); + mkip1->kip1 = malloc(f_size(&fp)); + f_read(&fp, mkip1->kip1, f_size(&fp), NULL); + DPRINTF("Loaded kip1 from SD (size %08X)\n", f_size(&fp)); + f_close(&fp); + list_append(&ctxt->kip1_list, &mkip1->link); + + i++; + } + } + + free(dir); + free(filelist); + } + else + { + if (f_open(&fp, value, FA_READ)) + return 0; + merge_kip_t *mkip1 = (merge_kip_t *)malloc(sizeof(merge_kip_t)); + mkip1->kip1 = malloc(f_size(&fp)); + f_read(&fp, mkip1->kip1, f_size(&fp), NULL); + DPRINTF("Loaded kip1 from SD (size %08X)\n", f_size(&fp)); + f_close(&fp); + list_append(&ctxt->kip1_list, &mkip1->link); + } + return 1; } diff --git a/bootloader/libs/fatfs/ffconf.h b/bootloader/libs/fatfs/ffconf.h index 382a69a..337445e 100644 --- a/bootloader/libs/fatfs/ffconf.h +++ b/bootloader/libs/fatfs/ffconf.h @@ -33,7 +33,7 @@ / 2: Enable with LF-CRLF conversion. */ -#define FF_USE_FIND 0 +#define FF_USE_FIND 1 /* This option switches filtered directory read functions, f_findfirst() and / f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ diff --git a/bootloader/main.c b/bootloader/main.c index 1bd3800..fac5869 100644 --- a/bootloader/main.c +++ b/bootloader/main.c @@ -1968,7 +1968,7 @@ void launch_tools(u8 type) else memcpy(dir, "bootloader/libtools", 20); - filelist = dirlist(dir); + filelist = dirlist(dir, NULL); u32 i = 0; diff --git a/bootloader/utils/dirlist.c b/bootloader/utils/dirlist.c index e5ada92..ba600a7 100644 --- a/bootloader/utils/dirlist.c +++ b/bootloader/utils/dirlist.c @@ -21,7 +21,7 @@ #include "../mem/heap.h" #include "../utils/types.h" -char *dirlist(char *directory) +char *dirlist(const char *directory, const char *pattern) { u8 max_entries = 61; @@ -33,7 +33,7 @@ char *dirlist(char *directory) char *dir_entries = (char *)calloc(max_entries, 256); char *temp = (char *)calloc(1, 256); - if (!f_opendir(&dir, directory)) + if (!pattern && !f_opendir(&dir, directory)) { for (;;) { @@ -47,22 +47,30 @@ char *dirlist(char *directory) if (k > (max_entries - 1)) break; } - else - continue; } f_closedir(&dir); - - if (!k) - { - free(temp); - free(dir_entries); - return NULL; - } } - else + else if (pattern && !f_findfirst(&dir, &fno, directory, pattern) && fno.fname[0]) + { + do + { + if (!(fno.fattrib & AM_DIR)) + { + memcpy(dir_entries + (k * 256), fno.fname, strlen(fno.fname) + 1); + k++; + if (k > (max_entries - 1)) + break; + } + res = f_findnext(&dir, &fno); + } while (fno.fname[0] && !res); + f_closedir(&dir); + } + + if (!k) { free(temp); free(dir_entries); + return NULL; } diff --git a/bootloader/utils/dirlist.h b/bootloader/utils/dirlist.h index e1510e9..23ac4da 100644 --- a/bootloader/utils/dirlist.h +++ b/bootloader/utils/dirlist.h @@ -16,4 +16,4 @@ #include "../utils/types.h" -char *dirlist(char *directory); +char *dirlist(const char *directory, const char *pattern);