Nyx: emuMMC Manage window, Tools UI, and misc updates

- Add gui_emu_tools: emuMMC Manage window with correct positioning (LV_PROTECT_PARENT + re-parent to win)
- Tools: single SD button (tap = SD partition manager, 3s hold = eMMC)
- Remove emuSD from Nyx UI (tabs, UMS, partition manager); keep bootloader emusd
- Shorten Create emuMMC description text by one character
- Storage/build/config and dependency updates

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-02-20 20:49:48 +01:00
parent 4eead2c14d
commit fed7f05831
81 changed files with 6932 additions and 3462 deletions

View File

@@ -13,7 +13,7 @@ include ./../Versions.inc
################################################################################
TARGET := nyx
BUILDDIR := ./../build/$(TARGET)
BUILDDIR := ./../build
OUTPUTDIR := ./../output
SOURCEDIR = nyx_gui
BDKDIR := bdk
@@ -22,47 +22,54 @@ VPATH = $(dir $(wildcard ./$(SOURCEDIR)/)) $(dir $(wildcard ./$(SOURCEDIR)/*/))
VPATH += $(dir $(wildcard ./$(SOURCEDIR)/*/*/*/)) $(dir $(wildcard ./$(SOURCEDIR)/*/*/*/*/))
VPATH += $(dir $(wildcard ../$(BDKDIR)/)) $(dir $(wildcard ../$(BDKDIR)/*/)) $(dir $(wildcard ../$(BDKDIR)/*/*/)) $(dir $(wildcard ../$(BDKDIR)/*/*/*/))
# Track compiler flags
TRACK_CFLAGS = $(BUILDDIR)/.cflags
TRACK_LDFLAGS = $(BUILDDIR)/.ldflags
# Main and graphics.
OBJS = start exception_handlers nyx heap gfx \
gui gui_info gui_tools gui_options gui_emmc_tools gui_emummc_tools gui_tools_partition_manager \
fe_emummc_tools fe_emmc_tools
OBJS = $(addprefix $(BUILDDIR)/$(TARGET)/, \
start.o exception_handlers.o \
nyx.o heap.o \
gfx.o \
gui.o gui_info.o gui_tools.o gui_options.o gui_emmc_tools.o gui_emummc_tools.o gui_tools_partition_manager.o gui_emu_tools.o \
fe_emummc_tools.o fe_emmc_tools.o \
)
# Hardware.
OBJS += actmon bpmp ccplex clock di vic i2c irq timer \
gpio pinmux pmc se smmu tsec uart \
fuse kfuse \
mc sdram minerva ramdisk \
sdmmc sdmmc_driver emmc sd nx_emmc_bis \
bm92t36 bq24193 max17050 max7762x max77620-rtc regulator_5v \
touch joycon tmp451 fan \
usbd xusbd usb_descriptors usb_gadget_ums usb_gadget_hid \
hw_init
OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \
bpmp.o ccplex.o clock.o di.o vic.o i2c.o irq.o timer.o \
gpio.o pinmux.o pmc.o se.o smmu.o tsec.o uart.o \
fuse.o kfuse.o \
mc.o sdram.o minerva.o ramdisk.o \
sdmmc.o sdmmc_driver.o emmc.o sd.o nx_emmc_bis.o \
bm92t36.o bq24193.o max17050.o max7762x.o max77620-rtc.o regulator_5v.o \
touch.o joycon.o tmp451.o fan.o \
usbd.o xusbd.o usb_descriptors.o usb_gadget_ums.o usb_gadget_hid.o \
hw_init.o boot_storage.o sfd.o mbr_gpt.o emummc_file_based.o file_based_storage.o \
)
# Utilities.
OBJS += btn dirlist ianos ini util config sprintf
OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \
btn.o dirlist.o ianos.o util.o \
config.o ini.o \
sprintf.o \
)
# Horizon.
OBJS += hos pkg1 pkg2
OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \
hos.o pkg1.o pkg2.o \
)
# Libraries.
OBJS += diskio ff ffunicode ffsystem \
elfload elfreloc_arm blz \
lv_group lv_indev lv_obj lv_refr lv_style lv_vdb \
lv_draw lv_draw_rbasic lv_draw_vbasic lv_draw_arc lv_draw_img \
lv_draw_label lv_draw_line lv_draw_rect lv_draw_triangle \
lv_hal_disp lv_hal_indev lv_hal_tick \
interui_20 interui_30 ubuntu_mono hekate_symbol_20 hekate_symbol_30 hekate_symbol_120 lv_font_builtin \
lv_anim lv_area lv_circ lv_color lv_font lv_ll lv_math lv_mem lv_task lv_txt lv_gc \
lv_bar lv_btn lv_btnm lv_cb lv_cont lv_ddlist lv_img lv_label lv_line lv_list lv_lmeter lv_mbox \
lv_page lv_roller lv_slider lv_sw lv_tabview lv_ta lv_win lv_log lv_imgbtn \
lv_theme lv_theme_hekate
OBJS := $(addsuffix .o, $(OBJS))
OBJS := $(addprefix $(BUILDDIR)/, $(OBJS))
OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \
diskio.o ff.o ffunicode.o ffsystem.o \
elfload.o elfreloc_arm.o blz.o \
lv_group.o lv_indev.o lv_obj.o lv_refr.o lv_style.o lv_vdb.o \
lv_draw.o lv_draw_rbasic.o lv_draw_vbasic.o lv_draw_arc.o lv_draw_img.o \
lv_draw_label.o lv_draw_line.o lv_draw_rect.o lv_draw_triangle.o \
lv_hal_disp.o lv_hal_indev.o lv_hal_tick.o \
interui_20.o interui_30.o ubuntu_mono.o hekate_symbol_20.o hekate_symbol_30.o hekate_symbol_120.o lv_font_builtin.o \
lv_anim.o lv_area.o lv_circ.o lv_color.o lv_font.o lv_ll.o lv_math.o lv_mem.o lv_task.o lv_txt.o lv_gc.o \
lv_bar.o lv_btn.o lv_btnm.o lv_cb.o lv_cont.o lv_ddlist.o lv_img.o lv_label.o lv_line.o lv_list.o lv_lmeter.o lv_mbox.o \
lv_page.o lv_roller.o lv_slider.o lv_sw.o lv_tabview.o lv_ta.o lv_win.o lv_log.o lv_imgbtn.o \
lv_theme.o lv_theme_hekate.o \
)
GFX_INC := '"../nyx/$(SOURCEDIR)/gfx/gfx.h"'
FFCFG_INC := '"../nyx/$(SOURCEDIR)/libs/fatfs/ffconf.h"'
@@ -94,14 +101,6 @@ ARCH := -march=armv4t -mtune=arm7tdmi -mthumb-interwork $(WARNINGS)
CFLAGS = $(ARCH) -O2 -g -gdwarf-4 -nostdlib -ffunction-sections -fdata-sections -fomit-frame-pointer -std=gnu11 $(CUSTOMDEFINES)
LDFLAGS = $(ARCH) -nostartfiles -lgcc -Wl,--nmagic,--gc-sections -Xlinker --defsym=NYX_LOAD_ADDR=$(NYX_LOAD_ADDR)
ifndef NYXECHO
T := $(shell $(MAKE) $(BUILDDIR)/$(TARGET).elf --no-print-directory -nrRf $(firstword $(MAKEFILE_LIST)) NYXECHO="NYXOBJ" | grep -c "NYXOBJ")
N := x
C = $(words $N)$(eval N := x $N)
NYXECHO = echo -ne "\r`expr " [\`expr $C '*' 100 / $T\`" : '.*\(....\)$$'`%]\033[K"
endif
################################################################################
.PHONY: all clean
@@ -118,29 +117,24 @@ clean:
@rm -rf $(BUILDDIR)
@rm -rf $(OUTPUTDIR)
$(TARGET).bin: $(BUILDDIR)/$(TARGET).elf
$(TARGET).bin: $(BUILDDIR)/$(TARGET)/$(TARGET).elf
@$(OBJCOPY) -S -O binary $< $(OUTPUTDIR)/$@
$(BUILDDIR)/$(TARGET).elf: $(OBJS) $(TRACK_LDFLAGS)
@echo -ne "\r[100%] Linking $(TARGET).elf\033[K"
@$(CC) $(LDFLAGS) -T $(SOURCEDIR)/link.ld $(OBJS) -o $@
@printf "\n$(TARGET) was built with the following flags:\nCFLAGS: $(CFLAGS)\nLDFLAGS: $(LDFLAGS)\n"
$(BUILDDIR)/$(TARGET)/$(TARGET).elf: $(OBJS)
@$(CC) $(LDFLAGS) -T $(SOURCEDIR)/link.ld $^ -o $@
@printf "$(TARGET) was built with the following flags:\nCFLAGS: $(CFLAGS)\nLDFLAGS: $(LDFLAGS)\n"
$(BUILDDIR)/%.o: %.c $(TRACK_CFLAGS) | $(BUILDDIR)
@$(NYXECHO) Building $@
@$(CC) $(CFLAGS) $(BDKINC) -MMD -MP -c $< -o $@
$(BUILDDIR)/$(TARGET)/%.o: %.c
@echo Building $@
@$(CC) $(CFLAGS) $(BDKINC) -c $< -o $@
$(BUILDDIR)/%.o: %.S $(TRACK_CFLAGS) | $(BUILDDIR)
@$(NYXECHO) Building $@
@$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
$(BUILDDIR)/$(TARGET)/%.o: %.S
@echo Building $@
@$(CC) $(CFLAGS) -c $< -o $@
$(BUILDDIR):
$(OBJS): $(BUILDDIR)/$(TARGET)
$(BUILDDIR)/$(TARGET):
@mkdir -p "$(BUILDDIR)"
@mkdir -p "$(BUILDDIR)/$(TARGET)"
@mkdir -p "$(OUTPUTDIR)"
# Non objects change detectors.
$(TRACK_CFLAGS): $(BUILDDIR)
@echo '$(CFLAGS)' | cmp -s - $@ || echo '$(CFLAGS)' > $@
$(TRACK_LDFLAGS): $(BUILDDIR)
@echo '$(LDFLAGS)' | cmp -s - $@ || echo '$(LDFLAGS)' > $@
-include $(OBJS:.o=.d)

View File

@@ -21,11 +21,11 @@
#include "config.h"
#include <libs/fatfs/ff.h>
#include <storage/boot_storage.h>
void set_default_configuration()
{
h_cfg.t210b01 = hw_get_chip_id() == GP_HIDREV_MAJOR_T210B01;
h_cfg.devmode = fuse_read_hw_state();
h_cfg.autoboot = 0;
h_cfg.autoboot_list = 0;
@@ -186,9 +186,9 @@ int create_config_entry()
int create_nyx_config_entry(bool force_unmount)
{
bool sd_mounted = sd_get_card_mounted();
bool sd_mounted = boot_storage_get_mounted();
if (!sd_mount())
if (!boot_storage_mount())
return 1;
char lbuf[64];
@@ -250,7 +250,7 @@ int create_nyx_config_entry(bool force_unmount)
f_close(&fp);
if (force_unmount || !sd_mounted)
sd_unmount();
boot_storage_unmount();
return 0;
}

View File

@@ -35,7 +35,6 @@ typedef struct _hekate_config
u32 bootprotect;
// Global temporary config.
bool t210b01;
bool devmode;
bool emummc_force_disable;
bool rcm_patched;
bool autorcm_enabled;

View File

@@ -1,7 +1,7 @@
/*
* Copyright (c) 2018 naehrwert
* Copyright (c) 2018 Rajko Stojadinovic
* Copyright (c) 2018-2025 CTCaer
* Copyright (c) 2018-2024 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,
@@ -18,6 +18,7 @@
//! fix the dram stuff and the pop ups
#include <storage/boot_storage.h>
#include <string.h>
#include <stdlib.h>
@@ -29,10 +30,6 @@
#include "../config.h"
#include <libs/fatfs/ff.h>
#define VERIF_STATUS_OK 0
#define VERIF_STATUS_ERROR 1
#define VERIF_STATUS_ABORT 2
#define NUM_SECTORS_PER_ITER 8192 // 4MB Cache.
#define OUT_FILENAME_SZ 128
#define HASH_FILENAME_SZ (OUT_FILENAME_SZ + 11) // 11 == strlen(".sha256sums")
@@ -141,7 +138,7 @@ static void _update_filename(char *outFilename, u32 sdPathLen, u32 currPartIdx)
itoa(currPartIdx, &outFilename[sdPathLen], 10);
}
static int _emmc_sd_copy_verify(emmc_tool_gui_t *gui, sdmmc_storage_t *storage, u32 lba_curr, const char *outFilename, const emmc_part_t *part)
static int _dump_emmc_verify(emmc_tool_gui_t *gui, sdmmc_storage_t *storage, u32 lba_curr, const char *outFilename, const emmc_part_t *part)
{
FIL fp;
FIL hashFp;
@@ -174,7 +171,7 @@ static int _emmc_sd_copy_verify(emmc_tool_gui_t *gui, sdmmc_storage_t *storage,
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
return VERIF_STATUS_ERROR;
return 1;
}
char chunkSizeAscii[10];
@@ -225,11 +222,10 @@ static int _emmc_sd_copy_verify(emmc_tool_gui_t *gui, sdmmc_storage_t *storage,
if (n_cfg.verification == 3)
f_close(&hashFp);
return VERIF_STATUS_ERROR;
return 1;
}
manual_system_maintenance(false);
se_sha_hash_256_async(hashEm, bufEm, num << 9);
se_calc_sha256(hashEm, NULL, bufEm, num << 9, 0, SHA_INIT_HASH, false);
f_lseek(&fp, (u64)sdFileSector << (u64)9);
if (f_read_fast(&fp, bufSd, num << 9))
@@ -246,11 +242,11 @@ static int _emmc_sd_copy_verify(emmc_tool_gui_t *gui, sdmmc_storage_t *storage,
if (n_cfg.verification == 3)
f_close(&hashFp);
return VERIF_STATUS_ERROR;
return 1;
}
manual_system_maintenance(false);
se_sha_hash_256_finalize(hashEm);
se_sha_hash_256_oneshot(hashSd, bufSd, num << 9);
se_calc_sha256_finalize(hashEm, NULL);
se_calc_sha256_oneshot(hashSd, bufSd, num << 9);
res = memcmp(hashEm, hashSd, SE_SHA_256_SIZE / 2);
if (res)
@@ -267,7 +263,7 @@ static int _emmc_sd_copy_verify(emmc_tool_gui_t *gui, sdmmc_storage_t *storage,
if (n_cfg.verification == 3)
f_close(&hashFp);
return VERIF_STATUS_ERROR;
return 1;
}
if (n_cfg.verification == 3)
@@ -307,7 +303,7 @@ static int _emmc_sd_copy_verify(emmc_tool_gui_t *gui, sdmmc_storage_t *storage,
// Check for cancellation combo.
if (btn_read_vol() == (BTN_VOL_UP | BTN_VOL_DOWN))
{
strcpy(gui->txt_buf, "#FFDD00 Verification was cancelled!#\n");
s_printf(gui->txt_buf, "#FFDD00 Verification was cancelled!#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -317,7 +313,7 @@ static int _emmc_sd_copy_verify(emmc_tool_gui_t *gui, sdmmc_storage_t *storage,
f_close(&fp);
f_close(&hashFp);
return VERIF_STATUS_ABORT;
return 0;
}
}
free(clmt);
@@ -329,15 +325,15 @@ static int _emmc_sd_copy_verify(emmc_tool_gui_t *gui, sdmmc_storage_t *storage,
lv_label_set_text(gui->label_pct, gui->txt_buf);
manual_system_maintenance(true);
return VERIF_STATUS_OK;
return 0;
}
else
{
strcpy(gui->txt_buf, "\n#FFDD00 File not found or could not be loaded!#\n#FFDD00 Verification failed..#\n");
s_printf(gui->txt_buf, "\n#FFDD00 File not found or could not be loaded!#\n#FFDD00 Verification failed..#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
return VERIF_STATUS_ERROR;
return 1;
}
}
@@ -350,7 +346,6 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
partial_sd_full_unmount = false;
u32 verification = n_cfg.verification;
u32 multipartSplitSize = (1u << 31);
u32 lba_end = part->lba_end;
u32 totalSectors = part->lba_end - part->lba_start + 1;
@@ -376,7 +371,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
_get_valid_partition(&sector_start, &sector_size, &part_idx, true);
if (!part_idx || !sector_size)
{
strcpy(gui->txt_buf, "\n#FFDD00 Failed to find a partition...#\n");
s_printf(gui->txt_buf, "\n#FFDD00 Failed to find a partition...#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -399,7 +394,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
lv_bar_set_value(gui->bar, 0);
lv_label_set_text(gui->label_pct, " "SYMBOL_DOT" 0%");
lv_bar_set_style(gui->bar, LV_BAR_STYLE_BG, gui->bar_white_bg);
lv_bar_set_style(gui->bar, LV_BAR_STYLE_BG, lv_theme_get_current()->bar.bg);
lv_bar_set_style(gui->bar, LV_BAR_STYLE_INDIC, gui->bar_white_ind);
manual_system_maintenance(true);
@@ -414,13 +409,13 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
{
isSmallSdCard = true;
strcpy(gui->txt_buf, "\n#FFBA00 Free space is smaller than backup size.#\n");
s_printf(gui->txt_buf, "\n#FFBA00 Free space is smaller than backup size.#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
if (!maxSplitParts)
{
strcpy(gui->txt_buf, "#FFDD00 Not enough free space for Partial Backup!#\n");
s_printf(gui->txt_buf, "#FFDD00 Not enough free space for Partial Backup!#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -430,7 +425,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
// Check if we are continuing a previous raw eMMC or USER partition backup in progress.
if (f_open(&partialIdxFp, partialIdxFilename, FA_READ) == FR_OK && totalSectors > (FAT32_FILESIZE_LIMIT / EMMC_BLOCKSIZE))
{
strcpy(gui->txt_buf, "\n#AEFD14 Partial Backup in progress. Continuing...#\n");
s_printf(gui->txt_buf, "\n#AEFD14 Partial Backup in progress. Continuing...#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -443,7 +438,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
if (!maxSplitParts)
{
strcpy(gui->txt_buf, "\n#FFDD00 Not enough free space for Partial Backup!#\n");
s_printf(gui->txt_buf, "\n#FFDD00 Not enough free space for Partial Backup!#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -541,25 +536,18 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
memset(&fp, 0, sizeof(fp));
currPartIdx++;
if (verification && !gui->raw_emummc)
if (n_cfg.verification && !gui->raw_emummc)
{
// Verify part.
res = _emmc_sd_copy_verify(gui, storage, lbaStartPart, outFilename, part);
switch (res)
if (_dump_emmc_verify(gui, storage, lbaStartPart, outFilename, part))
{
case VERIF_STATUS_OK:
break;
case VERIF_STATUS_ERROR:
strcpy(gui->txt_buf, "\n#FFDD00 Please try again...#\n");
s_printf(gui->txt_buf, "#FFDD00 Please try again...#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
return 0;
case VERIF_STATUS_ABORT:
verification = 0;
break;
}
lv_bar_set_style(gui->bar, LV_BAR_STYLE_BG, gui->bar_white_bg);
return 0;
}
lv_bar_set_style(gui->bar, LV_BAR_STYLE_BG, lv_theme_get_current()->bar.bg);
lv_bar_set_style(gui->bar, LV_BAR_STYLE_INDIC, gui->bar_white_ind);
}
@@ -576,7 +564,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
}
else
{
strcpy(gui->txt_buf, "\n#FF0000 Error creating partial.idx file!#\n");
s_printf(gui->txt_buf, "\n#FF0000 Error creating partial.idx file!#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -655,7 +643,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
msleep(150);
if (retryCount >= 3)
{
strcpy(gui->txt_buf, "#FF0000 Aborting...#\nPlease try again...\n");
s_printf(gui->txt_buf, "#FF0000 Aborting...#\nPlease try again...\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -667,7 +655,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
}
else
{
strcpy(gui->txt_buf, "#FFDD00 Retrying...#\n");
s_printf(gui->txt_buf, "#FFDD00 Retrying...#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
}
@@ -698,6 +686,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
s_printf(gui->txt_buf, " "SYMBOL_DOT" %d%%", pct);
lv_label_set_text(gui->label_pct, gui->txt_buf);
manual_system_maintenance(true);
prevPct = pct;
}
@@ -715,7 +704,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
// Check for cancellation combo.
if (btn_read_vol() == (BTN_VOL_UP | BTN_VOL_DOWN))
{
strcpy(gui->txt_buf, "\n#FFDD00 The backup was cancelled!#\n");
s_printf(gui->txt_buf, "\n#FFDD00 The backup was cancelled!#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -736,12 +725,12 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
f_close(&fp);
free(clmt);
if (verification && !gui->raw_emummc)
if (n_cfg.verification && !gui->raw_emummc)
{
// Verify last part or single file backup.
if (_emmc_sd_copy_verify(gui, storage, lbaStartPart, outFilename, part) == VERIF_STATUS_ERROR)
if (_dump_emmc_verify(gui, storage, lbaStartPart, outFilename, part))
{
strcpy(gui->txt_buf, "\n#FFDD00 Please try again...#\n");
s_printf(gui->txt_buf, "\n#FFDD00 Please try again...#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -781,14 +770,16 @@ void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui)
lv_label_set_text(gui->label_info, "Checking for available free space...");
manual_system_maintenance(true);
if (!sd_mount())
if (!boot_storage_mount())
{
lv_label_set_text(gui->label_info, "#FFDD00 Failed to init SD!#");
lv_label_set_text(gui->label_info, "#FFDD00 Failed to storage!#");
goto out;
}
// Get SD Card free space for Partial Backup.
f_getfree("", &sd_fs.free_clst, NULL);
FATFS *fs = boot_storage_get_fs();
f_getfree("", &fs->free_clst, NULL);
if (!emmc_initialize(false))
{
@@ -845,9 +836,9 @@ void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui)
res = _dump_emmc_part(gui, sdPath, i, &emmc_storage, &bootPart);
if (!res)
strcpy(txt_buf, "#FFDD00 Failed!#\n");
s_printf(txt_buf, "#FFDD00 Failed!#\n");
else
strcpy(txt_buf, "Done!\n");
s_printf(txt_buf, "Done!\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf);
manual_system_maintenance(true);
@@ -886,12 +877,12 @@ void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui)
// If a part failed, don't continue.
if (!res)
{
strcpy(txt_buf, "#FFDD00 Failed!#\n");
s_printf(txt_buf, "#FFDD00 Failed!#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf);
break;
}
else
strcpy(txt_buf, "Done!\n");
s_printf(txt_buf, "Done!\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf);
manual_system_maintenance(true);
@@ -928,9 +919,9 @@ void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui)
res = _dump_emmc_part(gui, sdPath, 2, &emmc_storage, &rawPart);
if (!res)
strcpy(txt_buf, "#FFDD00 Failed!#\n");
s_printf(txt_buf, "#FFDD00 Failed!#\n");
else
strcpy(txt_buf, "Done!\n");
s_printf(txt_buf, "Done!\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf);
manual_system_maintenance(true);
@@ -954,11 +945,11 @@ out:
free(txt_buf);
free(gui->base_path);
if (!partial_sd_full_unmount)
sd_unmount();
boot_storage_unmount();
else
{
partial_sd_full_unmount = false;
sd_end();
boot_storage_end();
}
}
@@ -966,7 +957,6 @@ static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_pa
{
static const u32 SECTORS_TO_MIB_COEFF = 11;
u32 verification = n_cfg.verification;
u32 lba_end = part->lba_end;
u32 totalSectors = part->lba_end - part->lba_start + 1;
u32 currPartIdx = 0;
@@ -983,8 +973,8 @@ static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_pa
lv_bar_set_value(gui->bar, 0);
lv_label_set_text(gui->label_pct, " "SYMBOL_DOT" 0%");
lv_bar_set_style(gui->bar, LV_BAR_STYLE_BG, gui->bar_orange_bg);
lv_bar_set_style(gui->bar, LV_BAR_STYLE_INDIC, gui->bar_orange_ind);
lv_bar_set_style(gui->bar, LV_BAR_STYLE_BG, lv_theme_get_current()->bar.bg);
lv_bar_set_style(gui->bar, LV_BAR_STYLE_INDIC, gui->bar_white_ind);
manual_system_maintenance(true);
bool use_multipart = false;
@@ -997,7 +987,7 @@ static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_pa
if (f_stat(outFilename, &fno))
{
// If not, check if there are partial files and the total size matches.
strcpy(gui->txt_buf, "\nNo single file, checking for part files...\n");
s_printf(gui->txt_buf, "\nNo single file, checking for part files...\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -1023,7 +1013,7 @@ static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_pa
if ((u32)((u64)totalCheckFileSize >> (u64)9) > totalSectors)
{
strcpy(gui->txt_buf, "\n#FF8000 Size of SD Card split backup exceeds#\n#FF8000 eMMC's selected part size!#\n#FFDD00 Aborting...#");
s_printf(gui->txt_buf, "\n#FF8000 Size of SD Card split backup exceeds#\n#FF8000 eMMC's selected part size!#\n#FFDD00 Aborting...#");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -1045,14 +1035,13 @@ static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_pa
{
// Set new total sectors and lba end sector for percentage calculations.
totalSectors = (u32)((u64)totalCheckFileSize >> (u64)9);
part->lba_end = totalSectors + part->lba_start - 1;
lba_end = part->lba_end;
lba_end = totalSectors + part->lba_start - 1;
}
// Restore folder is empty.
if (!numSplitParts)
{
strcpy(gui->txt_buf, "\n#FFDD00 Restore folder is empty.#\n\n");
s_printf(gui->txt_buf, "\n#FFDD00 Restore folder is empty.#\n\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -1065,7 +1054,7 @@ static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_pa
if (check_4MB_aligned && (((u64)fno.fsize) % SZ_4M))
{
strcpy(gui->txt_buf, "\n#FFDD00 The split file must be a#\n#FFDD00 multiple of 4 MiB.#\n#FFDD00 Aborting...#");
s_printf(gui->txt_buf, "\n#FFDD00 The split file must be a#\n#FFDD00 multiple of 4 MiB.#\n#FFDD00 Aborting...#");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -1093,7 +1082,7 @@ static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_pa
if (!(btn_wait() & BTN_POWER))
{
lv_obj_del(warn_mbox_bg);
strcpy(gui->txt_buf, "\n#FF0000 Size of SD Card split backup does not match#\n#FF0000 eMMC's selected part size!#\n");
s_printf(gui->txt_buf, "\n#FF0000 Size of SD Card split backup does not match#\n#FF0000 eMMC's selected part size!#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -1103,8 +1092,7 @@ static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_pa
// Set new total sectors and lba end sector for percentage calculations.
totalSectors = (u32)((u64)totalCheckFileSize >> (u64)9);
part->lba_end = totalSectors + part->lba_start - 1;
lba_end = part->lba_end;
lba_end = totalSectors + part->lba_start - 1;
}
use_multipart = true;
_update_filename(outFilename, sdPathLen, 0);
@@ -1149,7 +1137,7 @@ multipart_not_allowed:
{
if (((u32)((u64)f_size(&fp) >> (u64)9)) > totalSectors)
{
strcpy(gui->txt_buf, "\n#FF8000 Size of SD Card backup exceeds#\n#FF8000 eMMC's selected part size!#\n#FFDD00 Aborting...#");
s_printf(gui->txt_buf, "\n#FF8000 Size of SD Card backup exceeds#\n#FF8000 eMMC's selected part size!#\n#FFDD00 Aborting...#");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -1168,7 +1156,7 @@ multipart_not_allowed:
if (!(btn_wait() & BTN_POWER))
{
lv_obj_del(warn_mbox_bg);
strcpy(gui->txt_buf, "\n#FF0000 Size of the SD Card backup does not match#\n#FF0000 eMMC's selected part size.#\n");
s_printf(gui->txt_buf, "\n#FF0000 Size of the SD Card backup does not match#\n#FF0000 eMMC's selected part size.#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -1212,7 +1200,7 @@ multipart_not_allowed:
_get_valid_partition(&sector_start, &sector_size, &part_idx, false);
if (!part_idx || !sector_size)
{
strcpy(gui->txt_buf, "\n#FFDD00 Failed to find a partition...#\n");
s_printf(gui->txt_buf, "\n#FFDD00 Failed to find a partition...#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -1234,25 +1222,17 @@ multipart_not_allowed:
memset(&fp, 0, sizeof(fp));
currPartIdx++;
if (verification && !gui->raw_emummc)
if (n_cfg.verification && !gui->raw_emummc)
{
// Verify part.
res = _emmc_sd_copy_verify(gui, storage, lbaStartPart, outFilename, part);
switch (res)
if (_dump_emmc_verify(gui, storage, lbaStartPart, outFilename, part))
{
case VERIF_STATUS_OK:
break;
case VERIF_STATUS_ERROR:
strcpy(gui->txt_buf, "\n#FFDD00 Please try again...#\n");
s_printf(gui->txt_buf, "\n#FFDD00 Please try again...#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
return 0;
case VERIF_STATUS_ABORT:
verification = 0;
break;
}
lv_bar_set_style(gui->bar, LV_BAR_STYLE_BG, gui->bar_orange_bg);
lv_bar_set_style(gui->bar, LV_BAR_STYLE_INDIC, gui->bar_orange_ind);
}
_update_filename(outFilename, sdPathLen, currPartIdx);
@@ -1320,7 +1300,7 @@ multipart_not_allowed:
msleep(150);
if (retryCount >= 3)
{
strcpy(gui->txt_buf, "#FF0000 Aborting...#\n"
s_printf(gui->txt_buf, "#FF0000 Aborting...#\n"
"#FF0000 This device may be in an inoperative state!#\n"
"#FFDD00 Please try again now!#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
@@ -1332,7 +1312,7 @@ multipart_not_allowed:
}
else
{
strcpy(gui->txt_buf, "#FFDD00 Retrying...#\n");
s_printf(gui->txt_buf, "#FFDD00 Retrying...#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
}
@@ -1364,12 +1344,12 @@ multipart_not_allowed:
f_close(&fp);
free(clmt);
if (verification && !gui->raw_emummc)
if (n_cfg.verification && !gui->raw_emummc)
{
// Verify restored data.
if (_emmc_sd_copy_verify(gui, storage, lbaStartPart, outFilename, part) == VERIF_STATUS_ERROR)
if (_dump_emmc_verify(gui, storage, lbaStartPart, outFilename, part))
{
strcpy(gui->txt_buf, "\n#FFDD00 Please try again...#\n");
s_printf(gui->txt_buf, "#FFDD00 Please try again...#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
manual_system_maintenance(true);
@@ -1394,7 +1374,7 @@ multipart_not_allowed:
f_close(&fp_raw);
s_printf(sdPath, "emuMMC/RAW%d", part_idx);
save_emummc_cfg(part_idx, sector_start, sdPath);
save_emummc_cfg(part_idx, sector_start, sdPath, DRIVE_SD);
}
return 1;
@@ -1413,18 +1393,12 @@ void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui)
manual_system_maintenance(true);
if (!gui->raw_emummc)
strcpy(txt_buf, "#FFDD00 This may render the device inoperative!#");
else
strcpy(txt_buf, "#FFDD00 This may render the emuMMC inoperative!#");
strcat(txt_buf, "\n\n#FFDD00 Are you really sure?#");
if (gui->raw_emummc)
strcat(txt_buf, "\n\nOnly the 1st emuMMC found can be restored!");
s_printf(txt_buf,
"#FFDD00 This may render the device inoperative!#\n\n"
"#FFDD00 Are you really sure?#");
if ((restoreType & PART_BOOT) || (restoreType & PART_GP_ALL))
{
strcat(txt_buf,
s_printf(txt_buf + strlen(txt_buf),
"\n\nThe mode you selected will only restore\nthe partitions that it can find.\n"
"If it is not found, it will be skipped\nand continue with the next.");
}
@@ -1513,9 +1487,9 @@ void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui)
res = _restore_emmc_part(gui, sdPath, i, &emmc_storage, &bootPart, false);
if (!res)
strcpy(txt_buf, "#FFDD00 Failed!#\n");
s_printf(txt_buf, "#FFDD00 Failed!#\n");
else if (res > 0)
strcpy(txt_buf, "Done!\n");
s_printf(txt_buf, "Done!\n");
if (res >= 0)
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf);
@@ -1549,9 +1523,9 @@ void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui)
res = _restore_emmc_part(gui, sdPath, 0, &emmc_storage, part, false);
if (!res)
strcpy(txt_buf, "#FFDD00 Failed!#\n");
s_printf(txt_buf, "#FFDD00 Failed!#\n");
else if (res > 0)
strcpy(txt_buf, "Done!\n");
s_printf(txt_buf, "Done!\n");
if (res >= 0)
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf);
@@ -1588,9 +1562,9 @@ void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui)
res = _restore_emmc_part(gui, sdPath, 2, &emmc_storage, &rawPart, true);
if (!res)
strcpy(txt_buf, "#FFDD00 Failed!#\n");
s_printf(txt_buf, "#FFDD00 Failed!#\n");
else if (res > 0)
strcpy(txt_buf, "Done!\n");
s_printf(txt_buf, "Done!\n");
if (res >= 0)
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf);

File diff suppressed because it is too large Load Diff

View File

@@ -30,11 +30,9 @@ typedef struct _emummc_cfg_t
} emummc_cfg_t;
void load_emummc_cfg(emummc_cfg_t *emu_info);
void save_emummc_cfg(u32 part_idx, u32 sector_start, const char *path);
void dump_emummc_file(emmc_tool_gui_t *gui);
void dump_emummc_raw(emmc_tool_gui_t *gui, int part_idx, u32 sector_start, u32 resized_count);
void save_emummc_cfg(u32 part_idx, u32 sector_start, const char *path, u8 drive);
void dump_emummc_file(emmc_tool_gui_t *gui, u32 resized_cnt, u8 drive);
void dump_emummc_raw(emmc_tool_gui_t *gui, int part_idx, u32 sector_start, u32 resized_count, u8 drive);
void update_emummc_base_folder(char *outFilename, u32 sdPathLen, u32 currPartIdx);
int emummc_raw_derive_bis_keys();
#endif

View File

@@ -19,6 +19,7 @@
#include <bdk.h>
#include "gui.h"
#include "gui_emu_tools.h"
#include "gui_emummc_tools.h"
#include "gui_tools.h"
#include "gui_info.h"
@@ -29,6 +30,7 @@
#include "../config.h"
#include <libs/fatfs/ff.h>
#include <storage/boot_storage.h>
extern volatile boot_cfg_t *b_cfg;
extern volatile nyx_storage_t *nyx_str;
@@ -36,7 +38,7 @@ extern volatile nyx_storage_t *nyx_str;
extern lv_res_t launch_payload(lv_obj_t *list);
static bool disp_init_done = false;
static bool do_auto_reload = false;
static bool do_reload = false;
lv_style_t hint_small_style;
lv_style_t hint_small_style_white;
@@ -187,7 +189,7 @@ static void _save_log_to_bmp(char *fname)
char path[0x80];
strcpy(path, "bootloader/screenshots");
s_printf(path + strlen(path), "/nyx%s_log.bmp", fname);
sd_save_to_file(bitmap, file_size, path);
boot_storage_save_to_file(bitmap, file_size, path);
free(bitmap);
free(fb);
@@ -200,8 +202,8 @@ static void _save_fb_to_bmp()
if (get_tmr_ms() < timer)
return;
if (do_auto_reload)
goto exit;
if (do_reload)
return;
// Invalidate data.
bpmp_mmu_maintenance(BPMP_MMU_MAINT_INVALID_WAY, false);
@@ -271,7 +273,7 @@ static void _save_fb_to_bmp()
bmp->res_v = 2834;
bmp->rsvd2 = 0;
sd_mount();
boot_storage_mount();
char path[0x80];
@@ -288,7 +290,7 @@ static void _save_fb_to_bmp()
s_printf(path + strlen(path), "/nyx%s.bmp", fname);
// Save screenshot and log.
int res = sd_save_to_file(bitmap, file_size, path);
int res = boot_storage_save_to_file(bitmap, file_size, path);
if (!res)
_save_log_to_bmp(fname);
@@ -304,7 +306,6 @@ static void _save_fb_to_bmp()
manual_system_maintenance(true);
lv_mbox_start_auto_close(mbox, 4000);
exit:
// Set timer to 2s.
timer = get_tmr_ms() + 2000;
}
@@ -664,7 +665,7 @@ void manual_system_maintenance(bool refresh)
lv_img_dsc_t *bmp_to_lvimg_obj(const char *path)
{
u32 fsize;
u8 *bitmap = sd_file_read(path, &fsize);
u8 *bitmap = boot_storage_file_read(path, &fsize);
if (!bitmap)
return NULL;
@@ -794,7 +795,7 @@ lv_res_t mbox_action(lv_obj_t *btns, const char *txt)
bool nyx_emmc_check_battery_enough()
{
if (h_cfg.devmode)
if (fuse_read_hw_state() == FUSE_NX_HW_STATE_DEV)
return true;
int batt_volt = 0;
@@ -934,34 +935,17 @@ static void _launch_hos(u8 autoboot, u8 autoboot_list)
void (*main_ptr)() = (void *)nyx_str->hekate;
boot_storage_end();
sd_end();
emmc_end();
hw_deinit(false);
(*main_ptr)();
}
void reload_nyx(lv_obj_t *obj, bool force)
void reload_nyx()
{
if (!force)
{
sd_mount();
// Check that Nyx still exists.
if (f_stat("bootloader/sys/nyx.bin", NULL))
{
sd_unmount();
// Remove lvgl object in case of being invoked from a window.
if (obj)
lv_obj_del(obj);
do_auto_reload = false;
return;
}
}
b_cfg->boot_cfg = BOOT_CFG_AUTOBOOT_EN;
b_cfg->autoboot = 0;
b_cfg->autoboot_list = 0;
@@ -969,6 +953,9 @@ void reload_nyx(lv_obj_t *obj, bool force)
void (*main_ptr)() = (void *)nyx_str->hekate;
// TODO:
boot_storage_end();
emmc_end();
sd_end();
hw_deinit(false);
@@ -979,7 +966,7 @@ void reload_nyx(lv_obj_t *obj, bool force)
static lv_res_t reload_action(lv_obj_t *btns, const char *txt)
{
if (!lv_btnm_get_pressed(btns))
reload_nyx(NULL, false);
reload_nyx();
return mbox_action(btns, txt);
}
@@ -1001,7 +988,7 @@ static lv_res_t _removed_sd_action(lv_obj_t *btns, const char *txt)
break;
case 2:
sd_end();
do_auto_reload = false;
do_reload = false;
break;
}
@@ -1010,14 +997,12 @@ static lv_res_t _removed_sd_action(lv_obj_t *btns, const char *txt)
static void _check_sd_card_removed(void *params)
{
static lv_obj_t *dark_bg = NULL;
// The following checks if SDMMC_1 is initialized.
// If yes and card was removed, shows a message box,
// that will reload Nyx, when the card is inserted again.
if (!do_auto_reload && sd_get_card_removed())
if (!do_reload && sd_get_card_removed() && boot_storage_get_drive() == DRIVE_SD)
{
dark_bg = lv_obj_create(lv_scr_act(), NULL);
lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_style(dark_bg, &mbox_darken);
lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES);
@@ -1033,12 +1018,12 @@ static void _check_sd_card_removed(void *params)
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_top(mbox, true);
do_auto_reload = true;
do_reload = true;
}
// If in reload state and card was inserted, reload nyx.
if (do_auto_reload && !sd_get_card_removed())
reload_nyx(dark_bg, false);
if (do_reload && !sd_get_card_removed() && boot_storage_get_drive() == DRIVE_SD)
reload_nyx();
}
lv_task_t *task_emmc_errors;
@@ -1472,14 +1457,15 @@ static lv_res_t _create_mbox_payloads(lv_obj_t *btn)
lv_obj_set_size(list, LV_HOR_RES * 3 / 7, LV_VER_RES * 3 / 7);
lv_list_set_single_mode(list, true);
if (!sd_mount())
if (!boot_storage_mount())
{
// TODO: may not be SD, change error
lv_mbox_set_text(mbox, "#FFDD00 Failed to init SD!#");
goto out_end;
}
dirlist_t *filelist = dirlist("bootloader/payloads", NULL, 0);
dirlist_t *filelist = dirlist("bootloader/payloads", NULL, false, false);
sd_unmount();
u32 i = 0;
@@ -1784,7 +1770,7 @@ static lv_res_t _create_window_home_launch(lv_obj_t *btn)
u32 curr_btn_idx = 0; // Active buttons.
LIST_INIT(ini_sections);
if (!sd_mount())
if (!boot_storage_mount())
goto failed_sd_mount;
// Check if we use custom system icons.
@@ -1980,7 +1966,7 @@ failed_sd_mount:
if (curr_btn_idx < 1)
no_boot_entries = true;
sd_unmount();
boot_storage_unmount();
free(tmp_path);
@@ -2147,7 +2133,7 @@ static void _create_tab_home(lv_theme_t *th, lv_obj_t *parent)
label_btn = lv_label_create(btn_emummc, label_btn);
s_printf(btn_colored_text, "%s%s", text_color, " "SYMBOL_LIST"#");
lv_label_set_text(label_btn, btn_colored_text);
lv_btn_set_action(btn_emummc, LV_BTN_ACTION_CLICK, create_win_emummc_tools);
lv_btn_set_action(btn_emummc, LV_BTN_ACTION_CLICK, create_win_emu_tools);
lv_btn_set_layout(btn_emummc, LV_LAYOUT_OFF);
lv_obj_align(label_btn, NULL, LV_ALIGN_CENTER, 0, -28);
lv_obj_set_pos(btn_emummc, 959, 160);
@@ -2179,7 +2165,7 @@ static lv_res_t _save_options_action(lv_obj_t *btn)
int res = 0;
if (sd_mount())
if (boot_storage_mount())
res = !create_config_entry();
if (res)
@@ -2191,7 +2177,7 @@ static lv_res_t _save_options_action(lv_obj_t *btn)
nyx_options_clear_ini_changes_made();
sd_unmount();
boot_storage_unmount();
return LV_RES_OK;
}

View File

@@ -28,10 +28,7 @@ typedef struct _emmc_tool_gui_t
lv_obj_t *bar;
lv_style_t *bar_teal_bg;
lv_style_t *bar_teal_ind;
lv_style_t *bar_white_bg;
lv_style_t *bar_white_ind;
lv_style_t *bar_orange_bg;
lv_style_t *bar_orange_ind;
char *txt_buf;
char *base_path;
bool raw_emummc;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2025 CTCaer
* Copyright (c) 2018-2020 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,
@@ -101,7 +101,7 @@ static void _create_window_backup_restore(emmcPartType_t type, const char* win_l
lv_obj_align(label_info, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 10);
emmc_tool_gui_ctxt.label_info = label_info;
static lv_style_t bar_teal_bg, bar_teal_ind, bar_orange_bg, bar_orange_ind, bar_white_ind;
static lv_style_t bar_teal_bg, bar_teal_ind, bar_white_ind;
lv_style_copy(&bar_teal_bg, lv_theme_get_current()->bar.bg);
bar_teal_bg.body.main_color = LV_COLOR_HEX(0x005a47);
@@ -111,23 +111,12 @@ static void _create_window_backup_restore(emmcPartType_t type, const char* win_l
bar_teal_ind.body.main_color = LV_COLOR_HEX(0x00FFC9);
bar_teal_ind.body.grad_color = bar_teal_ind.body.main_color;
lv_style_copy(&bar_orange_bg, lv_theme_get_current()->bar.bg);
bar_orange_bg.body.main_color = LV_COLOR_HEX(0x755000);
bar_orange_bg.body.grad_color = bar_orange_bg.body.main_color;
lv_style_copy(&bar_orange_ind, lv_theme_get_current()->bar.indic);
bar_orange_ind.body.main_color = LV_COLOR_HEX(0xFFAE00);
bar_orange_ind.body.grad_color = bar_orange_ind.body.main_color;
lv_style_copy(&bar_white_ind, lv_theme_get_current()->bar.indic);
bar_white_ind.body.main_color = LV_COLOR_HEX(0xF0F0F0);
bar_white_ind.body.grad_color = bar_white_ind.body.main_color;
emmc_tool_gui_ctxt.bar_teal_bg = &bar_teal_bg;
emmc_tool_gui_ctxt.bar_teal_ind = &bar_teal_ind;
emmc_tool_gui_ctxt.bar_orange_bg = &bar_orange_bg;
emmc_tool_gui_ctxt.bar_orange_ind = &bar_orange_ind;
emmc_tool_gui_ctxt.bar_white_bg = lv_theme_get_current()->bar.bg;
emmc_tool_gui_ctxt.bar_white_ind = &bar_white_ind;
lv_obj_t *bar = lv_bar_create(h1, NULL);
@@ -250,15 +239,15 @@ static lv_res_t _emmc_backup_buttons_raw_toggle(lv_obj_t *btn)
else // Backup/Restore from and to emuMMC.
{
if (!emmc_btn_ctxt.restore)
lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_boot, NULL), SYMBOL_UPLOAD" SD emuMMC BOOT0 & BOOT1");
lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_boot, NULL), SYMBOL_UPLOAD" emuMMC BOOT0 & BOOT1");
else
lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_boot, NULL), SYMBOL_DOWNLOAD" SD emuMMC BOOT0 & BOOT1");
lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_boot, NULL), SYMBOL_DOWNLOAD" emuMMC BOOT0 & BOOT1");
lv_obj_realign(emmc_btn_ctxt.emmc_boot);
if (!emmc_btn_ctxt.restore)
lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_raw_gpp, NULL), SYMBOL_UPLOAD" SD emuMMC RAW GPP");
lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_raw_gpp, NULL), SYMBOL_UPLOAD" emuMMC RAW GPP");
else
lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_raw_gpp, NULL), SYMBOL_DOWNLOAD" SD emuMMC RAW GPP");
lv_label_set_static_text(lv_obj_get_child(emmc_btn_ctxt.emmc_raw_gpp, NULL), SYMBOL_DOWNLOAD" emuMMC RAW GPP");
lv_obj_realign(emmc_btn_ctxt.emmc_raw_gpp);
lv_obj_set_click(emmc_btn_ctxt.emmc_sys, false);
@@ -464,7 +453,7 @@ lv_res_t create_window_backup_restore_tool(lv_obj_t *btn)
lv_obj_t *sd_emummc_raw = lv_btn_create(h3, NULL);
nyx_create_onoff_button(lv_theme_get_current(), h3,
sd_emummc_raw, SYMBOL_SD" SD emuMMC Raw Partition", _emmc_backup_buttons_raw_toggle, false);
sd_emummc_raw, SYMBOL_SD" emuMMC Raw Partition", _emmc_backup_buttons_raw_toggle, false);
emmc_btn_ctxt.raw_emummc = false;
return LV_RES_OK;

View File

@@ -0,0 +1,50 @@
#include "gui_emu_tools.h"
#include "gui.h"
#include "gui_emummc_tools.h"
#include <libs/lvgl/lv_core/lv_obj.h>
#include <libs/lvgl/lv_core/lv_style.h>
#include <libs/lvgl/lv_objx/lv_cont.h>
#include <libs/lvgl/lv_objx/lv_win.h>
static lv_obj_t *_create_container(lv_obj_t *parent){
static lv_style_t h_style;
lv_style_copy(&h_style, &lv_style_transp);
h_style.body.padding.inner = 0;
h_style.body.padding.hor = 0;
h_style.body.padding.ver = 0;
lv_obj_t *h1 = lv_cont_create(parent, NULL);
lv_cont_set_style(h1, &h_style);
lv_cont_set_fit(h1, false, true);
lv_obj_set_width(h1, LV_HOR_RES - 62);
lv_obj_set_click(h1, false);
lv_cont_set_layout(h1, LV_LAYOUT_OFF);
return h1;
}
lv_res_t create_win_emu_tools(lv_obj_t *btn){
lv_obj_t *win = nyx_create_standard_window(SYMBOL_EDIT " emuMMC Manage");
static lv_style_t win_style_no_pad;
lv_style_copy(&win_style_no_pad, lv_win_get_style(win, LV_WIN_STYLE_CONTENT_BG));
win_style_no_pad.body.padding.hor = 0;
win_style_no_pad.body.padding.inner = 0;
lv_win_set_style(win, LV_WIN_STYLE_CONTENT_BG, &win_style_no_pad);
/* Create container on window; win's CHILD_CHG moves it to the page, so we protect and re-parent to win */
lv_obj_t *cont = _create_container(win);
lv_obj_set_protect(cont, LV_PROTECT_PARENT);
lv_obj_set_parent(cont, win);
lv_obj_set_height(cont, 572);
create_tab_emummc_tools(cont);
/* Align to content area; y offset works now because cont stays on win */
lv_obj_t *content = lv_win_get_content(win);
lv_obj_align(cont, content, LV_ALIGN_IN_TOP_MID, -20, 50);
return LV_RES_OK;
}

View File

@@ -0,0 +1,8 @@
#ifndef _GUI_EMU_TOOLS_H_
#define _GUI_EMU_TOOLS_H_
#include <libs/lvgl/lvgl.h>
lv_res_t create_win_emu_tools(lv_obj_t *btn);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -19,6 +19,6 @@
#include <libs/lvgl/lvgl.h>
lv_res_t create_win_emummc_tools(lv_obj_t *btn);
lv_res_t create_tab_emummc_tools(lv_obj_t *parent);
#endif

View File

@@ -23,6 +23,7 @@
#include "../hos/hos.h"
#include "../hos/pkg1.h"
#include <libs/fatfs/ff.h>
#include <storage/boot_storage.h>
#include <stdlib.h>
@@ -75,15 +76,15 @@ static lv_res_t _cal0_dump_window_action(lv_obj_t *btns, const char * txt)
if (btn_idx == 1)
{
int error = !sd_mount();
int error = !boot_storage_mount();
if (!error)
{
char path[64];
emmcsn_path_impl(path, "/dumps", "cal0.bin", NULL);
error = sd_save_to_file((u8 *)cal0_buf, SZ_32K, path);
error = boot_storage_save_to_file((u8 *)cal0_buf, SZ_32K, path);
sd_unmount();
boot_storage_unmount();
}
_create_window_dump_done(error, "cal0.bin");
@@ -95,7 +96,7 @@ static lv_res_t _cal0_dump_window_action(lv_obj_t *btns, const char * txt)
static lv_res_t _battery_dump_window_action(lv_obj_t * btn)
{
int error = !sd_mount();
int error = !boot_storage_mount();
if (!error)
{
@@ -105,9 +106,9 @@ static lv_res_t _battery_dump_window_action(lv_obj_t * btn)
max17050_dump_regs(buf);
emmcsn_path_impl(path, "/dumps", "fuel_gauge.bin", NULL);
error = sd_save_to_file((u8 *)buf, 0x200, path);
error = boot_storage_save_to_file((u8 *)buf, 0x200, path);
sd_unmount();
boot_storage_unmount();
}
_create_window_dump_done(error, "fuel_gauge.bin");
@@ -119,7 +120,7 @@ static lv_res_t _bootrom_dump_window_action(lv_obj_t * btn)
{
static const u32 BOOTROM_SIZE = 0x18000;
int error = !sd_mount();
int error = !boot_storage_mount();
if (!error)
{
char path[64];
@@ -129,13 +130,13 @@ static lv_res_t _bootrom_dump_window_action(lv_obj_t * btn)
if (!error)
{
emmcsn_path_impl(path, "/dumps", "evp_thunks.bin", NULL);
error = sd_save_to_file((u8 *)iram_evp_thunks, iram_evp_thunks_len, path);
error = boot_storage_save_to_file((u8 *)iram_evp_thunks, iram_evp_thunks_len, path);
}
else
error = 255;
emmcsn_path_impl(path, "/dumps", "bootrom_patched.bin", NULL);
int res = sd_save_to_file((u8 *)IROM_BASE, BOOTROM_SIZE, path);
int res = boot_storage_save_to_file((u8 *)IROM_BASE, BOOTROM_SIZE, path);
if (!error)
error = res;
@@ -144,13 +145,13 @@ static lv_res_t _bootrom_dump_window_action(lv_obj_t * btn)
memset((void*)IPATCH_BASE, 0, sizeof(ipatch_cam)); // Zeroing valid entries is enough but zero everything.
emmcsn_path_impl(path, "/dumps", "bootrom_unpatched.bin", NULL);
res = sd_save_to_file((u8 *)IROM_BASE, BOOTROM_SIZE, path);
res = boot_storage_save_to_file((u8 *)IROM_BASE, BOOTROM_SIZE, path);
if (!error)
error = res;
memcpy((void*)IPATCH_BASE, ipatch_cam, sizeof(ipatch_cam));
sd_unmount();
boot_storage_unmount();
}
_create_window_dump_done(error, "evp_thunks.bin, bootrom_patched.bin, bootrom_unpatched.bin");
@@ -180,14 +181,14 @@ static void _unlock_reserved_odm_fuses(bool lock)
static lv_res_t _fuse_dump_window_action(lv_obj_t * btn)
{
int error = !sd_mount();
int error = !boot_storage_mount();
if (!error)
{
char path[128];
if (!h_cfg.t210b01)
{
emmcsn_path_impl(path, "/dumps", "fuse_cached_t210.bin", NULL);
error = sd_save_to_file((u8 *)0x7000F900, 0x300, path);
error = boot_storage_save_to_file((u8 *)0x7000F900, 0x300, path);
emmcsn_path_impl(path, "/dumps", "fuse_array_raw_t210.bin", NULL);
}
else
@@ -196,10 +197,10 @@ static lv_res_t _fuse_dump_window_action(lv_obj_t * btn)
_unlock_reserved_odm_fuses(false);
emmcsn_path_impl(path, "/dumps", "fuse_cached_t210b01_x898.bin", NULL);
error = sd_save_to_file((u8 *)0x7000F898, 0x68, path);
error = boot_storage_save_to_file((u8 *)0x7000F898, 0x68, path);
emmcsn_path_impl(path, "/dumps", "fuse_cached_t210b01_x900.bin", NULL);
if (!error)
error = sd_save_to_file((u8 *)0x7000F900, 0x300, path);
error = boot_storage_save_to_file((u8 *)0x7000F900, 0x300, path);
emmcsn_path_impl(path, "/dumps", "fuse_array_raw_t210b01.bin", NULL);
}
@@ -214,7 +215,7 @@ static lv_res_t _fuse_dump_window_action(lv_obj_t * btn)
if (h_cfg.t210b01)
_unlock_reserved_odm_fuses(true);
sd_unmount();
boot_storage_unmount();
}
if (!h_cfg.t210b01)
@@ -231,15 +232,15 @@ static lv_res_t _kfuse_dump_window_action(lv_obj_t * btn)
int error = !kfuse_read(buf);
if (!error)
error = !sd_mount();
error = !boot_storage_mount();
if (!error)
{
char path[64];
emmcsn_path_impl(path, "/dumps", "kfuses.bin", NULL);
error = sd_save_to_file((u8 *)buf, KFUSE_NUM_WORDS * 4, path);
error = boot_storage_save_to_file((u8 *)buf, KFUSE_NUM_WORDS * 4, path);
sd_unmount();
boot_storage_unmount();
}
_create_window_dump_done(error, "kfuses.bin");
@@ -269,7 +270,7 @@ static lv_res_t _create_mbox_cal0(lv_obj_t *btn)
lv_label_set_style(lb_desc, &monospace_text);
lv_obj_set_width(lb_desc, LV_HOR_RES / 9 * 4);
sd_mount();
boot_storage_mount();
// Dump CAL0.
int cal0_res = hos_dump_cal0();
@@ -290,7 +291,7 @@ static lv_res_t _create_mbox_cal0(lv_obj_t *btn)
nx_emmc_cal0_t *cal0 = (nx_emmc_cal0_t *)cal0_buf;
u32 hash[8];
se_sha_hash_256_oneshot(hash, (u8 *)&cal0->cfg_id1, cal0->body_size);
se_calc_sha256_oneshot(hash, (u8 *)&cal0->cfg_id1, cal0->body_size);
s_printf(txt_buf,
"#FF8000 CAL0 Version:# %d\n"
@@ -369,7 +370,7 @@ static lv_res_t _create_mbox_cal0(lv_obj_t *btn)
out:
free(txt_buf);
sd_unmount();
boot_storage_unmount();
lv_mbox_add_btns(mbox, mbox_btn_map, _cal0_dump_window_action);
@@ -1094,6 +1095,30 @@ static lv_res_t _create_window_hw_info_status(lv_obj_t *btn)
switch (display_id)
{
case PANEL_RR_SUPER5_OLED_V1:
strcat(txt_buf, "RR SUPER5 OLED");
switch (display_rev)
{
case 0x01:
strcat(txt_buf, "-V1");
break;
default:
strcat(txt_buf, " #FFDD00 Contact me!#");
break;
}
break;
case PANEL_RR_SUPER5_OLED_HD_V1:
strcat(txt_buf, "RR SUPER5 OLED HD");
switch (display_rev)
{
case 0x01:
strcat(txt_buf, "-V1");
break;
default:
strcat(txt_buf, " #FFDD00 Contact me!#");
break;
}
break;
case PANEL_JDI_LAM062M109A:
strcat(txt_buf, "JDI LAM062M109A");
break;
@@ -1811,7 +1836,7 @@ static lv_res_t _create_mbox_benchmark(bool sd_bench)
for (u32 i = 0; i < rnd_off_cnt; i += 4)
{
// Generate new random numbers.
while (!se_rng_pseudo(random_numbers, SE_RNG_BLOCK_SIZE))
while (!se_gen_prng128(random_numbers))
;
// Clamp offsets to 256MB range.
random_offsets[i + 0] = random_numbers[0] % sct_rem_4kb;
@@ -2881,7 +2906,7 @@ static bool _lockpick_exists_check()
bool found = false;
void *buf = malloc(0x200);
if (sd_mount())
if (boot_storage_mount())
{
FIL fp;
if (f_open(&fp, "bootloader/payloads/Lockpick_RCM.bin", FA_READ))
@@ -2906,7 +2931,7 @@ static bool _lockpick_exists_check()
out:
free(buf);
sd_unmount();
boot_storage_unmount();
return found;
}

View File

@@ -23,6 +23,7 @@
#include "../config.h"
#include <libs/lvgl/lv_themes/lv_theme_hekate.h>
#include <libs/lvgl/lvgl.h>
#include <storage/boot_storage.h>
#define CLOCK_MIN_YEAR 2025
#define CLOCK_MAX_YEAR (CLOCK_MIN_YEAR + 10)
@@ -224,7 +225,7 @@ static void _create_autoboot_window()
lv_obj_set_size(list_main, LV_HOR_RES * 4 / 10, LV_VER_RES * 4 / 7);
lv_list_set_single_mode(list_main, true);
sd_mount();
boot_storage_mount();
// Parse hekate main configuration.
LIST_INIT(ini_sections);
@@ -285,7 +286,7 @@ static void _create_autoboot_window()
ini_free(&ini_list_sections);
}
sd_unmount();
boot_storage_unmount();
}
static lv_res_t _autoboot_hide_delay_action(lv_obj_t *btn)
@@ -429,7 +430,7 @@ static lv_res_t _save_theme_color_action(lv_obj_t *btn)
// Save nyx config.
create_nyx_config_entry(true);
reload_nyx(NULL, false);
reload_nyx();
return LV_RES_OK;
}
@@ -944,7 +945,7 @@ static lv_res_t _joycon_info_dump_action(lv_obj_t * btn)
jc_pad->bt_conn_r.type = is_r_hos ? jc_pad->bt_conn_r.type : 0;
save_data:
error = !sd_mount() ? 5 : 0;
error = !boot_storage_mount() ? 5 : 0;
if (!error)
{
@@ -958,7 +959,8 @@ save_data:
memcpy(data, &jc_pad->bt_conn_l, sizeof(jc_bt_conn_t));
memcpy(data + sizeof(jc_bt_conn_t), &jc_pad->bt_conn_r, sizeof(jc_bt_conn_t));
error = sd_save_to_file((u8 *)data, sizeof(jc_bt_conn_t) * 2, "switchroot/joycon_mac.bin") ? 4 : 0;
// TODO: JC dump should probably go to sd?
error = boot_storage_save_to_file((u8 *)data, sizeof(jc_bt_conn_t) * 2, "switchroot/joycon_mac.bin") ? 4 : 0;
// Save readable dump.
data[0] = 0;
@@ -1080,7 +1082,7 @@ save_data:
}
}
sd_unmount();
boot_storage_unmount();
}
disabled_or_cal0_issue:;

File diff suppressed because it is too large Load Diff

View File

@@ -25,5 +25,6 @@ void create_tab_tools(lv_theme_t *th, lv_obj_t *parent);
void nyx_run_ums(void *param);
bool get_set_autorcm_status(bool change);
lv_res_t action_ums_sd(lv_obj_t *btn);
lv_res_t action_ums_emmc_gpp(lv_obj_t *btn);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2025 CTCaer
* Copyright (c) 2019-2020 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,
@@ -17,7 +17,6 @@
#ifndef _GUI_TOOLS_PART_MANAGER_H_
#define _GUI_TOOLS_PART_MANAGER_H_
lv_res_t create_window_sd_partition_manager(lv_obj_t *btn);
lv_res_t create_window_emmc_partition_manager(lv_obj_t *btn);
lv_res_t create_window_partition_manager(lv_obj_t *btn, u8 drive);
#endif

View File

@@ -23,6 +23,7 @@
#include <bdk.h>
#include "hos.h"
#include <storage/boot_storage.h>
#include "../config.h"
u8 *cal0_buf = NULL;
@@ -208,7 +209,7 @@ static void _hos_eks_get()
// Decrypt EKS blob.
hos_eks_mbr_t *eks = (hos_eks_mbr_t *)(mbr + 0x80);
se_aes_crypt_ecb(14, DECRYPT, eks, eks, sizeof(hos_eks_mbr_t));
se_aes_crypt_ecb(14, DECRYPT, eks, sizeof(hos_eks_mbr_t), eks, sizeof(hos_eks_mbr_t));
// Check if valid and for this unit.
if (eks->magic == HOS_EKS_MAGIC && eks->lot0 == FUSE(FUSE_OPT_LOT_CODE_0))
@@ -254,7 +255,7 @@ static void _hos_eks_save()
// Get keys.
u8 *keys = (u8 *)zalloc(SZ_8K);
se_aes_ctx_get_keys(keys + SZ_4K, keys, SE_KEY_128_SIZE);
se_get_aes_keys(keys + SZ_4K, keys, SE_KEY_128_SIZE);
// Set magic and personalized info.
h_cfg.eks->magic = HOS_EKS_MAGIC;
@@ -269,7 +270,7 @@ static void _hos_eks_save()
// Encrypt EKS blob.
u8 *eks = malloc(sizeof(hos_eks_mbr_t));
memcpy(eks, h_cfg.eks, sizeof(hos_eks_mbr_t));
se_aes_crypt_ecb(14, ENCRYPT, eks, eks, sizeof(hos_eks_mbr_t));
se_aes_crypt_ecb(14, ENCRYPT, eks, sizeof(hos_eks_mbr_t), eks, sizeof(hos_eks_mbr_t));
// Write EKS blob to SD.
memcpy(mbr + 0x80, eks, sizeof(hos_eks_mbr_t));
@@ -304,7 +305,7 @@ void hos_eks_clear(u32 mkey)
// Encrypt EKS blob.
u8 *eks = malloc(sizeof(hos_eks_mbr_t));
memcpy(eks, h_cfg.eks, sizeof(hos_eks_mbr_t));
se_aes_crypt_ecb(14, ENCRYPT, eks, eks, sizeof(hos_eks_mbr_t));
se_aes_crypt_ecb(14, ENCRYPT, eks, sizeof(hos_eks_mbr_t), eks, sizeof(hos_eks_mbr_t));
// Write EKS blob to SD.
memcpy(mbr + 0x80, eks, sizeof(hos_eks_mbr_t));
@@ -381,7 +382,7 @@ int hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt)
*/
// Use custom TSEC Hovi Keygen firmware.
tsec_ctxt->fw = sd_file_read("bootloader/sys/thk.bin", NULL);
tsec_ctxt->fw = boot_storage_file_read("bootloader/sys/thk.bin", NULL);
if (!tsec_ctxt->fw)
{
EPRINTF("\nFailed to load thk.bin");
@@ -423,7 +424,7 @@ int hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt)
}
// Decrypt eks and set keyslots.
se_aes_crypt_ecb(12, DECRYPT, tsec_keys.tmp, eks_keyseeds[0], SE_KEY_128_SIZE);
se_aes_crypt_block_ecb(12, DECRYPT, tsec_keys.tmp, eks_keyseeds[0]);
se_aes_unwrap_key(15, 14, tsec_keys.tmp);
// Derive device keys.
@@ -447,7 +448,7 @@ int hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt)
se_aes_key_set(13, tsec_keys.tsec_root, SE_KEY_128_SIZE);
// Decrypt eks and set keyslots.
se_aes_crypt_ecb(12, DECRYPT, tsec_keys.tmp, eks_keyseeds[0], SE_KEY_128_SIZE);
se_aes_crypt_block_ecb(12, DECRYPT, tsec_keys.tmp, eks_keyseeds[0]);
se_aes_unwrap_key(15, 14, tsec_keys.tmp);
// Derive device keys.
@@ -469,30 +470,30 @@ int hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt)
se_aes_key_set(13, tsec_keys.tsec, SE_KEY_128_SIZE);
// Derive eks keys from TSEC+SBK.
se_aes_crypt_ecb(13, DECRYPT, tsec_keys.tsec, eks_keyseeds[0], SE_KEY_128_SIZE);
se_aes_crypt_block_ecb(13, DECRYPT, tsec_keys.tsec, eks_keyseeds[0]);
se_aes_unwrap_key(15, 14, tsec_keys.tsec);
se_aes_crypt_ecb(13, DECRYPT, tsec_keys.tsec, eks_keyseeds[mkey], SE_KEY_128_SIZE);
se_aes_crypt_block_ecb(13, DECRYPT, tsec_keys.tsec, eks_keyseeds[mkey]);
se_aes_unwrap_key(13, 14, tsec_keys.tsec);
/*
// Verify eks CMAC.
u8 cmac[SE_KEY_128_SIZE];
se_aes_unwrap_key(11, 13, cmac_keyseed);
se_aes_hash_cmac(cmac, SE_KEY_128_SIZE, 11, (void *)eks->ctr, sizeof(eks->ctr) + sizeof(eks->keys));
se_aes_cmac(cmac, SE_KEY_128_SIZE, 11, (void *)eks->ctr, sizeof(eks->ctr) + sizeof(eks->keys));
if (!memcmp(eks->cmac, cmac, SE_KEY_128_SIZE))
return 0;
*/
se_aes_crypt_ecb(13, DECRYPT, tsec_keys.tsec, cmac_keyseed, SE_KEY_128_SIZE);
se_aes_crypt_block_ecb(13, DECRYPT, tsec_keys.tsec, cmac_keyseed);
se_aes_unwrap_key(11, 13, cmac_keyseed);
// Decrypt eks and set keyslots.
se_aes_crypt_ctr(13, &eks->keys, &eks->keys, sizeof(eks_keys_t), eks->ctr);
se_aes_crypt_ctr(13, &eks->keys, sizeof(eks_keys_t), &eks->keys, sizeof(eks_keys_t), eks->ctr);
se_aes_key_set(11, eks->keys.package1_key, SE_KEY_128_SIZE);
se_aes_key_set(12, eks->keys.master_kekseed, SE_KEY_128_SIZE);
se_aes_key_set(13, eks->keys.master_kekseed, SE_KEY_128_SIZE);
se_aes_crypt_ecb(12, DECRYPT, tsec_keys.tsec, master_keyseed_retail, SE_KEY_128_SIZE);
se_aes_crypt_block_ecb(12, DECRYPT, tsec_keys.tsec, master_keyseed_retail);
switch (mkey)
{
@@ -531,11 +532,12 @@ static void _hos_validate_mkey()
do
{
mkey_idx--;
se_aes_crypt_ecb(7, DECRYPT, tmp_mkey, mkey_vectors[mkey_idx], SE_KEY_128_SIZE);
se_aes_crypt_ecb(7, DECRYPT, tmp_mkey, SE_KEY_128_SIZE, mkey_vectors[mkey_idx], SE_KEY_128_SIZE);
for (u32 idx = 0; idx < mkey_idx; idx++)
{
se_aes_key_clear(2);
se_aes_key_set(2, tmp_mkey, SE_KEY_128_SIZE);
se_aes_crypt_ecb(2, DECRYPT, tmp_mkey, mkey_vectors[mkey_idx - 1 - idx], SE_KEY_128_SIZE);
se_aes_crypt_ecb(2, DECRYPT, tmp_mkey, SE_KEY_128_SIZE, mkey_vectors[mkey_idx - 1 - idx], SE_KEY_128_SIZE);
}
if (!memcmp(tmp_mkey, "\x00\x00\x00\x00\x00\x00\x00\x00", 8))
@@ -592,17 +594,19 @@ int hos_bis_keygen()
do
{
mkey_idx--;
se_aes_crypt_ecb(7, DECRYPT, tmp_mkey, mkey_vectors[mkey_idx], SE_KEY_128_SIZE);
se_aes_crypt_ecb(7, DECRYPT, tmp_mkey, SE_KEY_128_SIZE, mkey_vectors[mkey_idx], SE_KEY_128_SIZE);
for (u32 idx = 0; idx < mkey_idx; idx++)
{
se_aes_key_clear(2);
se_aes_key_set(2, tmp_mkey, SE_KEY_128_SIZE);
se_aes_crypt_ecb(2, DECRYPT, tmp_mkey, mkey_vectors[mkey_idx - 1 - idx], SE_KEY_128_SIZE);
se_aes_crypt_ecb(2, DECRYPT, tmp_mkey, SE_KEY_128_SIZE, mkey_vectors[mkey_idx - 1 - idx], SE_KEY_128_SIZE);
}
} while (memcmp(tmp_mkey, "\x00\x00\x00\x00\x00\x00\x00\x00", 8) != 0 && (mkey_idx - 1));
// Derive new device key.
se_aes_key_clear(1);
se_aes_unwrap_key(1, 10, new_console_keyseed[keygen_rev]); // Uses Device key 4x.
se_aes_crypt_ecb(10, DECRYPT, tmp_mkey, new_console_keyseed[keygen_rev], SE_KEY_128_SIZE); // Uses Device key 4x.
se_aes_crypt_ecb(10, DECRYPT, tmp_mkey, SE_KEY_128_SIZE, new_console_keyseed[keygen_rev], SE_KEY_128_SIZE); // Uses Device key 4x.
se_aes_unwrap_key(1, 2, new_console_kekseed[keygen_rev]); // Uses Master Key 0.
se_aes_unwrap_key(1, 1, tmp_mkey);
@@ -610,27 +614,29 @@ int hos_bis_keygen()
}
// Generate generic key.
se_aes_key_clear(2);
se_aes_unwrap_key(2, console_key_slot, gen_keyseed_retail);
// Clear bis keys storage.
memset(bis_keys, 0, SE_KEY_128_SIZE * 6);
// Generate BIS 0 Keys.
se_aes_crypt_ecb(2, DECRYPT, bis_keys + (0 * SE_KEY_128_SIZE), bis_keyseed[0], SE_KEY_128_SIZE);
se_aes_crypt_ecb(2, DECRYPT, bis_keys + (1 * SE_KEY_128_SIZE), bis_keyseed[1], SE_KEY_128_SIZE);
se_aes_crypt_block_ecb(2, DECRYPT, bis_keys + (0 * SE_KEY_128_SIZE), bis_keyseed[0]);
se_aes_crypt_block_ecb(2, DECRYPT, bis_keys + (1 * SE_KEY_128_SIZE), bis_keyseed[1]);
// Generate generic kek.
se_aes_key_clear(2);
se_aes_unwrap_key(2, console_key_slot, gen_kekseed);
se_aes_unwrap_key(2, 2, bis_kekseed);
se_aes_unwrap_key(2, 2, gen_keyseed);
// Generate BIS 1 Keys.
se_aes_crypt_ecb(2, DECRYPT, bis_keys + (2 * SE_KEY_128_SIZE), bis_keyseed[2], SE_KEY_128_SIZE);
se_aes_crypt_ecb(2, DECRYPT, bis_keys + (3 * SE_KEY_128_SIZE), bis_keyseed[3], SE_KEY_128_SIZE);
se_aes_crypt_block_ecb(2, DECRYPT, bis_keys + (2 * SE_KEY_128_SIZE), bis_keyseed[2]);
se_aes_crypt_block_ecb(2, DECRYPT, bis_keys + (3 * SE_KEY_128_SIZE), bis_keyseed[3]);
// Generate BIS 2/3 Keys.
se_aes_crypt_ecb(2, DECRYPT, bis_keys + (4 * SE_KEY_128_SIZE), bis_keyseed[4], SE_KEY_128_SIZE);
se_aes_crypt_ecb(2, DECRYPT, bis_keys + (5 * SE_KEY_128_SIZE), bis_keyseed[5], SE_KEY_128_SIZE);
se_aes_crypt_block_ecb(2, DECRYPT, bis_keys + (4 * SE_KEY_128_SIZE), bis_keyseed[4]);
se_aes_crypt_block_ecb(2, DECRYPT, bis_keys + (5 * SE_KEY_128_SIZE), bis_keyseed[5]);
// Validate key because HOS_MKEY_VER_MAX.
if (!h_cfg.t210b01)
@@ -682,7 +688,7 @@ int hos_dump_cal0()
LIST_INIT(gpt);
emmc_gpt_parse(&gpt);
emmc_part_t *cal0_part = emmc_part_find(&gpt, "PRODINFO"); // check if null
nx_emmc_bis_init(cal0_part, false, 0);
nx_emmc_bis_init(cal0_part, false, NULL, 0);
nx_emmc_bis_read(0, 0x40, cal0_buf);
nx_emmc_bis_end();
emmc_gpt_free(&gpt);
@@ -707,7 +713,7 @@ int hos_dump_cal0()
}
u32 hash[8];
se_sha_hash_256_oneshot(hash, (u8 *)&cal0->cfg_id1, cal0->body_size);
se_calc_sha256_oneshot(hash, (u8 *)&cal0->cfg_id1, cal0->body_size);
if (memcmp(hash, cal0->body_sha256, 0x20))
return 3;

View File

@@ -96,7 +96,7 @@ int pkg1_decrypt(const pkg1_id_t *id, u8 *pkg1)
u8 *pkg11 = pkg1 + id->pkg11_off;
u32 pkg11_size = *(u32 *)pkg11;
hdr = (pk11_hdr_t *)(pkg11 + 0x20);
se_aes_crypt_ctr(11, hdr, hdr, pkg11_size, pkg11 + 0x10);
se_aes_crypt_ctr(11, hdr, pkg11_size, hdr, pkg11_size, pkg11 + 0x10);
}
else
{
@@ -107,7 +107,7 @@ int pkg1_decrypt(const pkg1_id_t *id, u8 *pkg1)
// Use BEK for T210B01.
// Additionally, skip 0x20 bytes from decryption to maintain the header.
se_aes_iv_clear(13);
se_aes_crypt_cbc(13, DECRYPT, pkg1 + 0x20, pkg1 + 0x20, oem_hdr->size - 0x20);
se_aes_crypt_cbc(13, DECRYPT, pkg1 + 0x20, oem_hdr->size - 0x20, pkg1 + 0x20, oem_hdr->size - 0x20);
}
// Return if header is valid.

View File

@@ -26,12 +26,6 @@
#define PK11_SECTION_LD 1
#define PK11_SECTION_SM 2
#define PKG1_BOOTLOADER_SIZE SZ_256K
#define PKG1_BOOTLOADER_MAIN_OFFSET (0x100000 / EMMC_BLOCKSIZE)
#define PKG1_BOOTLOADER_BACKUP_OFFSET (0x140000 / EMMC_BLOCKSIZE)
#define PKG1_BOOTLOADER_SAFE_OFFSET (0x000000 / EMMC_BLOCKSIZE)
#define PKG1_HOS_EKS_OFFSET (0x180000 / EMMC_BLOCKSIZE)
typedef struct _bl_hdr_t210b01_t
{
/* 0x000 */ u8 aes_mac[0x10];

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2018 naehrwert
* Copyright (c) 2018-2026 CTCaer
* Copyright (c) 2018-2025 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,
@@ -123,13 +123,13 @@ static const u8 mkey_vector_7xx[HOS_MKEY_VER_MAX - HOS_MKEY_VER_810 + 1][SE_KEY_
static bool _pkg2_key_unwrap_validate(pkg2_hdr_t *tmp_test, pkg2_hdr_t *hdr, u8 src_slot, u8 *mkey, const u8 *key_seed)
{
// Decrypt older encrypted mkey.
se_aes_crypt_ecb(src_slot, DECRYPT, mkey, key_seed, SE_KEY_128_SIZE);
se_aes_crypt_ecb(src_slot, DECRYPT, mkey, SE_KEY_128_SIZE, key_seed, SE_KEY_128_SIZE);
// Set and unwrap pkg2 key.
se_aes_key_set(9, mkey, SE_KEY_128_SIZE);
se_aes_unwrap_key(9, 9, package2_keyseed);
// Decrypt header.
se_aes_crypt_ctr(9, tmp_test, hdr, sizeof(pkg2_hdr_t), hdr);
se_aes_crypt_ctr(9, tmp_test, sizeof(pkg2_hdr_t), hdr, sizeof(pkg2_hdr_t), hdr);
// Return if header is valid.
return (tmp_test->magic == PKG2_MAGIC);
@@ -150,7 +150,7 @@ pkg2_hdr_t *pkg2_decrypt(void *data, u8 mkey)
pdata += sizeof(pkg2_hdr_t);
// Check if we need to decrypt with newer mkeys. Valid for THK for 7.0.0 and up.
se_aes_crypt_ctr(8, &mkey_test, hdr, sizeof(pkg2_hdr_t), hdr);
se_aes_crypt_ctr(8, &mkey_test, sizeof(pkg2_hdr_t), hdr, sizeof(pkg2_hdr_t), hdr);
if (mkey_test.magic == PKG2_MAGIC)
goto key_found;
@@ -197,7 +197,7 @@ pkg2_hdr_t *pkg2_decrypt(void *data, u8 mkey)
key_found:
// Decrypt header.
se_aes_crypt_ctr(pkg2_keyslot, hdr, hdr, sizeof(pkg2_hdr_t), hdr);
se_aes_crypt_ctr(pkg2_keyslot, hdr, sizeof(pkg2_hdr_t), hdr, sizeof(pkg2_hdr_t), hdr);
if (hdr->magic != PKG2_MAGIC)
return NULL;
@@ -209,7 +209,7 @@ DPRINTF("sec %d has size %08X\n", i, hdr->sec_size[i]);
if (!hdr->sec_size[i])
continue;
se_aes_crypt_ctr(pkg2_keyslot, pdata, pdata, hdr->sec_size[i], hdr->sec_ctr[i]);
se_aes_crypt_ctr(pkg2_keyslot, pdata, hdr->sec_size[i], pdata, hdr->sec_size[i], &hdr->sec_ctr[i * SE_AES_IV_SIZE]);
pdata += hdr->sec_size[i];
}

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2018 naehrwert
* Copyright (c) 2018-2026 CTCaer
* Copyright (c) 2018-2025 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,
@@ -39,7 +39,7 @@ extern u32 pkg2_newkern_ini1_end;
typedef struct _pkg2_hdr_t
{
/* 0x000 */ u8 ctr[0x10];
/* 0x010 */ u8 sec_ctr[4][SE_AES_IV_SIZE];
/* 0x010 */ u8 sec_ctr[0x40];
/* 0x050 */ u32 magic;
/* 0x054 */ u32 base;
/* 0x058 */ u32 pad0;
@@ -48,7 +48,7 @@ typedef struct _pkg2_hdr_t
/* 0x05E */ u16 pad1;
/* 0x060 */ u32 sec_size[4];
/* 0x070 */ u32 sec_off[4];
/* 0x080 */ u8 sec_sha256[4][SE_SHA_256_SIZE];
/* 0x080 */ u8 sec_sha256[0x80];
/* 0x100 */ u8 data[];
} pkg2_hdr_t;

View File

@@ -1,7 +1,7 @@
/*-----------------------------------------------------------------------*/
/* Low level disk I/O module skeleton for FatFs */
/* (C) ChaN, 2016 */
/* (C) CTCaer, 2018-2025 */
/* (C) CTCaer, 2018-2020 */
/*-----------------------------------------------------------------------*/
/* If a working storage control module is available, it should be */
/* attached to the FatFs via a glue function rather than modifying it. */
@@ -9,18 +9,113 @@
/* storage control modules to the FatFs module with a defined API. */
/*-----------------------------------------------------------------------*/
#include <storage/emmc.h>
#include <string.h>
#include <bdk.h>
#include <libs/fatfs/diskio.h> /* FatFs lower layer API */
#include <fatfs_cfg.h>
#include "../../storage/sfd.h"
static u32 sd_rsvd_sectors = 0;
static u32 ramdisk_sectors = 0;
static u32 bis_sectors = 0;
static u32 emummc_sectors = 0;
static u32 emummc_sectors = 0;
static u32 sfd_sectors = 0;
static bool bis_write_allowed = false;
static u32 cur_partition;
static void save_cur_partition(BYTE pdrv){
bool save = false;
switch(pdrv){
case DRIVE_BOOT1:
case DRIVE_BOOT1_1MB:
case DRIVE_EMMC:
save = true;
break;
case DRIVE_SD:
case DRIVE_RAM:
break;
case DRIVE_BIS:
case DRIVE_EMU:
if(nx_emmc_bis_get_storage() == &emmc_storage){
save = true;
}
break;
case DRIVE_SFD:
if(sfd_get_storage() == &emmc_storage){
save = true;
}
break;
default:
break;
}
if(save){
cur_partition = emmc_storage.partition;
}
}
static void restore_cur_partition(BYTE pdrv){
bool restore = false;
switch(pdrv){
case DRIVE_BOOT1:
case DRIVE_BOOT1_1MB:
case DRIVE_EMMC:
restore = true;
break;
case DRIVE_SD:
case DRIVE_RAM:
break;
case DRIVE_BIS:
case DRIVE_EMU:
if(nx_emmc_bis_get_storage() == &emmc_storage){
restore = true;
}
break;
case DRIVE_SFD:
if(sfd_get_storage() == &emmc_storage){
restore = true;
}
break;
default:
break;
}
if(restore){
if(emmc_storage.partition != cur_partition){
emmc_set_partition(cur_partition);
}
}
}
static bool ensure_partition(BYTE pdrv){
u8 part;
switch(pdrv){
case DRIVE_BOOT1:
case DRIVE_BOOT1_1MB:
part = EMMC_BOOT1;
break;
case DRIVE_EMMC:
part = EMMC_GPP;
break;
case DRIVE_SD:
case DRIVE_RAM:
return true;
case DRIVE_BIS:
case DRIVE_EMU:
case DRIVE_SFD:
return true;
default:
return false;
}
if(emmc_storage.partition != part){
return emmc_set_partition(part);
}
return true;
}
/*-----------------------------------------------------------------------*/
/* Get Drive Status */
@@ -52,20 +147,45 @@ DRESULT disk_read (
UINT count /* Number of sectors to read */
)
{
switch (pdrv)
{
case DRIVE_SD:
return sdmmc_storage_read(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR;
case DRIVE_RAM:
return ram_disk_read(sector, count, (void *)buff);
case DRIVE_EMMC:
return sdmmc_storage_read(&emmc_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR;
case DRIVE_BIS:
case DRIVE_EMU:
return nx_emmc_bis_read(sector, count, (void *)buff) ? RES_OK : RES_ERROR;
DRESULT res = RES_OK;
save_cur_partition(pdrv);
if(!ensure_partition(pdrv)){
res = RES_ERROR;
}
return RES_ERROR;
if(res == RES_OK){
switch (pdrv)
{
case DRIVE_SD:
res = sdmmc_storage_read(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR;
break;
case DRIVE_RAM:
res = ram_disk_read(sector, count, (void *)buff);
break;
case DRIVE_EMMC:
res = sdmmc_storage_read(&emmc_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR;
break;
case DRIVE_BIS:
case DRIVE_EMU:
res = nx_emmc_bis_read(sector, count, (void *)buff) ? RES_OK : RES_ERROR;
break;
case DRIVE_BOOT1_1MB:
res = sdmmc_storage_read(&emmc_storage, sector + (0x100000 / 512), count, buff) ? RES_OK : RES_ERROR;
break;
case DRIVE_BOOT1:
res = sdmmc_storage_read(&emmc_storage, sector, count, buff) ? RES_OK : RES_ERROR;
break;
case DRIVE_SFD:
res = sfd_read(sector, count, buff) ? RES_OK : RES_ERROR;
break;
}
}
restore_cur_partition(pdrv);
return res;
}
/*-----------------------------------------------------------------------*/
@@ -78,22 +198,47 @@ DRESULT disk_write (
UINT count /* Number of sectors to write */
)
{
switch (pdrv)
{
case DRIVE_SD:
return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR;
case DRIVE_RAM:
return ram_disk_write(sector, count, (void *)buff);
case DRIVE_EMMC:
return RES_WRPRT;
case DRIVE_BIS:
case DRIVE_EMU:
if (pdrv == DRIVE_BIS && !bis_write_allowed)
return RES_WRPRT;
return nx_emmc_bis_write(sector, count, (void *)buff) ? RES_OK : RES_ERROR;
DRESULT res = RES_OK;
save_cur_partition(pdrv);
if(!ensure_partition(pdrv)){
res = RES_ERROR;
}
return RES_ERROR;
if(res == RES_OK){
switch (pdrv)
{
case DRIVE_SD:
res = sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR;
break;
case DRIVE_RAM:
res = ram_disk_write(sector, count, (void *)buff);
break;
case DRIVE_EMMC:
res = sdmmc_storage_write(&emmc_storage, sector, count, (void*)buff) ? RES_OK : RES_ERROR;
break;
case DRIVE_BIS:
res = RES_WRPRT;
break;
case DRIVE_EMU:
res = nx_emmc_bis_write(sector, count, (void *)buff) ? RES_OK : RES_ERROR;
break;
case DRIVE_BOOT1_1MB:
res = sdmmc_storage_write(&emmc_storage, sector + (0x100000 / 512), count, (void*)buff) ? RES_OK : RES_ERROR;
break;
case DRIVE_BOOT1:
res = sdmmc_storage_write(&emmc_storage, sector, count, (void*)buff) ? RES_OK : RES_ERROR;
break;
case DRIVE_SFD:
res = sfd_write(sector, count, (void*)buff) ? RES_OK : RES_ERROR;
break;
}
}
restore_cur_partition(pdrv);
return res;
}
/*-----------------------------------------------------------------------*/
@@ -107,9 +252,8 @@ DRESULT disk_ioctl (
{
DWORD *buf = (DWORD *)buff;
switch (pdrv)
if (pdrv == DRIVE_SD)
{
case DRIVE_SD:
switch (cmd)
{
case GET_SECTOR_COUNT:
@@ -119,9 +263,9 @@ DRESULT disk_ioctl (
*buf = 32768; // Align to 16MB.
break;
}
break;
case DRIVE_RAM:
}
else if (pdrv == DRIVE_RAM)
{
switch (cmd)
{
case GET_SECTOR_COUNT:
@@ -131,33 +275,29 @@ DRESULT disk_ioctl (
*buf = 2048; // Align to 1MB.
break;
}
break;
case DRIVE_BIS:
switch (cmd)
{
case GET_SECTOR_COUNT:
*buf = bis_sectors;
break;
case GET_BLOCK_SIZE:
*buf = 32768; // Align to 16MB.
break;
}
break;
case DRIVE_EMU:
}
else if (pdrv == DRIVE_EMU)
{
switch (cmd)
{
case GET_SECTOR_COUNT:
*buf = emummc_sectors;
break;
case GET_BLOCK_SIZE:
*buf = 16384; // Align to 8MB (With BOOT0/1 data will be at 16MB BU).
*buf = 32768; // Align to 16MB.
break;
}
break;
default: // Catch all for unknown devices.
}else if(pdrv == DRIVE_SFD){
switch(cmd){
case GET_SECTOR_COUNT:
*buf = sfd_sectors;
break;
case GET_BLOCK_SIZE:
*buf = 32768;
break;
}
}else // Catch all for unknown devices.
{
switch (cmd)
{
case CTRL_SYNC:
@@ -167,7 +307,6 @@ DRESULT disk_ioctl (
*buf = 0; // Zero value to force default or abort.
break;
}
break;
}
return RES_OK;
@@ -188,22 +327,17 @@ DRESULT disk_set_info (
case DRIVE_SD:
sd_rsvd_sectors = *buf;
break;
case DRIVE_RAM:
ramdisk_sectors = *buf;
break;
case DRIVE_BIS:
bis_sectors = *buf;
break;
case DRIVE_EMU:
emummc_sectors = *buf;
break;
case DRIVE_SFD:
sfd_sectors = *buf;
break;
}
}
else if (cmd == SET_WRITE_PROTECT && pdrv == DRIVE_BIS)
bis_write_allowed = *(bool *)buff;
return RES_OK;
}

View File

@@ -168,7 +168,7 @@
*/
#define FF_FS_RPATH 1
#define FF_FS_RPATH 2
/* This option configures support for relative path.
/
/ 0: Disable relative path and remove related functions.
@@ -181,12 +181,12 @@
/ Drive/Volume Configurations
/---------------------------------------------------------------------------*/
#define FF_VOLUMES 5
#define FF_VOLUMES 8
/* Number of volumes (logical drives) to be used. (1-10) */
#define FF_STR_VOLUME_ID 1
#define FF_VOLUME_STRS "sd","ram","emmc","bis","emu"
#define FF_VOLUME_STRS "sd","ram","emmc","bis","emu", "boot1", "boot1_1mb", "sfd"
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
/ number in the path name. FF_VOLUME_STRS defines the volume ID strings for each
@@ -302,6 +302,15 @@
/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be
/ included somewhere in the scope of ff.h. */
typedef enum {
DRIVE_SD = 0,
DRIVE_RAM = 1,
DRIVE_EMMC = 2,
DRIVE_BIS = 3,
DRIVE_EMU = 4,
DRIVE_BOOT1 = 5,
DRIVE_BOOT1_1MB = 6,
DRIVE_SFD = 7,
} DDRIVE;
/*--- End of configuration options ---*/

View File

@@ -26,6 +26,7 @@
#include <ianos/ianos.h>
#include <libs/compr/blz.h>
#include <libs/fatfs/ff.h>
#include <storage/boot_storage.h>
#include "frontend/fe_emmc_tools.h"
#include "frontend/gui.h"
@@ -34,7 +35,7 @@ nyx_config n_cfg;
hekate_config h_cfg;
const volatile ipl_ver_meta_t __attribute__((section ("._ipl_version"))) ipl_ver = {
.magic = NYX_MAGIC,
.magic = NYX_MAGIC,
.version = (NYX_VER_MJ + '0') | ((NYX_VER_MN + '0') << 8) | ((NYX_VER_HF + '0') << 16) | ((NYX_VER_RL) << 24),
};
@@ -121,7 +122,7 @@ lv_res_t launch_payload(lv_obj_t *list)
strcpy(path,"bootloader/payloads/");
strcat(path, filename);
if (!sd_mount())
if (!boot_storage_mount())
goto out;
// Read payload.
@@ -142,7 +143,7 @@ lv_res_t launch_payload(lv_obj_t *list)
goto out;
}
sd_end();
boot_storage_end();
// Copy the payload to our chosen address.
memcpy((void *)RCM_PAYLOAD_ADDR, buf, size);
@@ -329,8 +330,8 @@ static void _show_errors(int sd_error)
if (*excp_enabled == EXCP_MAGIC || sd_error)
{
gfx_clear_grey(0);
gfx_con_setpos(0, 0, 0);
// gfx_clear_grey(0);
// gfx_con_setpos(0, 0, 0);
display_backlight_brightness(150, 1000);
display_init_window_d_console();
display_window_d_console_enable();
@@ -380,7 +381,7 @@ error_occured:
msleep(1000);
btn_wait();
reload_nyx(NULL, true);
reload_nyx();
}
}
@@ -427,13 +428,13 @@ void nyx_init_load_res()
_show_errors(SD_NO_ERROR);
// Try 2 times to mount SD card.
if (!sd_mount())
if (!boot_storage_mount())
{
// Restore speed to SDR104.
sd_end();
boot_storage_end();
// Retry.
if (!sd_mount())
if (!boot_storage_mount())
_show_errors(SD_MOUNT_ERROR); // Fatal.
}
@@ -490,7 +491,7 @@ void nyx_init_load_res()
nyx_load_bg_icons();
// Unmount FAT partition.
sd_unmount();
boot_storage_unmount();
}
void ipl_main()

86
nyx/nyx_gui/storage/sfd.c Normal file
View File

@@ -0,0 +1,86 @@
#include "sfd.h"
#include <storage/emmc.h>
#include <storage/sdmmc.h>
#include <storage/file_based_storage.h>
#include <libs/fatfs/diskio.h>
#include <string.h>
static bool file_based;
static sdmmc_storage_t *_storage;
static u32 _offset;
static u32 _size;
static void ensure_partition(){
if(_storage == &emmc_storage){
emmc_set_partition(EMMC_GPP);
}
}
sdmmc_storage_t *sfd_get_storage(){
if(file_based){
return NULL;
}else{
return _storage;
}
}
int sfd_read(u32 sector, u32 count, void *buff){
int res;
if(sector + count > _size){
return 0;
}
if(file_based){
res = file_based_storage_read(sector, count, buff);
}else{
ensure_partition();
res = sdmmc_storage_read(_storage, sector + _offset, count, buff);
}
return res;
}
int sfd_write(u32 sector, u32 count, void *buff){
int res;
if(sector + count > _size){
return 0;
}
if(file_based){
res = file_based_storage_write(sector, count, buff);
}else{
ensure_partition();
res = sdmmc_storage_write(_storage, sector + _offset, count, buff);
}
return res;
}
bool sfd_init(sdmmc_storage_t *storage, u32 offset, u32 size){
_storage = storage;
_offset = offset;
_size = size;
disk_set_info(DRIVE_SFD, SET_SECTOR_COUNT, &size);
return true;
}
bool sfd_file_based_init(const char *base_path) {
file_based = true;
if(!file_based_storage_init(base_path)){
gfx_printf("file based init fail\n");
return 0;
}
_size = file_based_storage_get_total_size();
disk_set_info(DRIVE_SFD, SET_SECTOR_COUNT, &_size);
return 1;
}
void sfd_end(){
_storage = NULL;
_offset = 0;
_size = 0;
u32 size = 0;
file_based = false;
disk_set_info(DRIVE_SFD, SET_SECTOR_COUNT, &size);
}

16
nyx/nyx_gui/storage/sfd.h Normal file
View File

@@ -0,0 +1,16 @@
#ifndef _SFD_H
#define _SFD_H
#include <storage/sdmmc.h>
#include <utils/types.h>
int sfd_read(u32 sector, u32 count, void *buff);
int sfd_write(u32 sector, u32 count, void *buff);
bool sfd_file_based_init(const char *base_path);
bool sfd_init(sdmmc_storage_t *storage, u32 offset, u32 size);
void sfd_end();
sdmmc_storage_t *sfd_get_storage();
#endif