From 3472e7e7fb149cccdb9081d7e7b502bcc1ca139f Mon Sep 17 00:00:00 2001 From: CTCaer Date: Wed, 28 Aug 2019 01:08:57 +0300 Subject: [PATCH] Various bugfixes --- bootloader/config/config.c | 2 +- bootloader/config/ini.c | 14 +++----------- bootloader/gfx/di.h | 2 +- bootloader/gfx/gfx.h | 2 -- bootloader/hos/hos.c | 6 +++--- bootloader/hos/pkg2.c | 2 +- bootloader/hos/sept.c | 1 - bootloader/main.c | 3 +-- bootloader/soc/i2c.c | 14 +++++++------- bootloader/utils/util.c | 10 ++++++++-- nyx/nyx_gui/config/config.c | 2 +- nyx/nyx_gui/config/ini.c | 14 +++----------- nyx/nyx_gui/hos/pkg1.c | 7 +++++-- nyx/nyx_gui/hos/sept.c | 10 +++++++--- nyx/nyx_gui/input/touch.c | 4 +--- nyx/nyx_gui/soc/pinmux.h | 6 +++--- nyx/nyx_gui/storage/sdmmc.c | 6 +++--- nyx/nyx_gui/thermal/fan.c | 9 +++++---- nyx/nyx_gui/utils/util.c | 9 +++++++-- 19 files changed, 60 insertions(+), 63 deletions(-) diff --git a/bootloader/config/config.c b/bootloader/config/config.c index 2a65169..1e2db7d 100644 --- a/bootloader/config/config.c +++ b/bootloader/config/config.c @@ -56,7 +56,7 @@ int create_config_entry() if (!sd_mount()) return 1; - char lbuf[16]; + char lbuf[32]; FIL fp; bool mainIniFound = false; diff --git a/bootloader/config/ini.c b/bootloader/config/ini.c index 2dadfde..f033994 100644 --- a/bootloader/config/ini.c +++ b/bootloader/config/ini.c @@ -35,7 +35,7 @@ static char *_strdup(char *str) strcpy(res, str); // Remove trailing space. - if (res[strlen(res) - 1] == ' ' && strlen(res)) + if (strlen(res) && res[strlen(res) - 1] == ' ') res[strlen(res) - 1] = 0; return res; @@ -180,22 +180,14 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir) char *ini_check_payload_section(ini_sec_t *cfg) { - char *path = NULL; - if (cfg == NULL) return NULL; LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg->kvs, link) { if (!strcmp("payload", kv->key)) - { - if (!path) - path = _strdup(kv->val); - } + return kv->val; } - if (path) - return path; - else - return NULL; + return NULL; } diff --git a/bootloader/gfx/di.h b/bootloader/gfx/di.h index 94b64ec..69d231a 100644 --- a/bootloader/gfx/di.h +++ b/bootloader/gfx/di.h @@ -235,7 +235,7 @@ #define UV_LINE_STRIDE(x) (((x) & 0xffff) << 16) #define DC_WIN_DV_CONTROL 0x70E -// The following registers are A/B/C shadows of the 0xBC0/0xDC0/0xFC0 registers (see DISPLAY_WINDOW_HEADER). +/*! The following registers are A/B/C shadows of the 0xBC0/0xDC0/0xFC0 registers (see DISPLAY_WINDOW_HEADER). */ #define DC_WINBUF_START_ADDR 0x800 #define DC_WINBUF_ADDR_H_OFFSET 0x806 #define DC_WINBUF_ADDR_V_OFFSET 0x808 diff --git a/bootloader/gfx/gfx.h b/bootloader/gfx/gfx.h index b1b6eba..94cb0ed 100644 --- a/bootloader/gfx/gfx.h +++ b/bootloader/gfx/gfx.h @@ -26,8 +26,6 @@ #define WPRINTF(text) gfx_printf("%k"text"%k\n", 0xFFFFDD00, 0xFFCCCCCC) #define WPRINTFARGS(text, args...) gfx_printf("%k"text"%k\n", 0xFFFFDD00, args, 0xFFCCCCCC) -#define FB_ADDRESS 0xC0000000 - void gfx_init_ctxt(u32 *fb, u32 width, u32 height, u32 stride); void gfx_clear_grey(u8 color); void gfx_clear_partial_grey(u8 color, u32 pos_x, u32 height); diff --git a/bootloader/hos/hos.c b/bootloader/hos/hos.c index e7d17ae..8cbb8d4 100644 --- a/bootloader/hos/hos.c +++ b/bootloader/hos/hos.c @@ -625,6 +625,9 @@ int hos_launch(ini_sec_t *cfg) gfx_printf("Rebuilt & loaded pkg2\n"); + // Unmount SD card. + sd_unmount(); + gfx_printf("\n%kBooting...%k\n", 0xFF96FF00, 0xFFCCCCCC); // Clear pkg1/pkg2 keys. @@ -679,9 +682,6 @@ int hos_launch(ini_sec_t *cfg) if (ctxt.atmosphere && ctxt.secmon) config_exosphere(ctxt.pkg1_id->id, ctxt.pkg1_id->kb, (void *)ctxt.pkg1_id->warmboot_base, ctxt.stock); - // Unmount SD card. - sd_unmount(); - // Finalize MC carveout. if (ctxt.pkg1_id->kb <= KB_FIRMWARE_VERSION_301) mc_config_carveout(); diff --git a/bootloader/hos/pkg2.c b/bootloader/hos/pkg2.c index 2a70364..ae7dad2 100644 --- a/bootloader/hos/pkg2.c +++ b/bootloader/hos/pkg2.c @@ -811,7 +811,7 @@ static int _kipm_inject(const char *kipm_path, char *target_name, pkg2_kip1_info { if(!currSectIdx) // .text. { - memcpy(ki->kip1->data + inject_size, fs_kip->data + new_offset, fs_kip->sections[0].size_comp); + memcpy(ki->kip1->data + inject_size, fs_kip->data, fs_kip->sections[0].size_comp); ki->kip1->sections[0].size_decomp += inject_size; ki->kip1->sections[0].size_comp += inject_size; } diff --git a/bootloader/hos/sept.c b/bootloader/hos/sept.c index b4df0a4..0a5ca02 100644 --- a/bootloader/hos/sept.c +++ b/bootloader/hos/sept.c @@ -219,7 +219,6 @@ int reboot_to_sept(const u8 *tsec_fw, u32 kb) error: EPRINTF("Failed to run sept\n"); - display_backlight_brightness(h_cfg.backlight, 1000); btn_wait(); diff --git a/bootloader/main.c b/bootloader/main.c index 758ef3d..d4b6530 100644 --- a/bootloader/main.c +++ b/bootloader/main.c @@ -300,7 +300,6 @@ int launch_payload(char *path, bool update) } f_close(&fp); - free(path); if (update && is_ipl_updated(buf)) return 1; @@ -685,7 +684,7 @@ void nyx_load_run() { sd_mount(); - u8 *nyx = sd_file_read("bootloader/sys/nyx.bin", false); + u8 *nyx = sd_file_read("bootloader/sys/nyx.bin", NULL); if (!nyx) return; diff --git a/bootloader/soc/i2c.c b/bootloader/soc/i2c.c index e845693..d06d64a 100644 --- a/bootloader/soc/i2c.c +++ b/bootloader/soc/i2c.c @@ -44,10 +44,10 @@ static int _i2c_send_pkt(u32 idx, u32 x, u8 *buf, u32 size) memcpy(&tmp, buf, size); vu32 *base = (vu32 *)i2c_addrs[idx]; - base[I2C_CMD_ADDR0] = x << 1; //Set x (send mode). - base[I2C_CMD_DATA1] = tmp; //Set value. - base[I2C_CNFG] = (2 * size - 2) | 0x2800; //Set size and send mode. - _i2c_wait(base); //Kick transaction. + base[I2C_CMD_ADDR0] = x << 1; //Set x (send mode). + base[I2C_CMD_DATA1] = tmp; //Set value. + base[I2C_CNFG] = ((size - 1) << 1) | 0x2800; //Set size and send mode. + _i2c_wait(base); //Kick transaction. base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFFDFF) | 0x200; while (base[I2C_STATUS] & 0x100) @@ -65,9 +65,9 @@ static int _i2c_recv_pkt(u32 idx, u8 *buf, u32 size, u32 x) return 0; vu32 *base = (vu32 *)i2c_addrs[idx]; - base[I2C_CMD_ADDR0] = (x << 1) | 1; // Set x (recv mode). - base[I2C_CNFG] = (size - 1) << 1 | 0x2840; // Set size and recv mode. - _i2c_wait(base); // Kick transaction. + base[I2C_CMD_ADDR0] = (x << 1) | 1; // Set x (recv mode). + base[I2C_CNFG] = ((size - 1) << 1) | 0x2840; // Set size and recv mode. + _i2c_wait(base); // Kick transaction. base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFFDFF) | 0x200; while (base[I2C_STATUS] & 0x100) diff --git a/bootloader/utils/util.c b/bootloader/utils/util.c index 778db8e..4bdc1ff 100644 --- a/bootloader/utils/util.c +++ b/bootloader/utils/util.c @@ -73,8 +73,10 @@ void panic(u32 val) TMR(TIMER_TMR9_TMR_PTV) = TIMER_EN | TIMER_PER_EN; TMR(TIMER_WDT4_CONFIG) = TIMER_SRC(9) | TIMER_PER(1) | TIMER_PMCRESET_EN; TMR(TIMER_WDT4_COMMAND) = TIMER_START_CNT; - while (1) - ; + + while (true) + usleep(1); + } void reboot_normal() @@ -104,9 +106,13 @@ void reboot_rcm() void power_off() { sd_unmount(); + display_end(); // Stop the alarm, in case we injected and powered off too fast. max77620_rtc_stop_alarm(); i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_ONOFFCNFG1, MAX77620_ONOFFCNFG1_PWR_OFF); + + while (true) + usleep(1); } diff --git a/nyx/nyx_gui/config/config.c b/nyx/nyx_gui/config/config.c index 9edafd9..210f062 100644 --- a/nyx/nyx_gui/config/config.c +++ b/nyx/nyx_gui/config/config.c @@ -56,7 +56,7 @@ int create_config_entry() if (!sd_mount()) return 1; - char lbuf[16]; + char lbuf[32]; FIL fp; bool mainIniFound = false; diff --git a/nyx/nyx_gui/config/ini.c b/nyx/nyx_gui/config/ini.c index ecb97f0..8485c20 100644 --- a/nyx/nyx_gui/config/ini.c +++ b/nyx/nyx_gui/config/ini.c @@ -35,7 +35,7 @@ static char *_strdup(char *str) strcpy(res, str); // Remove trailing space. - if (res[strlen(res) - 1] == ' ' && strlen(res)) + if (strlen(res) && res[strlen(res) - 1] == ' ') res[strlen(res) - 1] = 0; return res; @@ -180,22 +180,14 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir) char *ini_check_payload_section(ini_sec_t *cfg) { - char *path = NULL; - if (cfg == NULL) return NULL; LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg->kvs, link) { if (!strcmp("payload", kv->key)) - { - if (!path) - path = _strdup(kv->val); - } + return kv->val; } - if (path) - return path; - else - return NULL; + return NULL; } diff --git a/nyx/nyx_gui/hos/pkg1.c b/nyx/nyx_gui/hos/pkg1.c index ff34af0..bd7a029 100644 --- a/nyx/nyx_gui/hos/pkg1.c +++ b/nyx/nyx_gui/hos/pkg1.c @@ -57,8 +57,11 @@ static const pkg1_id_t _pkg1_ids[] = { const pkg1_id_t *pkg1_identify(u8 *pkg1, char *build_date) { - memcpy(build_date, (char *)(pkg1 + 0x10), 14); - build_date[14] = 0; + if (build_date) + { + memcpy(build_date, (char *)(pkg1 + 0x10), 14); + build_date[14] = 0; + } for (u32 i = 0; _pkg1_ids[i].id; i++) if (!memcmp(pkg1 + 0x10, _pkg1_ids[i].id, 12)) diff --git a/nyx/nyx_gui/hos/sept.c b/nyx/nyx_gui/hos/sept.c index 3d50f41..e2a7c20 100644 --- a/nyx/nyx_gui/hos/sept.c +++ b/nyx/nyx_gui/hos/sept.c @@ -73,10 +73,14 @@ extern void reloc_patcher(u32 payload_dst, u32 payload_src, u32 payload_size); void check_sept() { // Check if non-hekate payload is used for sept and restore it. - if (h_cfg.sept_run && !f_stat("sept/payload.bak", NULL)) + if (h_cfg.sept_run) { - f_unlink("sept/payload.bin"); - f_rename("sept/payload.bak", "sept/payload.bin"); + if (!f_stat("sept/payload.bak", NULL)) + { + f_unlink("sept/payload.bin"); + f_rename("sept/payload.bak", "sept/payload.bin"); + } + return; } diff --git a/nyx/nyx_gui/input/touch.c b/nyx/nyx_gui/input/touch.c index 53550f4..a3f7540 100644 --- a/nyx/nyx_gui/input/touch.c +++ b/nyx/nyx_gui/input/touch.c @@ -31,9 +31,7 @@ #include "../gfx/gfx.h" -extern gfx_ctxt_t gfx_ctxt; -extern gfx_con_t gfx_con; -#define DPRINTF(...) gfx_printf(&gfx_con, __VA_ARGS__) +#define DPRINTF(...) gfx_printf(__VA_ARGS__) static int touch_command(u8 cmd) { diff --git a/nyx/nyx_gui/soc/pinmux.h b/nyx/nyx_gui/soc/pinmux.h index 5a7b681..a2d20b8 100644 --- a/nyx/nyx_gui/soc/pinmux.h +++ b/nyx/nyx_gui/soc/pinmux.h @@ -46,13 +46,13 @@ #define PINMUX_AUX_UART2_TX 0xF4 #define PINMUX_AUX_UART3_TX 0x104 #define PINMUX_AUX_DAP4_DIN 0x148 -#define PINMUX_AUX_USB_VBUS_EN0 0x1A8 -#define PINMUX_AUX_WIFI_EN 0x1B4 -#define PINMUX_AUX_WIFI_RST 0x1B8 #define PINMUX_AUX_DAP4_SCLK 0x150 #define PINMUX_AUX_GPIO_X1_AUD 0x18C #define PINMUX_AUX_GPIO_X3_AUD 0x190 #define PINMUX_AUX_SPDIF_IN 0x1A4 +#define PINMUX_AUX_USB_VBUS_EN0 0x1A8 +#define PINMUX_AUX_WIFI_EN 0x1B4 +#define PINMUX_AUX_WIFI_RST 0x1B8 #define PINMUX_AUX_AP_WAKE_NFC 0x1CC #define PINMUX_AUX_NFC_EN 0x1D0 #define PINMUX_AUX_NFC_INT 0x1D4 diff --git a/nyx/nyx_gui/storage/sdmmc.c b/nyx/nyx_gui/storage/sdmmc.c index a893d08..a52f411 100644 --- a/nyx/nyx_gui/storage/sdmmc.c +++ b/nyx/nyx_gui/storage/sdmmc.c @@ -838,7 +838,7 @@ int _sd_storage_enable_highspeed_low_volt(sdmmc_storage_t *storage, u32 type, u8 u32 hs_type = 0; switch (type) { - case 11: + case 11: // SDR104. // Fall through if not supported. if (buf[13] & SD_MODE_UHS_SDR104) { @@ -848,7 +848,7 @@ int _sd_storage_enable_highspeed_low_volt(sdmmc_storage_t *storage, u32 type, u8 storage->csd.busspeed = 104; break; } - case 10: + case 10: // SDR50. if (buf[13] & SD_MODE_UHS_SDR50) { type = 10; @@ -857,7 +857,7 @@ int _sd_storage_enable_highspeed_low_volt(sdmmc_storage_t *storage, u32 type, u8 storage->csd.busspeed = 50; break; } - case 8: + case 8: // SDR12. if (!(buf[13] & SD_MODE_UHS_SDR12)) return 0; type = 8; diff --git a/nyx/nyx_gui/thermal/fan.c b/nyx/nyx_gui/thermal/fan.c index f7c967a..c8f96b7 100644 --- a/nyx/nyx_gui/thermal/fan.c +++ b/nyx/nyx_gui/thermal/fan.c @@ -60,15 +60,16 @@ void set_fan_duty(u32 duty) // Inverted polarity. u32 inv_duty = 236 - duty; + + // If disabled send a 0 duty. if (inv_duty == 236) inv_duty = 255; // Set PWM duty. - if (inv_duty) - PWM(PWM_CONTROLLER_PWM_CSR_1) = (1 << 31) | (inv_duty << 16); - else + if (inv_duty == 255) PWM(PWM_CONTROLLER_PWM_CSR_1) = 0; -} + else + PWM(PWM_CONTROLLER_PWM_CSR_1) = (1 << 31) | (inv_duty << 16); void get_fan_speed(u32 *duty, u32 *rpm) { diff --git a/nyx/nyx_gui/utils/util.c b/nyx/nyx_gui/utils/util.c index fc13566..6ec67a3 100644 --- a/nyx/nyx_gui/utils/util.c +++ b/nyx/nyx_gui/utils/util.c @@ -72,8 +72,10 @@ void panic(u32 val) TMR(TIMER_TMR9_TMR_PTV) = TIMER_EN | TIMER_PER_EN; TMR(TIMER_WDT4_CONFIG) = TIMER_SRC(9) | TIMER_PER(1) | TIMER_PMCRESET_EN; TMR(TIMER_WDT4_COMMAND) = TIMER_START_CNT; - while (1) - ; + + while (true) + usleep(1); + } void reboot_normal() @@ -106,4 +108,7 @@ void power_off() display_end(); i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_ONOFFCNFG1, MAX77620_ONOFFCNFG1_PWR_OFF); + + while (true) + usleep(1); }