Skip to content

Commit 85d1003

Browse files
Version 104: Quit update mode function
1 parent d61eb7b commit 85d1003

11 files changed

Lines changed: 293 additions & 85 deletions

.DS_Store

6 KB
Binary file not shown.

LeafSDTools/ExitUpdateMode.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include "stdafx.h"
2+
#include "ExitUpdateMode.h"
3+
#include "Display.h"
4+
#include "Touch.h"
5+
6+
typedef int (WINAPI *LPCAPISetBootMode)(int param_1);
7+
8+
void RunExitUpdate() {
9+
LogError(L"Start ExitUpdate", 0);
10+
ResetTextRenderer();
11+
DrawBackground(0x0010);
12+
WaitForScreenUntouch();
13+
Sleep(50);
14+
WaitForScreenUntouch();
15+
Sleep(50);
16+
17+
PrintToScreen(2, "E X I T U P D A T E M O D E");
18+
PrintToScreen(1, "\n\nYou can exit update mode if stock updater is unavailable.\n\nTouch the screen to continue\nor wait 10 sec to return\n");
19+
20+
LCDTouchEvent* evt = WaitForTouch(10000);
21+
if (evt != NULL) {
22+
WaitForScreenUntouch();
23+
Sleep(50);
24+
WaitForScreenUntouch();
25+
Sleep(50);
26+
27+
HINSTANCE hDll = NULL;
28+
LPCAPISetBootMode pSetBootMode = NULL;
29+
30+
// Load the DLL
31+
hDll = LoadLibrary(TEXT("COMMONDLL.DLL"));
32+
if (hDll == NULL)
33+
{
34+
PrintToScreen(1, "Failed to load COMMONDLL.DLL. Error: %d\n", GetLastError());
35+
Sleep(5000);
36+
return;
37+
}
38+
39+
// Get the function address
40+
pSetBootMode = (LPCAPISetBootMode)GetProcAddress(hDll, TEXT("CApi_SetBootMode"));
41+
if (pSetBootMode == NULL)
42+
{
43+
PrintToScreen(1, "Failed to get address of CApi_SetBootMode. Error: %d\n", GetLastError());
44+
FreeLibrary(hDll);
45+
Sleep(5000);
46+
return;
47+
}
48+
49+
pSetBootMode(0);
50+
51+
FreeLibrary(hDll);
52+
53+
CleanupLog();
54+
55+
Sleep(100);
56+
57+
DrawBackground(0x2de0);
58+
AdjustTextPosition(0, 0);
59+
Sleep(100);
60+
PrintToScreen(4, "U P D A T E Q U I T !\n\n\n");
61+
PrintToScreen(1, "Please turn off power and re-insert your stock SD card!");
62+
Sleep(100);
63+
64+
// Infinite loop
65+
while (TRUE) {
66+
Sleep(500);
67+
}
68+
}
69+
WaitForScreenUntouch();
70+
}

LeafSDTools/ExitUpdateMode.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef EXITUPDATEMODE_H
2+
#define EXITUPDATEMODE_H
3+
4+
void RunExitUpdate();
5+
6+
#endif

LeafSDTools/Flash.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ int ReadSingleFlashBlock(int block, DWORD size, BYTE* output) {
173173
CloseHandle(hFMD1);
174174
return 0;
175175
}
176+
CloseHandle(hFMD1);
176177
return 3;
177178
}
179+
CloseHandle(hFMD1);
178180
return 2;
179181
}
180182
return 1;

LeafSDTools/LeafSDTools.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#include "WriteNAND.h"
77
#include "UserSRAM.h"
88
#include "SDPinControl.h"
9+
#include "ExitUpdateMode.h"
910

10-
const char* labels[] = {"Read NAND", "Write NAND", "SRAM", "SD lock", "SD unlock"};
11+
const char* labels[] = {"Read NAND", "Write NAND", "SRAM", "SD lock", "SD unlock", "EXIT UPDATE"};
1112

1213
char* wchar_to_ascii(const wchar_t* wchar_str) {
1314
if (!wchar_str) return NULL;
@@ -30,7 +31,7 @@ void RenderMenuOptions() {
3031

3132
int y = 20;
3233

33-
for (int i = 0; i < 5; i++) {
34+
for (int i = 0; i < 6; i++) {
3435
if (RenderButton(780, y, 180, 65, labels[i]) != 0) {
3536
break;
3637
}
@@ -118,15 +119,14 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLin
118119
LCDTouchEvent* touchEvt = WaitForTouch(INFINITE);
119120
if (touchEvt != NULL) {
120121
if (btn == -1) {
121-
btn = GetPressedButton(touchEvt->xCoord, touchEvt->yCoord, 780, 20, 180, 65, 10, 5);
122+
btn = GetPressedButton(touchEvt->xCoord, touchEvt->yCoord, 780, 20, 180, 65, 10, 6);
122123
}
123124
} else if (btn != -1) {
124125
// Once user has lifted their finger off / touch events have stopped, continue.
125126
break;
126127
}
127128
}
128129

129-
130130
switch (btn) {
131131
case 0:
132132
RunReadNAND(false);
@@ -143,6 +143,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLin
143143
case 4:
144144
RunSDPinControl(false);
145145
break;
146+
case 5:
147+
RunExitUpdate();
148+
break;
146149
default:
147150
continue;
148151
}

LeafSDTools/LeafSDTools.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
#include <windows.h>
55

6-
#define TOOL_VERSION "103-beta"
6+
#define TOOL_VERSION "104-beta"
77

88
#endif // LEAFSDTOOLS_H

LeafSDTools/LeafSDTools.vcb

0 Bytes
Binary file not shown.

LeafSDTools/LeafSDTools.vcl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</h3>
88
<h3>Command Lines</h3>
99
Creating command line "rc.exe /l 0x409 /fo"SH4Rel/LeafSDTools.res" /d UNDER_CE=500 /d _WIN32_WCE=500 /d "NDEBUG" /d "UNICODE" /d "_UNICODE" /d "WCE_PLATFORM_STANDARDSDK_500" /d "SHx" /d "SH4" /d "_SH4_" /r "E:\Program Files\Microsoft eMbedded C++ 4.0\Common\EVC\MyProjects\LeafSDTools\LeafSDTools.rc""
10-
Creating temporary file "E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSP6BF.tmp" with contents
10+
Creating temporary file "E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSPED.tmp" with contents
1111
[
1212
/nologo /W3 /D _WIN32_WCE=500 /D "WCE_PLATFORM_STANDARDSDK_500" /D "SHx" /D "SH4" /D "_SH4_" /D UNDER_CE=500 /D "UNICODE" /D "_UNICODE" /D "NDEBUG" /FR"SH4Rel/" /Fp"SH4Rel/LeafSDTools.pch" /Yu"stdafx.h" /Fo"SH4Rel/" /Qsh4 /O2 /MC /c
1313
"E:\Program Files\Microsoft eMbedded C++ 4.0\Common\EVC\MyProjects\LeafSDTools\ReadNAND.cpp"
@@ -19,15 +19,16 @@ Creating temporary file "E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSP6BF.tmp" with con
1919
"E:\Program Files\Microsoft eMbedded C++ 4.0\Common\EVC\MyProjects\LeafSDTools\LeafSDTools.cpp"
2020
"E:\Program Files\Microsoft eMbedded C++ 4.0\Common\EVC\MyProjects\LeafSDTools\Logger.cpp"
2121
"E:\Program Files\Microsoft eMbedded C++ 4.0\Common\EVC\MyProjects\LeafSDTools\Touch.cpp"
22+
"E:\Program Files\Microsoft eMbedded C++ 4.0\Common\EVC\MyProjects\LeafSDTools\ExitUpdateMode.cpp"
2223
]
23-
Creating command line "clsh.exe @E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSP6BF.tmp"
24-
Creating temporary file "E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSP6C0.tmp" with contents
24+
Creating command line "clsh.exe @E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSPED.tmp"
25+
Creating temporary file "E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSPEE.tmp" with contents
2526
[
2627
/nologo /W3 /D _WIN32_WCE=500 /D "WCE_PLATFORM_STANDARDSDK_500" /D "SHx" /D "SH4" /D "_SH4_" /D UNDER_CE=500 /D "UNICODE" /D "_UNICODE" /D "NDEBUG" /FR"SH4Rel/" /Fp"SH4Rel/LeafSDTools.pch" /Yc"stdafx.h" /Fo"SH4Rel/" /Qsh4 /O2 /MC /c
2728
"E:\Program Files\Microsoft eMbedded C++ 4.0\Common\EVC\MyProjects\LeafSDTools\StdAfx.cpp"
2829
]
29-
Creating command line "clsh.exe @E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSP6C0.tmp"
30-
Creating temporary file "E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSP6C1.tmp" with contents
30+
Creating command line "clsh.exe @E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSPEE.tmp"
31+
Creating temporary file "E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSPEF.tmp" with contents
3132
[
3233
commctrl.lib coredll.lib ceddk.lib /nologo /base:"0x00010000" /stack:0x10000,0x1000 /entry:"WinMainCRTStartup" /incremental:no /pdb:"SH4Rel/LeafSDTools.pdb" /nodefaultlib:"libc.lib /nodefaultlib:libcd.lib /nodefaultlib:libcmt.lib /nodefaultlib:libcmtd.lib /nodefaultlib:msvcrt.lib /nodefaultlib:msvcrtd.lib" /out:"SH4Rel/LeafSDTools.exe" /subsystem:windowsce,5.00 /MACHINE:SH4
3334
".\SH4Rel\ReadNAND.obj"
@@ -41,8 +42,9 @@ commctrl.lib coredll.lib ceddk.lib /nologo /base:"0x00010000" /stack:0x10000,0x1
4142
".\SH4Rel\StdAfx.obj"
4243
".\SH4Rel\Touch.obj"
4344
".\SH4Rel\LeafSDTools.res"
45+
".\SH4Rel\ExitUpdateMode.obj"
4446
]
45-
Creating command line "link.exe @E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSP6C1.tmp"
47+
Creating command line "link.exe @E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSPEF.tmp"
4648
<h3>Output Window</h3>
4749
Compiling resources...
4850
Compiling...
@@ -65,14 +67,15 @@ E:\Program Files\Microsoft eMbedded C++ 4.0\Common\EVC\MyProjects\LeafSDTools\Di
6567
E:\Program Files\Microsoft eMbedded C++ 4.0\Common\EVC\MyProjects\LeafSDTools\Display.cpp(564) : warning C4244: 'argument' : conversion from 'unsigned long' to 'unsigned short', possible loss of data
6668
E:\Program Files\Microsoft eMbedded C++ 4.0\Common\EVC\MyProjects\LeafSDTools\Display.cpp(681) : warning C4244: '=' : conversion from 'unsigned long' to 'unsigned short', possible loss of data
6769
Flash.cpp
68-
E:\Program Files\Microsoft eMbedded C++ 4.0\Common\EVC\MyProjects\LeafSDTools\Flash.cpp(226) : warning C4129: 'S' : unrecognized character escape sequence
70+
E:\Program Files\Microsoft eMbedded C++ 4.0\Common\EVC\MyProjects\LeafSDTools\Flash.cpp(228) : warning C4129: 'S' : unrecognized character escape sequence
6971
LeafSDTools.cpp
7072
Logger.cpp
7173
Touch.cpp
7274
E:\Program Files\Microsoft eMbedded C++ 4.0\Common\EVC\MyProjects\LeafSDTools\Touch.cpp(40) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
75+
ExitUpdateMode.cpp
7376
Generating Code...
7477
Linking...
75-
Creating temporary file "E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSP6C4.tmp" with contents
78+
Creating temporary file "E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSPF2.tmp" with contents
7679
[
7780
/nologo /o"SH4Rel/LeafSDTools.bsc"
7881
".\SH4Rel\StdAfx.sbr"
@@ -84,8 +87,9 @@ Creating temporary file "E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSP6C4.tmp" with con
8487
".\SH4Rel\Flash.sbr"
8588
".\SH4Rel\LeafSDTools.sbr"
8689
".\SH4Rel\Logger.sbr"
87-
".\SH4Rel\Touch.sbr"]
88-
Creating command line "bscmake.exe @E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSP6C4.tmp"
90+
".\SH4Rel\Touch.sbr"
91+
".\SH4Rel\ExitUpdateMode.sbr"]
92+
Creating command line "bscmake.exe @E:\DOCUME~1\LYLYKA~1\LOCALS~1\Temp\RSPF2.tmp"
8993
Creating browse info file...
9094
<h3>Output Window</h3>
9195

LeafSDTools/LeafSDTools.vco

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)