Update BDK to hekate v6.5.5

Replaces the old vendored BDK with the one from hekate v6.5.5 (CTCaer's
2025/2026 refactors: sdmmc, SE, minerva v1.6, display, heap, return
value homogenisation). OmniNX additions re-applied on top:
bq24193_charger_connected() and jc_clear_input(); s_vprintf now ships
with the BDK.

Ported to the new API:
- sd_mount(), sdmmc_storage_* and ini_parse() now return 0 on success.
  The installer checked ini_parse() != 1, which would have made it miss
  manifest.ini and run every install as a clean install.
- SD helpers come from bdk/storage/sd.c (source/nx_sd.* removed),
  ffsystem.c from the BDK, diskio.c/ffconf.h from hekate (ffconf keeps
  the sd:/ volume prefix).
- minerva_init() needs the minerva storage; the installer still drops
  to 800 MHz afterwards.
- Payload launch follows hekate (sd_file_read, hw_deinit); coreboot
  path removed upstream.
- Stack moved to 0x96000000: the old 0x83100000 is inside the new heap.
- GUI/USB/compression parts of the BDK are not built.
This commit is contained in:
niklascfw committed 2026-11-12 23:17:18 +01:00
1 parent 14be4646d0
commit 1b4a81239b
328 files changed
+108294 -42230

No files matched your search

+40 -54
View File
@@ -21,10 +21,11 @@
#include <soc/hw_init.h>
#include <soc/pmc.h>
#include <soc/t210.h>
#include "nx_sd.h"
#include <storage/sd.h>
#include <storage/sdmmc.h>
#include <utils/btn.h>
#include <utils/util.h>
#include <soc/timer.h>
#include <utils/sprintf.h>
#include <input/joycon.h>
@@ -36,14 +37,18 @@
// Configuration
#define PAYLOAD_PATH "sd:/bootloader/update.bin"
// Payload launch defines
// Payload launch defines (same as hekate)
#define RELOC_META_OFF 0x7C
#define PATCHED_RELOC_SZ 0x94
#define PATCHED_RELOC_STACK 0x40007000
#define PATCHED_RELOC_ENTRY 0x40010000
#define EXT_PAYLOAD_ADDR 0xC0000000
#define RCM_PAYLOAD_ADDR (EXT_PAYLOAD_ADDR + ALIGN(PATCHED_RELOC_SZ, 0x10))
#define COREBOOT_END_ADDR 0xD0000000
// Stack in DRAM: the tree walkers recurse with path buffers, too deep for the
// 4KB IRAM stack hekate uses. 0x96000000 is in the unused RAM disk gap, clear
// of the heap (0x82000000-0x92000000) and the payload buffer at 0xC0000000.
#define INSTALLER_STACK_TOP 0x96000000
// Hekate config structure (simplified)
typedef struct _hekate_config
@@ -70,7 +75,6 @@ hekate_config h_cfg;
boot_cfg_t __attribute__((section ("._boot_cfg"))) b_cfg;
volatile nyx_storage_t *nyx_str = (nyx_storage_t *)NYX_STORAGE_ADDR;
static void *coreboot_addr;
static int total_errors = 0;
// Use BDK colors (CYAN/WHITE overridden for consistency; GREEN/YELLOW from types.h)
@@ -119,7 +123,7 @@ static inline bool cancel_combo_pressed(u8 btn)
}
void reloc_patcher(u32 payload_dst, u32 payload_src, u32 payload_size) {
static void reloc_patcher(u32 payload_dst, u32 payload_src, u32 payload_size) {
memcpy((u8 *)payload_src, (u8 *)IPL_LOAD_ADDR, PATCHED_RELOC_SZ);
volatile reloc_meta_t *relocator = (reloc_meta_t *)(payload_src + RELOC_META_OFF);
@@ -128,55 +132,37 @@ void reloc_patcher(u32 payload_dst, u32 payload_src, u32 payload_size) {
relocator->stack = PATCHED_RELOC_STACK;
relocator->end = payload_dst + payload_size;
relocator->ep = payload_dst;
if (payload_size == 0x7000) {
memcpy((u8 *)(payload_src + ALIGN(PATCHED_RELOC_SZ, 0x10)), coreboot_addr, 0x7000);
}
}
// Load and launch a payload (hekate update.bin). Returns only on failure.
static int launch_payload(const char *path) {
if (!path)
return 1;
if (sd_mount()) {
FIL fp;
if (f_open(&fp, path, FA_READ)) {
gfx_printf("Hekate nicht gefunden: %s\n", path);
return 1;
}
void *buf;
u32 size = f_size(&fp);
if (size < 0x30000)
buf = (void *)RCM_PAYLOAD_ADDR;
else {
coreboot_addr = (void *)(COREBOOT_END_ADDR - size);
buf = coreboot_addr;
}
if (f_read(&fp, buf, size, NULL)) {
f_close(&fp);
return 1;
}
f_close(&fp);
sd_unmount();
if (size < 0x30000) {
reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, ALIGN(size, 0x10));
hw_reinit_workaround(false, byte_swap_32(*(u32 *)(buf + size - sizeof(u32))));
} else {
reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, 0x7000);
hw_reinit_workaround(true, 0);
}
sdmmc_storage_init_wait_sd();
void (*ext_payload_ptr)() = (void *)EXT_PAYLOAD_ADDR;
(*ext_payload_ptr)();
u32 size = 0;
void *buf = sd_file_read(path, &size);
if (!buf) {
gfx_printf("Hekate nicht gefunden: %s\n", path);
return 1;
}
// Must fit IRAM (same limit as hekate).
if (size > 0x30000) {
free(buf);
gfx_printf("Payload zu gross: %s\n", path);
return 1;
}
sd_end();
memcpy((void *)RCM_PAYLOAD_ADDR, buf, size);
reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, ALIGN(size, 0x10));
hw_deinit(false);
void (*ext_payload_ptr)() = (void *)EXT_PAYLOAD_ADDR;
(*ext_payload_ptr)();
return 1;
}
@@ -196,25 +182,25 @@ extern void pivot_stack(u32 stack_top);
void ipl_main(void) {
// Hardware initialization
hw_init();
pivot_stack(IPL_STACK_TOP);
heap_init(IPL_HEAP_START);
pivot_stack(INSTALLER_STACK_TOP);
heap_init((void *)IPL_HEAP_START);
// Set bootloader's default configuration
set_default_configuration();
// Mount SD Card
if (!sd_mount()) {
// Mount SD Card (BDK: 0 = success)
if (sd_mount()) {
// Can't show error without display, just reboot
power_set_state(POWER_OFF_REBOOT);
}
// Initialize minerva for faster memory
minerva_init();
minerva_change_freq(FREQ_800);
// Train DRAM, then stay at 800 MHz like before (minerva_init ends at 1600)
if (!minerva_init((minerva_str_t *)&nyx_str->minerva))
minerva_change_freq(FREQ_800);
// Initialize display
display_init();
u32 *fb = display_init_framebuffer_pitch();
u32 *fb = display_init_window_a_pitch();
gfx_init_ctxt(fb, 720, 1280, 720);
gfx_con_init();
display_backlight_pwm_init();