From 5193416658236c938d98ce0ed0f2ecbdff2eac30 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Sat, 11 Feb 2023 23:51:43 +0200 Subject: [PATCH] hekate/nyx: stylistic corrections --- bootloader/hos/fss.c | 2 +- bootloader/hos/hos.c | 6 +++--- bootloader/hos/pkg2.c | 6 +++--- bootloader/hos/pkg2.h | 2 ++ bootloader/l4t/l4t.c | 2 +- bootloader/main.c | 24 +++++++++++++----------- modules/simple_sample/gfx/gfx.c | 18 +++++++++--------- nyx/nyx_gui/frontend/gui.c | 2 +- nyx/nyx_gui/frontend/gui_emummc_tools.c | 16 ++++++++-------- nyx/nyx_gui/gfx/gfx.c | 14 +++++++------- nyx/nyx_gui/nyx.c | 12 +++++------- 11 files changed, 53 insertions(+), 51 deletions(-) diff --git a/bootloader/hos/fss.c b/bootloader/hos/fss.c index c99e3e5..318f341 100644 --- a/bootloader/hos/fss.c +++ b/bootloader/hos/fss.c @@ -89,7 +89,7 @@ static void _set_fss_path_and_update_r2p(launch_ctxt_t *ctxt, const char *path) strcpy(r2p_path, path); - while(path_len) + while (path_len) { if ((r2p_path[path_len - 1] == '/') || (r2p_path[path_len - 1] == '\\')) { diff --git a/bootloader/hos/hos.c b/bootloader/hos/hos.c index 76691ee..d728b59 100644 --- a/bootloader/hos/hos.c +++ b/bootloader/hos/hos.c @@ -2,7 +2,7 @@ * Copyright (c) 2018 naehrwert * Copyright (c) 2018 st4rk * Copyright (c) 2018 Ced2911 - * Copyright (c) 2018-2022 CTCaer + * Copyright (c) 2018-2023 CTCaer * Copyright (c) 2018 balika011 * * This program is free software; you can redistribute it and/or modify it @@ -176,10 +176,10 @@ static void _se_lock(bool lock_se) gfx_printf("SE(0x4) = %08X\n", SE(0x4)); gfx_printf("SE(SE_CRYPTO_SECURITY_PERKEY_REG) = %08X\n", SE(SE_CRYPTO_SECURITY_PERKEY_REG)); gfx_printf("SE(SE_RSA_SECURITY_PERKEY_REG) = %08X\n", SE(SE_RSA_SECURITY_PERKEY_REG)); - for(u32 i = 0; i < 16; i++) + for (u32 i = 0; i < 16; i++) gfx_printf("%02X ", SE(SE_CRYPTO_KEYTABLE_ACCESS_REG + i * 4) & 0xFF); gfx_putc('\n'); - for(u32 i = 0; i < 2; i++) + for (u32 i = 0; i < 2; i++) gfx_printf("%02X ", SE(SE_RSA_KEYTABLE_ACCESS_REG + i * 4) & 0xFF); gfx_putc('\n'); gfx_hexdump(SE_BASE, (void *)SE_BASE, 0x400);*/ diff --git a/bootloader/hos/pkg2.c b/bootloader/hos/pkg2.c index c506ba5..c09df64 100644 --- a/bootloader/hos/pkg2.c +++ b/bootloader/hos/pkg2.c @@ -117,7 +117,7 @@ static void parse_external_kip_patches() kip1_patchset_t *patchsets = (kip1_patchset_t *)calloc(sizeof(kip1_patchset_t), 16); // Max 16 patchsets per kip. u32 curr_patchset_idx; - for(curr_patchset_idx = 0; curr_kip->patchset[curr_patchset_idx].name != NULL; curr_patchset_idx++) + for (curr_patchset_idx = 0; curr_kip->patchset[curr_patchset_idx].name != NULL; curr_patchset_idx++) { patchsets[curr_patchset_idx].name = curr_kip->patchset[curr_patchset_idx].name; patchsets[curr_patchset_idx].patches = curr_kip->patchset[curr_patchset_idx].patches; @@ -254,7 +254,7 @@ DPRINTF(" kip1 %d:%s @ %08X (%08X)\n", i, kip1->name, (u32)kip1, ki->size); int pkg2_has_kip(link_t *info, u64 tid) { LIST_FOREACH_ENTRY(pkg2_kip1_info_t, ki, info, link) - if(ki->kip1->tid == tid) + if (ki->kip1->tid == tid) return 1; return 0; } @@ -388,7 +388,7 @@ static int _kipm_inject(const char *kipm_path, char *target_name, pkg2_kip1_info for (u32 currSectIdx = 0; currSectIdx < KIP1_NUM_SECTIONS - 2; currSectIdx++) { - if(!currSectIdx) // .text. + if (!currSectIdx) // .text. { memcpy(ki->kip1->data + inject_size, fs_kip->data, fs_kip->sections[0].size_comp); ki->kip1->sections[0].size_decomp += inject_size; diff --git a/bootloader/hos/pkg2.h b/bootloader/hos/pkg2.h index 321d5ab..8eea648 100644 --- a/bootloader/hos/pkg2.h +++ b/bootloader/hos/pkg2.h @@ -26,6 +26,8 @@ #define PKG2_SEC_INI1 1 #define INI1_MAGIC 0x31494E49 + +//! TODO: Update on kernel change if needed. #define PKG2_NEWKERN_GET_INI1_HEURISTIC 0xD2800015 // Offset of OP + 12 is the INI1 offset. #define PKG2_NEWKERN_START 0x800 diff --git a/bootloader/l4t/l4t.c b/bootloader/l4t/l4t.c index 7b9b4d2..1b68424 100644 --- a/bootloader/l4t/l4t.c +++ b/bootloader/l4t/l4t.c @@ -1,7 +1,7 @@ /* * L4T Loader for Tegra X1 * - * Copyright (c) 2020-2022 CTCaer + * Copyright (c) 2020-2023 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/bootloader/main.c b/bootloader/main.c index 7595399..7f72ef0 100644 --- a/bootloader/main.c +++ b/bootloader/main.c @@ -1,7 +1,7 @@ /* * Copyright (c) 2018 naehrwert * - * Copyright (c) 2018-2022 CTCaer + * Copyright (c) 2018-2023 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -144,7 +144,7 @@ static void _reloc_patcher(u32 payload_dst, u32 payload_src, u32 payload_size) if (payload_size == 0x7000) { - memcpy((u8 *)(payload_src + ALIGN(PATCHED_RELOC_SZ, 0x10)), coreboot_addr, 0x7000); //Bootblock + memcpy((u8 *)(payload_src + ALIGN(PATCHED_RELOC_SZ, 0x10)), coreboot_addr, 0x7000); // Bootblock. *(vu32 *)CBFS_DRAM_EN_ADDR = CBFS_DRAM_MAGIC; } } @@ -311,6 +311,7 @@ static void _launch_payloads() // Build configuration menu. ments[0].type = MENT_BACK; ments[0].caption = "Back"; + ments[1].type = MENT_CHGLINE; while (true) @@ -389,14 +390,15 @@ static void _launch_ini_list() ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 3)); ments[0].type = MENT_BACK; ments[0].caption = "Back"; + ments[1].type = MENT_CHGLINE; u32 sec_idx = 2; LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_list_sections, link) { - if (!strcmp(ini_sec->name, "config") || - ini_sec->type == INI_COMMENT || - ini_sec->type == INI_NEWLINE) + if (ini_sec->type == INI_COMMENT || + ini_sec->type == INI_NEWLINE || + !strcmp(ini_sec->name, "config")) continue; ments[sec_idx].type = ini_sec->type; @@ -517,6 +519,7 @@ static void _launch_config() ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 6)); ments[0].type = MENT_BACK; ments[0].caption = "Back"; + ments[1].type = MENT_CHGLINE; ments[2].type = MENT_HANDLER; @@ -532,9 +535,9 @@ static void _launch_config() u32 sec_idx = 5; LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) { - if (!strcmp(ini_sec->name, "config") || - ini_sec->type == INI_COMMENT || - ini_sec->type == INI_NEWLINE) + if (ini_sec->type == INI_COMMENT || + ini_sec->type == INI_NEWLINE || + !strcmp(ini_sec->name, "config")) continue; ments[sec_idx].type = ini_sec->type; @@ -693,15 +696,14 @@ static void _nyx_load_run() reloc_meta_t *reloc = (reloc_meta_t *)(IPL_LOAD_ADDR + RELOC_META_OFF); memcpy((u8 *)nyx_str->hekate, (u8 *)reloc->start, reloc->end - reloc->start); - void (*nyx_ptr)() = (void *)nyx; - bpmp_mmu_disable(); bpmp_clk_rate_set(BPMP_CLK_NORMAL); minerva_periodic_training(); - // Some cards (Sandisk U1), do not like a fast power cycle. Wait min 100ms. + // Some cards (Sandisk U1), do not like a fast power cycle. sdmmc_storage_init_wait_sd(); + void (*nyx_ptr)() = (void *)nyx; (*nyx_ptr)(); } diff --git a/modules/simple_sample/gfx/gfx.c b/modules/simple_sample/gfx/gfx.c index 5c30ba7..0557f45 100644 --- a/modules/simple_sample/gfx/gfx.c +++ b/modules/simple_sample/gfx/gfx.c @@ -326,9 +326,9 @@ void gfx_printf(const char *fmt, ...) int fill, fcnt; va_start(ap, fmt); - while(*fmt) + while (*fmt) { - if(*fmt == '%') + if (*fmt == '%') { fmt++; fill = 0; @@ -400,17 +400,17 @@ void gfx_hexdump(u32 base, const u8 *buf, u32 len) u8 prevFontSize = gfx_con.fntsz; gfx_con.fntsz = 8; - for(u32 i = 0; i < len; i++) + for (u32 i = 0; i < len; i++) { - if(i % 0x10 == 0) + if (i % 0x10 == 0) { - if(i != 0) + if (i != 0) { gfx_puts("| "); - for(u32 j = 0; j < 0x10; j++) + for (u32 j = 0; j < 0x10; j++) { u8 c = buf[i - 0x10 + j]; - if(c >= 32 && c <= 126) + if (c >= 32 && c <= 126) gfx_putc(c); else gfx_putc('.'); @@ -431,10 +431,10 @@ void gfx_hexdump(u32 base, const u8 *buf, u32 len) gfx_puts(" "); } gfx_puts("| "); - for(u32 j = 0; j < (ln ? k : k + 1); j++) + for (u32 j = 0; j < (ln ? k : k + 1); j++) { u8 c = buf[i - k + j]; - if(c >= 32 && c <= 126) + if (c >= 32 && c <= 126) gfx_putc(c); else gfx_putc('.'); diff --git a/nyx/nyx_gui/frontend/gui.c b/nyx/nyx_gui/frontend/gui.c index 7d0d793..1a389d9 100644 --- a/nyx/nyx_gui/frontend/gui.c +++ b/nyx/nyx_gui/frontend/gui.c @@ -643,7 +643,7 @@ void manual_system_maintenance(bool refresh) for (u32 task_idx = 0; task_idx < (sizeof(system_maintenance_tasks_t) / sizeof(lv_task_t *)); task_idx++) { lv_task_t *task = system_tasks.tasks[task_idx]; - if(task && (lv_tick_elaps(task->last_run) >= task->period)) + if (task && (lv_tick_elaps(task->last_run) >= task->period)) { task->last_run = lv_tick_get(); task->task(task->param); diff --git a/nyx/nyx_gui/frontend/gui_emummc_tools.c b/nyx/nyx_gui/frontend/gui_emummc_tools.c index 958d298..16f2c55 100644 --- a/nyx/nyx_gui/frontend/gui_emummc_tools.c +++ b/nyx/nyx_gui/frontend/gui_emummc_tools.c @@ -503,7 +503,7 @@ static void _migrate_sd_backup_file_based() for (int j = 0; j < 100; j++) { update_emummc_base_folder(emu_path, base_len, j); - if(f_stat(emu_path, NULL) == FR_NO_FILE) + if (f_stat(emu_path, NULL) == FR_NO_FILE) break; } base_len = strlen(emu_path); @@ -534,7 +534,7 @@ static void _migrate_sd_backup_file_based() bool multipart = false; s_printf(backup_file_path, "%s/rawnand.bin", backup_path); - if(f_stat(backup_file_path, NULL)) + if (f_stat(backup_file_path, NULL)) multipart = true; if (!multipart) @@ -820,19 +820,19 @@ static lv_res_t _create_mbox_emummc_migrate(lv_obj_t *btn) s_printf(path_buf, "%c%c%c%c%s", 's', 'x', 'o','s', "/emunand/boot0.bin"); - if(!f_stat(path_buf, NULL)) + if (!f_stat(path_buf, NULL)) em_file = true; emmcsn_path_impl(path_buf, "", "BOOT0", &emmc_storage); - if(!f_stat(path_buf, NULL)) + if (!f_stat(path_buf, NULL)) backup = true; emmcsn_path_impl(path_buf, "", "rawnand.bin", &emmc_storage); - if(!f_stat(path_buf, NULL)) + if (!f_stat(path_buf, NULL)) rawnand_backup = true; emmcsn_path_impl(path_buf, "", "rawnand.bin.00", &emmc_storage); - if(!f_stat(path_buf, NULL)) + if (!f_stat(path_buf, NULL)) rawnand_backup = true; backup = backup && rawnand_backup; @@ -983,7 +983,7 @@ static lv_res_t _create_change_emummc_window(lv_obj_t *btn_caller) { s_printf(path, "emuMMC/%s/raw_based", &emummc_img->dirlist[emummc_idx * 256]); - if(!f_stat(path, NULL)) + if (!f_stat(path, NULL)) { f_open(&fp, path, FA_READ); u32 curr_list_sector = 0; @@ -1024,7 +1024,7 @@ static lv_res_t _create_change_emummc_window(lv_obj_t *btn_caller) { s_printf(path, "emuMMC/%s/file_based", &emummc_img->dirlist[emummc_idx * 256]); - if(!f_stat(path, NULL)) + if (!f_stat(path, NULL)) { char *tmp = &emummc_img->dirlist[emummc_idx * 256]; memcpy(&emummc_img->dirlist[file_based_idx * 256], tmp, strlen(tmp) + 1); diff --git a/nyx/nyx_gui/gfx/gfx.c b/nyx/nyx_gui/gfx/gfx.c index 32d29bf..5b38779 100644 --- a/nyx/nyx_gui/gfx/gfx.c +++ b/nyx/nyx_gui/gfx/gfx.c @@ -449,17 +449,17 @@ void gfx_hexdump(u32 base, const void *buf, u32 len) u8 prevFontSize = gfx_con.fntsz; gfx_con.fntsz = 8; - for(u32 i = 0; i < len; i++) + for (u32 i = 0; i < len; i++) { - if(i % 0x10 == 0) + if (i % 0x10 == 0) { - if(i != 0) + if (i != 0) { gfx_puts("| "); - for(u32 j = 0; j < 0x10; j++) + for (u32 j = 0; j < 0x10; j++) { u8 c = buff[i - 0x10 + j]; - if(c >= 32 && c <= 126) + if (c >= 32 && c <= 126) gfx_putc(c); else gfx_putc('.'); @@ -480,10 +480,10 @@ void gfx_hexdump(u32 base, const void *buf, u32 len) gfx_puts(" "); } gfx_puts("| "); - for(u32 j = 0; j < (ln ? k : k + 1); j++) + for (u32 j = 0; j < (ln ? k : k + 1); j++) { u8 c = buff[i - k + j]; - if(c >= 32 && c <= 126) + if (c >= 32 && c <= 126) gfx_putc(c); else gfx_putc('.'); diff --git a/nyx/nyx_gui/nyx.c b/nyx/nyx_gui/nyx.c index 02902c7..7014014 100644 --- a/nyx/nyx_gui/nyx.c +++ b/nyx/nyx_gui/nyx.c @@ -30,10 +30,6 @@ #include "frontend/fe_emmc_tools.h" #include "frontend/gui.h" -#ifdef MENU_LOGO_ENABLE -u8 *Kc_MENU_LOGO; -#endif //MENU_LOGO_ENABLE - nyx_config n_cfg; hekate_config h_cfg; @@ -121,7 +117,7 @@ void reloc_patcher(u32 payload_dst, u32 payload_src, u32 payload_size) if (payload_size == 0x7000) { - memcpy((u8 *)(payload_src + ALIGN(PATCHED_RELOC_SZ, 0x10)), coreboot_addr, 0x7000); //Bootblock + memcpy((u8 *)(payload_src + ALIGN(PATCHED_RELOC_SZ, 0x10)), coreboot_addr, 0x7000); // Bootblock. *(vu32 *)CBFS_DRAM_EN_ADDR = CBFS_DRAM_MAGIC; } } @@ -433,12 +429,13 @@ void nyx_init_load_res() void ipl_main() { - // Tegra/Horizon configuration goes to 0x80000000+, package2 goes to 0xA9800000, we place our heap in between. + // Set heap address. heap_init((void *)IPL_HEAP_START); b_cfg = (boot_cfg_t *)(nyx_str->hekate + 0x94); #ifdef DEBUG_UART_PORT + // Enable the selected uart debug port. #if (DEBUG_UART_PORT == UART_B) gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_SPIO); #elif (DEBUG_UART_PORT == UART_C) @@ -453,9 +450,10 @@ void ipl_main() uart_wait_xfer(DEBUG_UART_PORT, UART_TX_IDLE); #endif - // Initialize the rest of hw and load nyx's resources. + // Initialize the rest of hw and load Nyx resources. nyx_init_load_res(); + // Initialize Nyx GUI and show it. nyx_load_and_run(); // Halt BPMP if we managed to get out of execution.