Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add system.xml dumper #24

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions ios_mcp/source/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
static void option_SetColdbootTitle(void);
static void option_DumpSyslogs(void);
static void option_DumpOtpAndSeeprom(void);
static void option_DumpSystemXml(void);
static void option_StartWupserver(void);
static void option_LoadNetConf(void);
static void option_pairDRC(void);
Expand Down Expand Up @@ -62,6 +63,7 @@ static const Menu mainMenuOptions[] = {
{"Set Coldboot Title", {.callback = option_SetColdbootTitle}},
{"Dump Syslogs", {.callback = option_DumpSyslogs}},
{"Dump OTP + SEEPROM", {.callback = option_DumpOtpAndSeeprom}},
{"Dump system.xml", {.callback = option_DumpSystemXml}},
{"Start wupserver", {.callback = option_StartWupserver}},
{"Load Network Configuration", {.callback = option_LoadNetConf}},
{"Pair Gamepad", {.callback = option_pairDRC}},
Expand Down Expand Up @@ -456,6 +458,30 @@ static void option_DumpOtpAndSeeprom(void)
IOS_HeapFree(CROSS_PROCESS_HEAP_ID, dataBuffer);
}

static void option_DumpSystemXml(void)
{
gfx_clear(COLOR_BACKGROUND);

drawTopBar("Dumping system.xml...");
setNotificationLED(NOTIF_LED_RED_BLINKING, 0);

uint32_t index = 16 + 8 + 2 + 8;
int res = copy_file(fsaHandle, "/vol/system/sys/config/system.xml", "/vol/storage_recovsd/system.xml");
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, GfxPrintFlag_ClearBG, "Failed to copy system.xml: %x", res);
setNotificationLED(NOTIF_LED_PURPLE, 0);
waitButtonInput();

return;
}

gfx_set_font_color(COLOR_SUCCESS);
gfx_print(16, index, 0, "Done!");
setNotificationLED(NOTIF_LED_PURPLE, 0);
waitButtonInput();
}

static void option_StartWupserver(void)
{
gfx_clear(COLOR_BACKGROUND);
Expand Down Expand Up @@ -1445,7 +1471,7 @@ int menuThread(void* arg)
printf("menuThread running\n");

// set LED to purple-orange blinking
setNotificationLED(NOTIF_LED_RED | NOTIF_LED_RED_BLINKING | NOTIF_LED_BLUE | NOTIF_LED_BLUE_BLINKING | NOTIF_LED_ORANGE);
setNotificationLED(NOTIF_LED_RED | NOTIF_LED_RED_BLINKING | NOTIF_LED_BLUE | NOTIF_LED_BLUE_BLINKING | NOTIF_LED_ORANGE, 0);

// stop ppcHeartbeatThread and reset PPC
IOS_CancelThread(ppcHeartBeatThreadId, 0);
Expand Down Expand Up @@ -1490,7 +1516,7 @@ int menuThread(void* arg)
}

// set LED to purple
setNotificationLED(NOTIF_LED_RED | NOTIF_LED_BLUE);
setNotificationLED(NOTIF_LED_PURPLE, 0);

int selected = 0;
while (1) {
Expand Down
44 changes: 42 additions & 2 deletions ios_mcp/source/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
#include "imports.h"
#include "fsa.h"

#include <stdbool.h>
#include <unistd.h>

#define COPY_BUFFER_SIZE 1024

#define HW_RSTB 0x0d800194

static NOTIF_LED oldLedState = NOTIF_LED_PURPLE;
static int ledTid = -1;
static volatile bool ledCanceled;
static uint8_t ledThreadStack[0x400] __attribute__((aligned(0x20)));

uint32_t kernRead32(uint32_t address)
{
return IOS_Syscall0x81(0, address, 0);
Expand Down Expand Up @@ -96,9 +104,41 @@ int readDCConfig(DisplayController_Config* config)
return bspRead("DISPLAY", 0, "DC_CONFIG", 0x14, config);
}

int setNotificationLED(uint8_t mask)
static int ledThread(void *arg)
{
for(uint32_t i = 0; i < (uint32_t)arg; ++i)
{
usleep(1);
if(ledCanceled)
return 0;
}

bspWrite("SMC", 0, "NotificationLED", 1, &oldLedState);
return 0;
}

void setNotificationLED(NOTIF_LED state, uint32_t duration)
{
return bspWrite("SMC", 0, "NotificationLED", 1, &mask);
if(state == oldLedState)
return;

if(ledTid != -1)
{
ledCanceled = true;
IOS_JoinThread(ledTid, NULL);
ledTid = -1;
}

bspWrite("SMC", 0, "NotificationLED", 1, &state);

if(duration != 0)
{
ledCanceled = false;
ledTid = IOS_CreateThread(ledThread, (void *)duration, ledThreadStack + sizeof(ledThreadStack), sizeof(ledThreadStack), IOS_GetThreadPriority(0), 0);
IOS_StartThread(ledTid);
}
else
oldLedState = state;
}

int setDrivePower(int power)
Expand Down
8 changes: 5 additions & 3 deletions ios_mcp/source/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ typedef struct DisplayController_Config {
void* framebuffer;
} DisplayController_Config;

enum {
typedef enum {
NOTIF_LED_OFF = 0,
NOTIF_LED_ORANGE_BLINKING = 1 << 0,
NOTIF_LED_ORANGE = 1 << 1,
NOTIF_LED_RED_BLINKING = 1 << 2,
NOTIF_LED_RED = 1 << 3,
NOTIF_LED_BLUE_BLINKING = 1 << 4,
NOTIF_LED_BLUE = 1 << 5,
};
NOTIF_LED_PURPLE = NOTIF_LED_RED | NOTIF_LED_BLUE,
NOTIF_LED_PURPLE_BLINKING = NOTIF_LED_RED_BLINKING | NOTIF_LED_BLUE_BLINKING,
} NOTIF_LED;

uint32_t kernRead32(uint32_t address);

Expand All @@ -65,6 +67,6 @@ int initDisplay(uint32_t configuration);

int readDCConfig(DisplayController_Config* config);

int setNotificationLED(uint8_t mask);
void setNotificationLED(NOTIF_LED state, uint32_t duration);

int setDrivePower(int power);