Various bugfixes

This commit is contained in:
CTCaer 2019-08-28 01:08:57 +03:00
parent e07dde1c58
commit 3472e7e7fb
19 changed files with 60 additions and 63 deletions

View file

@ -56,7 +56,7 @@ int create_config_entry()
if (!sd_mount()) if (!sd_mount())
return 1; return 1;
char lbuf[16]; char lbuf[32];
FIL fp; FIL fp;
bool mainIniFound = false; bool mainIniFound = false;

View file

@ -35,7 +35,7 @@ static char *_strdup(char *str)
strcpy(res, str); strcpy(res, str);
// Remove trailing space. // Remove trailing space.
if (res[strlen(res) - 1] == ' ' && strlen(res)) if (strlen(res) && res[strlen(res) - 1] == ' ')
res[strlen(res) - 1] = 0; res[strlen(res) - 1] = 0;
return res; 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 *ini_check_payload_section(ini_sec_t *cfg)
{ {
char *path = NULL;
if (cfg == NULL) if (cfg == NULL)
return NULL; return NULL;
LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg->kvs, link) LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg->kvs, link)
{ {
if (!strcmp("payload", kv->key)) if (!strcmp("payload", kv->key))
{ return kv->val;
if (!path)
path = _strdup(kv->val);
}
} }
if (path)
return path;
else
return NULL; return NULL;
} }

View file

@ -235,7 +235,7 @@
#define UV_LINE_STRIDE(x) (((x) & 0xffff) << 16) #define UV_LINE_STRIDE(x) (((x) & 0xffff) << 16)
#define DC_WIN_DV_CONTROL 0x70E #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_START_ADDR 0x800
#define DC_WINBUF_ADDR_H_OFFSET 0x806 #define DC_WINBUF_ADDR_H_OFFSET 0x806
#define DC_WINBUF_ADDR_V_OFFSET 0x808 #define DC_WINBUF_ADDR_V_OFFSET 0x808

View file

@ -26,8 +26,6 @@
#define WPRINTF(text) gfx_printf("%k"text"%k\n", 0xFFFFDD00, 0xFFCCCCCC) #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 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_init_ctxt(u32 *fb, u32 width, u32 height, u32 stride);
void gfx_clear_grey(u8 color); void gfx_clear_grey(u8 color);
void gfx_clear_partial_grey(u8 color, u32 pos_x, u32 height); void gfx_clear_partial_grey(u8 color, u32 pos_x, u32 height);

View file

@ -625,6 +625,9 @@ int hos_launch(ini_sec_t *cfg)
gfx_printf("Rebuilt & loaded pkg2\n"); gfx_printf("Rebuilt & loaded pkg2\n");
// Unmount SD card.
sd_unmount();
gfx_printf("\n%kBooting...%k\n", 0xFF96FF00, 0xFFCCCCCC); gfx_printf("\n%kBooting...%k\n", 0xFF96FF00, 0xFFCCCCCC);
// Clear pkg1/pkg2 keys. // Clear pkg1/pkg2 keys.
@ -679,9 +682,6 @@ int hos_launch(ini_sec_t *cfg)
if (ctxt.atmosphere && ctxt.secmon) if (ctxt.atmosphere && ctxt.secmon)
config_exosphere(ctxt.pkg1_id->id, ctxt.pkg1_id->kb, (void *)ctxt.pkg1_id->warmboot_base, ctxt.stock); 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. // Finalize MC carveout.
if (ctxt.pkg1_id->kb <= KB_FIRMWARE_VERSION_301) if (ctxt.pkg1_id->kb <= KB_FIRMWARE_VERSION_301)
mc_config_carveout(); mc_config_carveout();

View file

@ -811,7 +811,7 @@ static int _kipm_inject(const char *kipm_path, char *target_name, pkg2_kip1_info
{ {
if(!currSectIdx) // .text. 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_decomp += inject_size;
ki->kip1->sections[0].size_comp += inject_size; ki->kip1->sections[0].size_comp += inject_size;
} }

View file

@ -219,7 +219,6 @@ int reboot_to_sept(const u8 *tsec_fw, u32 kb)
error: error:
EPRINTF("Failed to run sept\n"); EPRINTF("Failed to run sept\n");
display_backlight_brightness(h_cfg.backlight, 1000);
btn_wait(); btn_wait();

View file

@ -300,7 +300,6 @@ int launch_payload(char *path, bool update)
} }
f_close(&fp); f_close(&fp);
free(path);
if (update && is_ipl_updated(buf)) if (update && is_ipl_updated(buf))
return 1; return 1;
@ -685,7 +684,7 @@ void nyx_load_run()
{ {
sd_mount(); sd_mount();
u8 *nyx = sd_file_read("bootloader/sys/nyx.bin", false); u8 *nyx = sd_file_read("bootloader/sys/nyx.bin", NULL);
if (!nyx) if (!nyx)
return; return;

View file

@ -46,7 +46,7 @@ static int _i2c_send_pkt(u32 idx, u32 x, u8 *buf, u32 size)
vu32 *base = (vu32 *)i2c_addrs[idx]; vu32 *base = (vu32 *)i2c_addrs[idx];
base[I2C_CMD_ADDR0] = x << 1; //Set x (send mode). base[I2C_CMD_ADDR0] = x << 1; //Set x (send mode).
base[I2C_CMD_DATA1] = tmp; //Set value. base[I2C_CMD_DATA1] = tmp; //Set value.
base[I2C_CNFG] = (2 * size - 2) | 0x2800; //Set size and send mode. base[I2C_CNFG] = ((size - 1) << 1) | 0x2800; //Set size and send mode.
_i2c_wait(base); //Kick transaction. _i2c_wait(base); //Kick transaction.
base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFFDFF) | 0x200; base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFFDFF) | 0x200;
@ -66,7 +66,7 @@ static int _i2c_recv_pkt(u32 idx, u8 *buf, u32 size, u32 x)
vu32 *base = (vu32 *)i2c_addrs[idx]; vu32 *base = (vu32 *)i2c_addrs[idx];
base[I2C_CMD_ADDR0] = (x << 1) | 1; // Set x (recv mode). base[I2C_CMD_ADDR0] = (x << 1) | 1; // Set x (recv mode).
base[I2C_CNFG] = (size - 1) << 1 | 0x2840; // Set size and recv mode. base[I2C_CNFG] = ((size - 1) << 1) | 0x2840; // Set size and recv mode.
_i2c_wait(base); // Kick transaction. _i2c_wait(base); // Kick transaction.
base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFFDFF) | 0x200; base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFFDFF) | 0x200;

View file

@ -73,8 +73,10 @@ void panic(u32 val)
TMR(TIMER_TMR9_TMR_PTV) = TIMER_EN | TIMER_PER_EN; 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_CONFIG) = TIMER_SRC(9) | TIMER_PER(1) | TIMER_PMCRESET_EN;
TMR(TIMER_WDT4_COMMAND) = TIMER_START_CNT; TMR(TIMER_WDT4_COMMAND) = TIMER_START_CNT;
while (1)
; while (true)
usleep(1);
} }
void reboot_normal() void reboot_normal()
@ -104,9 +106,13 @@ void reboot_rcm()
void power_off() void power_off()
{ {
sd_unmount(); sd_unmount();
display_end();
// Stop the alarm, in case we injected and powered off too fast. // Stop the alarm, in case we injected and powered off too fast.
max77620_rtc_stop_alarm(); max77620_rtc_stop_alarm();
i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_ONOFFCNFG1, MAX77620_ONOFFCNFG1_PWR_OFF); i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_ONOFFCNFG1, MAX77620_ONOFFCNFG1_PWR_OFF);
while (true)
usleep(1);
} }

View file

@ -56,7 +56,7 @@ int create_config_entry()
if (!sd_mount()) if (!sd_mount())
return 1; return 1;
char lbuf[16]; char lbuf[32];
FIL fp; FIL fp;
bool mainIniFound = false; bool mainIniFound = false;

View file

@ -35,7 +35,7 @@ static char *_strdup(char *str)
strcpy(res, str); strcpy(res, str);
// Remove trailing space. // Remove trailing space.
if (res[strlen(res) - 1] == ' ' && strlen(res)) if (strlen(res) && res[strlen(res) - 1] == ' ')
res[strlen(res) - 1] = 0; res[strlen(res) - 1] = 0;
return res; 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 *ini_check_payload_section(ini_sec_t *cfg)
{ {
char *path = NULL;
if (cfg == NULL) if (cfg == NULL)
return NULL; return NULL;
LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg->kvs, link) LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg->kvs, link)
{ {
if (!strcmp("payload", kv->key)) if (!strcmp("payload", kv->key))
{ return kv->val;
if (!path)
path = _strdup(kv->val);
}
} }
if (path)
return path;
else
return NULL; return NULL;
} }

View file

@ -57,8 +57,11 @@ static const pkg1_id_t _pkg1_ids[] = {
const pkg1_id_t *pkg1_identify(u8 *pkg1, char *build_date) const pkg1_id_t *pkg1_identify(u8 *pkg1, char *build_date)
{ {
if (build_date)
{
memcpy(build_date, (char *)(pkg1 + 0x10), 14); memcpy(build_date, (char *)(pkg1 + 0x10), 14);
build_date[14] = 0; build_date[14] = 0;
}
for (u32 i = 0; _pkg1_ids[i].id; i++) for (u32 i = 0; _pkg1_ids[i].id; i++)
if (!memcmp(pkg1 + 0x10, _pkg1_ids[i].id, 12)) if (!memcmp(pkg1 + 0x10, _pkg1_ids[i].id, 12))

View file

@ -73,10 +73,14 @@ extern void reloc_patcher(u32 payload_dst, u32 payload_src, u32 payload_size);
void check_sept() void check_sept()
{ {
// Check if non-hekate payload is used for sept and restore it. // 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)
{
if (!f_stat("sept/payload.bak", NULL))
{ {
f_unlink("sept/payload.bin"); f_unlink("sept/payload.bin");
f_rename("sept/payload.bak", "sept/payload.bin"); f_rename("sept/payload.bak", "sept/payload.bin");
}
return; return;
} }

View file

@ -31,9 +31,7 @@
#include "../gfx/gfx.h" #include "../gfx/gfx.h"
extern gfx_ctxt_t gfx_ctxt; #define DPRINTF(...) gfx_printf(__VA_ARGS__)
extern gfx_con_t gfx_con;
#define DPRINTF(...) gfx_printf(&gfx_con, __VA_ARGS__)
static int touch_command(u8 cmd) static int touch_command(u8 cmd)
{ {

View file

@ -46,13 +46,13 @@
#define PINMUX_AUX_UART2_TX 0xF4 #define PINMUX_AUX_UART2_TX 0xF4
#define PINMUX_AUX_UART3_TX 0x104 #define PINMUX_AUX_UART3_TX 0x104
#define PINMUX_AUX_DAP4_DIN 0x148 #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_DAP4_SCLK 0x150
#define PINMUX_AUX_GPIO_X1_AUD 0x18C #define PINMUX_AUX_GPIO_X1_AUD 0x18C
#define PINMUX_AUX_GPIO_X3_AUD 0x190 #define PINMUX_AUX_GPIO_X3_AUD 0x190
#define PINMUX_AUX_SPDIF_IN 0x1A4 #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_AP_WAKE_NFC 0x1CC
#define PINMUX_AUX_NFC_EN 0x1D0 #define PINMUX_AUX_NFC_EN 0x1D0
#define PINMUX_AUX_NFC_INT 0x1D4 #define PINMUX_AUX_NFC_INT 0x1D4

View file

@ -838,7 +838,7 @@ int _sd_storage_enable_highspeed_low_volt(sdmmc_storage_t *storage, u32 type, u8
u32 hs_type = 0; u32 hs_type = 0;
switch (type) switch (type)
{ {
case 11: case 11: // SDR104.
// Fall through if not supported. // Fall through if not supported.
if (buf[13] & SD_MODE_UHS_SDR104) 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; storage->csd.busspeed = 104;
break; break;
} }
case 10: case 10: // SDR50.
if (buf[13] & SD_MODE_UHS_SDR50) if (buf[13] & SD_MODE_UHS_SDR50)
{ {
type = 10; type = 10;
@ -857,7 +857,7 @@ int _sd_storage_enable_highspeed_low_volt(sdmmc_storage_t *storage, u32 type, u8
storage->csd.busspeed = 50; storage->csd.busspeed = 50;
break; break;
} }
case 8: case 8: // SDR12.
if (!(buf[13] & SD_MODE_UHS_SDR12)) if (!(buf[13] & SD_MODE_UHS_SDR12))
return 0; return 0;
type = 8; type = 8;

View file

@ -60,15 +60,16 @@ void set_fan_duty(u32 duty)
// Inverted polarity. // Inverted polarity.
u32 inv_duty = 236 - duty; u32 inv_duty = 236 - duty;
// If disabled send a 0 duty.
if (inv_duty == 236) if (inv_duty == 236)
inv_duty = 255; inv_duty = 255;
// Set PWM duty. // Set PWM duty.
if (inv_duty) if (inv_duty == 255)
PWM(PWM_CONTROLLER_PWM_CSR_1) = (1 << 31) | (inv_duty << 16);
else
PWM(PWM_CONTROLLER_PWM_CSR_1) = 0; 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) void get_fan_speed(u32 *duty, u32 *rpm)
{ {

View file

@ -72,8 +72,10 @@ void panic(u32 val)
TMR(TIMER_TMR9_TMR_PTV) = TIMER_EN | TIMER_PER_EN; 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_CONFIG) = TIMER_SRC(9) | TIMER_PER(1) | TIMER_PMCRESET_EN;
TMR(TIMER_WDT4_COMMAND) = TIMER_START_CNT; TMR(TIMER_WDT4_COMMAND) = TIMER_START_CNT;
while (1)
; while (true)
usleep(1);
} }
void reboot_normal() void reboot_normal()
@ -106,4 +108,7 @@ void power_off()
display_end(); display_end();
i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_ONOFFCNFG1, MAX77620_ONOFFCNFG1_PWR_OFF); i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_ONOFFCNFG1, MAX77620_ONOFFCNFG1_PWR_OFF);
while (true)
usleep(1);
} }