This commit is contained in:
Kostas Missos 2018-12-16 16:52:38 +02:00
parent 949a034500
commit 30d3c76655
9 changed files with 51 additions and 37 deletions

View file

@ -61,9 +61,11 @@ OBJS += $(addprefix $(BUILD)/$(TARGET)/, \
elfload.o elfreloc_arm.o \ elfload.o elfreloc_arm.o \
) )
CUSTOMDEFINES := -DBLVERSIONMJ=$(BLVERSION_MAJOR) -DBLVERSIONMN=$(BLVERSION_MINOR) -DMENU_LOGO_ENABLE
#CUSTOMDEFINES += -DDEBUG
#CUSTOMDEFINES += -DDEBUG_UART_PORT=0
ARCH := -march=armv4t -mtune=arm7tdmi -mthumb -mthumb-interwork ARCH := -march=armv4t -mtune=arm7tdmi -mthumb -mthumb-interwork
CUSTOMDEFINES := -DBLVERSIONMJ=$(BLVERSION_MAJOR) -DBLVERSIONMN=$(BLVERSION_MINOR)
CUSTOMDEFINES += -DMENU_LOGO_ENABLE #-DDEBUG
CFLAGS = $(ARCH) -O2 -nostdlib -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-inline -std=gnu11 -Wall $(CUSTOMDEFINES) CFLAGS = $(ARCH) -O2 -nostdlib -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-inline -std=gnu11 -Wall $(CUSTOMDEFINES)
LDFLAGS = $(ARCH) -nostartfiles -lgcc -Wl,--nmagic,--gc-sections LDFLAGS = $(ARCH) -nostartfiles -lgcc -Wl,--nmagic,--gc-sections

View file

@ -84,7 +84,7 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir)
lblen = strlen(lbuf); lblen = strlen(lbuf);
// Remove trailing newline. // Remove trailing newline.
if (lbuf[lblen - 1] == '\n') if (lbuf[lblen - 1] == '\n' || lbuf[lblen - 1] == '\r')
lbuf[lblen - 1] = 0; lbuf[lblen - 1] = 0;
if (lblen > 2 && lbuf[0] == '[') // Create new section. if (lblen > 2 && lbuf[0] == '[') // Create new section.
@ -96,7 +96,7 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir)
} }
u32 i; u32 i;
for (i = 0; i < lblen && lbuf[i] != '\n' && lbuf[i] != ']'; i++) for (i = 0; i < lblen && lbuf[i] != ']' && lbuf[i] != '\n' && lbuf[i] != '\r'; i++)
; ;
lbuf[i] = 0; lbuf[i] = 0;
@ -114,7 +114,7 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir)
} }
u32 i; u32 i;
for (i = 0; i < lblen && lbuf[i] != '\n' && lbuf[i] != '}'; i++) for (i = 0; i < lblen && lbuf[i] != '}' && lbuf[i] != '\n' && lbuf[i] != '\r'; i++)
; ;
lbuf[i] = 0; lbuf[i] = 0;
@ -132,7 +132,7 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir)
} }
u32 i; u32 i;
for (i = 0; i < lblen && lbuf[i] != '\n'; i++) for (i = 0; i < lblen && lbuf[i] != '\n' && lbuf[i] != '\r'; i++)
; ;
lbuf[i] = 0; lbuf[i] = 0;
@ -155,7 +155,7 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir)
else if (csec && csec->type == INI_CHOICE) //Extract key/value. else if (csec && csec->type == INI_CHOICE) //Extract key/value.
{ {
u32 i; u32 i;
for (i = 0; i < lblen && lbuf[i] != '\n' && lbuf[i] != '='; i++) for (i = 0; i < lblen && lbuf[i] != '=' && lbuf[i] != '\n' && lbuf[i] != '\r'; i++)
; ;
lbuf[i] = 0; lbuf[i] = 0;

View file

@ -652,7 +652,10 @@ int _restore_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *par
res = f_open(&fp, outFilename, FA_READ); res = f_open(&fp, outFilename, FA_READ);
if (res) if (res)
{ {
WPRINTFARGS("Error (%d) while opening backup. Continuing...\n", res); if (res != FR_NO_FILE)
EPRINTFARGS("Error (%d) while opening backup. Continuing...\n", res);
else
WPRINTFARGS("Error (%d) file not found. Continuing...\n", res);
gfx_con.fntsz = 16; gfx_con.fntsz = 16;
return 0; return 0;

View file

@ -637,11 +637,11 @@ void _ipatch_process(u32 offset, u32 value)
u8 lo = value & 0xff; u8 lo = value & 0xff;
switch (value >> 8) switch (value >> 8)
{ {
case 0xdf:
gfx_printf(&gfx_con, " svc #0x%02x", lo);
break;
case 0x20: case 0x20:
gfx_printf(&gfx_con, " movs r0, #0x%02x", lo); gfx_printf(&gfx_con, " MOVS R0, #0x%02X", lo);
break;
case 0xDF:
gfx_printf(&gfx_con, " SVC #0x%02X", lo);
break; break;
} }
gfx_puts(&gfx_con, "\n"); gfx_puts(&gfx_con, "\n");
@ -688,8 +688,8 @@ void bootrom_ipatches_info()
if (!sd_save_to_file((u8 *)BOOTROM_BASE, BOOTROM_SIZE, path)) if (!sd_save_to_file((u8 *)BOOTROM_BASE, BOOTROM_SIZE, path))
gfx_puts(&gfx_con, "\nbootrom_patched.bin saved!\n"); gfx_puts(&gfx_con, "\nbootrom_patched.bin saved!\n");
u32 ipatch_backup[13]; u32 ipatch_backup[14];
memcpy(ipatch_backup, (void *) IPATCH_BASE, sizeof(ipatch_backup)); memcpy(ipatch_backup, (void *)IPATCH_BASE, sizeof(ipatch_backup));
memset((void*)IPATCH_BASE, 0, sizeof(ipatch_backup)); memset((void*)IPATCH_BASE, 0, sizeof(ipatch_backup));
emmcsn_path_impl(path, "/dumps", "bootrom_unpatched.bin", NULL); emmcsn_path_impl(path, "/dumps", "bootrom_unpatched.bin", NULL);

View file

@ -96,7 +96,7 @@ static void _se_lock(bool lock_se)
SE(SE_SECURITY_0) &= 0xFFFFFFFB; // Make access lock regs secure only. SE(SE_SECURITY_0) &= 0xFFFFFFFB; // Make access lock regs secure only.
} }
memset((void *)IPATCH_BASE, 0, 13 * sizeof(u32)); memset((void *)IPATCH_BASE, 0, 14 * sizeof(u32));
SB(SB_CSR) = 0x10; // Protected IROM enable. SB(SB_CSR) = 0x10; // Protected IROM enable.
// This is useful for documenting the bits in the SE config registers, so we can keep it around. // This is useful for documenting the bits in the SE config registers, so we can keep it around.
@ -281,10 +281,10 @@ static int _read_emmc_pkg1(launch_ctxt_t *ctxt)
ctxt->pkg1_id = pkg1_identify(ctxt->pkg1); ctxt->pkg1_id = pkg1_identify(ctxt->pkg1);
if (!ctxt->pkg1_id) if (!ctxt->pkg1_id)
{ {
gfx_printf(&gfx_con, "%kUnknown package1,\nVersion (= '%s').%k\n", 0xFFFF0000, (char *)ctxt->pkg1 + 0x10, 0xFFCCCCCC); gfx_printf(&gfx_con, "%kUnknown pkg1,\nVersion (= '%s').%k\n", 0xFFFF0000, (char *)ctxt->pkg1 + 0x10, 0xFFCCCCCC);
goto out; goto out;
} }
gfx_printf(&gfx_con, "Identified package1 ('%s'),\nKeyblob version %d\n\n", (char *)(ctxt->pkg1 + 0x10), ctxt->pkg1_id->kb); gfx_printf(&gfx_con, "Identified pkg1 ('%s'),\nKeyblob version %d\n\n", (char *)(ctxt->pkg1 + 0x10), ctxt->pkg1_id->kb);
// Read the correct keyblob. // Read the correct keyblob.
ctxt->keyblob = (u8 *)calloc(NX_EMMC_BLOCKSIZE, 1); ctxt->keyblob = (u8 *)calloc(NX_EMMC_BLOCKSIZE, 1);
@ -376,7 +376,7 @@ int hos_launch(ini_sec_t *cfg)
if (!_read_emmc_pkg1(&ctxt)) if (!_read_emmc_pkg1(&ctxt))
return 0; return 0;
gfx_printf(&gfx_con, "Loaded package1 and keyblob\n"); gfx_printf(&gfx_con, "Loaded pkg1 and keyblob\n");
// Generate keys. // Generate keys.
if (!h_cfg.se_keygen_done || ctxt.pkg1_id->kb >= KB_FIRMWARE_VERSION_620) if (!h_cfg.se_keygen_done || ctxt.pkg1_id->kb >= KB_FIRMWARE_VERSION_620)
@ -402,7 +402,7 @@ int hos_launch(ini_sec_t *cfg)
pkg1_unpack((void *)ctxt.pkg1_id->warmboot_base, (void *)ctxt.pkg1_id->secmon_base, NULL, ctxt.pkg1_id, ctxt.pkg1); pkg1_unpack((void *)ctxt.pkg1_id->warmboot_base, (void *)ctxt.pkg1_id->secmon_base, NULL, ctxt.pkg1_id, ctxt.pkg1);
gfx_printf(&gfx_con, "Decrypted and unpacked package1\n"); gfx_printf(&gfx_con, "Decrypted and unpacked pkg1\n");
} }
// Replace 'warmboot.bin' if requested. // Replace 'warmboot.bin' if requested.
@ -439,10 +439,15 @@ int hos_launch(ini_sec_t *cfg)
if (!bootConfigBuf) if (!bootConfigBuf)
return 0; return 0;
gfx_printf(&gfx_con, "Read package2\n"); gfx_printf(&gfx_con, "Read pkg2\n");
// Decrypt package2 and parse KIP1 blobs in INI1 section. // Decrypt package2 and parse KIP1 blobs in INI1 section.
pkg2_hdr_t *pkg2_hdr = pkg2_decrypt(ctxt.pkg2); pkg2_hdr_t *pkg2_hdr = pkg2_decrypt(ctxt.pkg2);
if (!pkg2_hdr)
{
gfx_printf(&gfx_con, "Pkg2 decryption failed!\n");
return 0;
}
LIST_INIT(kip1_info); LIST_INIT(kip1_info);
pkg2_parse_kips(&kip1_info, pkg2_hdr); pkg2_parse_kips(&kip1_info, pkg2_hdr);
@ -500,7 +505,7 @@ int hos_launch(ini_sec_t *cfg)
// Rebuild and encrypt package2. // Rebuild and encrypt package2.
pkg2_build_encrypt((void *)0xA9800000, ctxt.kernel, ctxt.kernel_size, &kip1_info); pkg2_build_encrypt((void *)0xA9800000, ctxt.kernel, ctxt.kernel_size, &kip1_info);
gfx_printf(&gfx_con, "Rebuilt and loaded package2\n"); gfx_printf(&gfx_con, "Rebuilt and loaded pkg2\n");
// Unmount SD card. // Unmount SD card.
sd_unmount(); sd_unmount();

View file

@ -91,28 +91,28 @@ PATCHSET_DEF(_warmboot_2_patchset,
); );
PATCHSET_DEF(_warmboot_3_patchset, PATCHSET_DEF(_warmboot_3_patchset,
{ 0x4DC, _NOPv7() } // Fuse check. { 0x4DC, _NOPv7() }, // Fuse check.
{ 0x4F0, _NOPv7() } // Segment id check. { 0x4F0, _NOPv7() } // Segment id check.
); );
PATCHSET_DEF(_warmboot_4_patchset, PATCHSET_DEF(_warmboot_4_patchset,
{ 0x544, _NOPv7() } // Fuse check. { 0x544, _NOPv7() }, // Fuse check.
{ 0x558, _NOPv7() } // Segment id check. { 0x558, _NOPv7() } // Segment id check.
); );
PATCHSET_DEF(_warmboot_5_patchset, PATCHSET_DEF(_warmboot_5_patchset,
{ 0x544, _NOPv7() } // Fuse check. { 0x544, _NOPv7() }, // Fuse check.
{ 0x558, _NOPv7() } // Segment id check. { 0x558, _NOPv7() } // Segment id check.
); );
PATCHSET_DEF(_warmboot_6_patchset, PATCHSET_DEF(_warmboot_6_patchset,
{ 0x544, _NOPv7() } // Fuse check. { 0x544, _NOPv7() }, // Fuse check.
{ 0x558, _NOPv7() } // Segment id check. { 0x558, _NOPv7() } // Segment id check.
); );
PATCHSET_DEF(_warmboot_620_patchset, PATCHSET_DEF(_warmboot_620_patchset,
{ 0x544, _NOPv7() } // Fuse check. { 0x544, _NOPv7() }, // Fuse check.
{ 0x558, _NOPv7() } // Segment id check. { 0x558, _NOPv7() } // Segment id check.
); );
/* /*

View file

@ -57,7 +57,7 @@ void config_exosphere(const char *id, u32 kb, bool debug)
exoFlags |= EXO_FLAG_620_KGN; exoFlags |= EXO_FLAG_620_KGN;
if (debug) if (debug)
exoFlags |= EXO_FLAG_DBG_PRIV | EXO_FLAG_DBG_USER; exoFlags |= EXO_FLAG_DBG_PRIV;
// Set mailbox values. // Set mailbox values.
*mb_exo_magic = EXO_MAGIC_VAL; *mb_exo_magic = EXO_MAGIC_VAL;

View file

@ -1156,16 +1156,17 @@ void ipl_main()
heap_init(0x90020000); heap_init(0x90020000);
#ifdef DEBUG_UART_PORT #ifdef DEBUG_UART_PORT
//uart_send(DEBUG_UART_PORT, (u8 *)0x40000000, 0x10000); uart_send(DEBUG_UART_PORT, (u8 *)"Hekate: Hello!\r\n", 18);
//uart_wait_idle(DEBUG_UART_PORT, UART_TX_IDLE); uart_wait_idle(DEBUG_UART_PORT, UART_TX_IDLE);
#endif #endif
// Set bootloader's default configuration. // Set bootloader's default configuration.
set_default_configuration(); set_default_configuration();
// Save sdram lp0 config. // Save sdram lp0 config.
if (ianos_loader(true, "bootloader/sys/libsys_lp0.bso", DRAM_LIB, (void *)sdram_get_params())) if (*(vu32 *)BOOTLOADER_UPDATED_MAGIC_ADDR != BOOTLOADER_UPDATED_MAGIC)
h_cfg.errors |= ERR_LIBSYS_LP0; if (ianos_loader(true, "bootloader/sys/libsys_lp0.bso", DRAM_LIB, (void *)sdram_get_params()))
h_cfg.errors |= ERR_LIBSYS_LP0;
display_init(); display_init();

View file

@ -31,6 +31,9 @@
#define UART_TX_IDLE 0x1 #define UART_TX_IDLE 0x1
#define UART_RX_IDLE 0x2 #define UART_RX_IDLE 0x2
#define UART_TX_FIFO_FULL 0x100
#define UART_RX_FIFO_EMPTY 0x200
#define UART_LCR_DLAB 0x80 #define UART_LCR_DLAB 0x80
#define UART_LCR_WORD_LENGTH_8 0x3 #define UART_LCR_WORD_LENGTH_8 0x3
#define UART_LSR_RDR 0x1 #define UART_LSR_RDR 0x1