don't do HDD checks when no vmc configuref
[open-ps2-loader.git] / labs / genvmclab / genvmclab.c
blobc0f394c3f5e9762af99c8effbae96e1e4b1c5db3
2 #include <tamtypes.h>
3 #include <kernel.h>
4 #include <sifrpc.h>
5 #include <loadfile.h>
6 #include <fileio.h>
7 #include <fileXio_rpc.h>
8 #include <malloc.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <sbv_patches.h>
12 #include <iopcontrol.h>
13 #include <iopheap.h>
14 #include <debug.h>
15 #include <sys/time.h>
16 #include <time.h>
18 #include "../../modules/vmc/genvmc/genvmc.h"
20 #define DPRINTF(args...) printf(args); scr_printf(args);
22 #define IP_ADDR "192.168.0.10"
23 #define NETMASK "255.255.255.0"
24 #define GATEWAY "192.168.0.1"
26 extern void poweroff_irx;
27 extern int size_poweroff_irx;
28 extern void ps2dev9_irx;
29 extern int size_ps2dev9_irx;
30 extern void smsutils_irx;
31 extern int size_smsutils_irx;
32 extern void smstcpip_irx;
33 extern int size_smstcpip_irx;
34 extern void smsmap_irx;
35 extern int size_smsmap_irx;
36 extern void udptty_irx;
37 extern int size_udptty_irx;
38 extern void ioptrap_irx;
39 extern int size_ioptrap_irx;
40 extern void ps2link_irx;
41 extern int size_ps2link_irx;
42 extern void iomanx_irx;
43 extern int size_iomanx_irx;
44 extern void filexio_irx;
45 extern int size_filexio_irx;
46 extern void usbd_irx;
47 extern int size_usbd_irx;
48 extern void usbhdfsd_irx;
49 extern int size_usbhdfsd_irx;
50 extern void genvmc_irx;
51 extern int size_genvmc_irx;
52 extern void mcman_irx;
53 extern int size_mcman_irx;
55 // for IP config
56 #define IPCONFIG_MAX_LEN 64
57 static char g_ipconfig[IPCONFIG_MAX_LEN] __attribute__((aligned(64)));
58 static int g_ipconfig_len;
60 //--------------------------------------------------------------
61 void delay(int count)
63 int i;
64 int ret;
65 for (i = 0; i < count; i++) {
66 ret = 0x01000000;
67 while(ret--) asm("nop\nnop\nnop\nnop");
71 //--------------------------------------------------------------
72 void set_ipconfig(void)
74 memset(g_ipconfig, 0, IPCONFIG_MAX_LEN);
75 g_ipconfig_len = 0;
77 strncpy(&g_ipconfig[g_ipconfig_len], IP_ADDR, 15);
78 g_ipconfig_len += strlen(IP_ADDR) + 1;
79 strncpy(&g_ipconfig[g_ipconfig_len], NETMASK, 15);
80 g_ipconfig_len += strlen(NETMASK) + 1;
81 strncpy(&g_ipconfig[g_ipconfig_len], GATEWAY, 15);
82 g_ipconfig_len += strlen(GATEWAY) + 1;
85 //--------------------------------------------------------------
86 int main(int argc, char *argv[2])
88 int ret, id;
90 init_scr();
91 scr_clear();
93 DPRINTF("genvmclab start...\n");
95 SifInitRpc(0);
97 DPRINTF("IOP Reset... ");
99 while(!SifIopReset("rom0:UDNL rom0:EELOADCNF",0));
100 while(!SifIopSync());;
101 fioExit();
102 SifExitIopHeap();
103 SifLoadFileExit();
104 SifExitRpc();
105 SifExitCmd();
107 SifInitRpc(0);
108 FlushCache(0);
109 FlushCache(2);
111 SifLoadFileInit();
112 SifInitIopHeap();
114 sbv_patch_enable_lmb();
115 sbv_patch_disable_prefix_check();
117 SifLoadModule("rom0:SIO2MAN", 0, 0);
118 //SifLoadModule("rom0:MCMAN", 0, 0);
120 DPRINTF("OK\n");
122 set_ipconfig();
124 // HomeBrew mcman required by genvmc for VMCcopy function to work (on my V3, mcman
125 // from ROM is buggy and we can't read MC pages directly)
126 DPRINTF("loading mcman... ");
127 id = SifExecModuleBuffer(&mcman_irx, size_mcman_irx, 0, NULL, &ret);
128 DPRINTF("ret=%d\n", ret);
130 DPRINTF("loading iomanX... ");
131 id = SifExecModuleBuffer(&iomanx_irx, size_iomanx_irx, 0, NULL, &ret);
132 DPRINTF("ret=%d\n", ret);
134 DPRINTF("loading fileXio... ");
135 id = SifExecModuleBuffer(&filexio_irx, size_filexio_irx, 0, NULL, &ret);
136 DPRINTF("ret=%d\n", ret);
138 DPRINTF("loading poweroff... "); // modules for debugging
139 id = SifExecModuleBuffer(&poweroff_irx, size_poweroff_irx, 0, NULL, &ret);
140 DPRINTF("ret=%d\n", ret);
142 DPRINTF("loading ps2dev9... ");
143 id = SifExecModuleBuffer(&ps2dev9_irx, size_ps2dev9_irx, 0, NULL, &ret);
144 DPRINTF("ret=%d\n", ret);
146 DPRINTF("loading smsutils... ");
147 id = SifExecModuleBuffer(&smsutils_irx, size_smsutils_irx, 0, NULL, &ret);
148 DPRINTF("ret=%d\n", ret);
150 DPRINTF("loading smstcpip... ");
151 id = SifExecModuleBuffer(&smstcpip_irx, size_smstcpip_irx, 0, NULL, &ret);
152 DPRINTF("ret=%d\n", ret);
154 DPRINTF("loading smsmap... ");
155 id = SifExecModuleBuffer(&smsmap_irx, size_smsmap_irx, g_ipconfig_len, g_ipconfig, &ret);
156 DPRINTF("ret=%d\n", ret);
158 DPRINTF("loading udptty... ");
159 id = SifExecModuleBuffer(&udptty_irx, size_udptty_irx, 0, NULL, &ret);
160 DPRINTF("ret=%d\n", ret);
162 DPRINTF("loading ioptrap... ");
163 id = SifExecModuleBuffer(&ioptrap_irx, size_ioptrap_irx, 0, NULL, &ret);
164 DPRINTF("ret=%d\n", ret);
166 DPRINTF("loading ps2link... ");
167 id = SifExecModuleBuffer(&ps2link_irx, size_ps2link_irx, 0, NULL, &ret);
168 DPRINTF("ret=%d\n", ret);
170 DPRINTF("loading genvmc... "); // the module in testing
171 id = SifExecModuleBuffer(&genvmc_irx, size_genvmc_irx, 0, NULL, &ret);
172 DPRINTF("ret=%d\n", ret);
174 DPRINTF("loading usbd... "); // usb drivers needed to create file on it
175 id = SifExecModuleBuffer(&usbd_irx, size_usbd_irx, 0, NULL, &ret);
176 DPRINTF("ret=%d\n", ret);
178 DPRINTF("loading usbhdfsd... ");
179 id = SifExecModuleBuffer(&usbhdfsd_irx, size_usbhdfsd_irx, 0, NULL, &ret);
180 DPRINTF("ret=%d\n", ret);
182 delay(3); // some delay is required by usb mass storage driver
184 DPRINTF("modules load OK\n");
186 fileXioInit();
188 // ----------------------------------------------------------------
189 // how to get a blank vmc file created
190 // ----------------------------------------------------------------
191 createVMCparam_t p;
192 statusVMCparam_t vmc_stats;
194 memset(&p, 0, sizeof(createVMCparam_t));
195 strcpy(p.VMC_filename, "mass:8MB_VMC0.bin");
196 p.VMC_card_slot = -1; // do not forget this for blank VMC file creation
197 p.VMC_size_mb = 8;
198 p.VMC_blocksize = 16; // usually official MC has blocksize of 16
199 p.VMC_thread_priority = 0xf;
200 DPRINTF("requesting VMC file creation... ");
201 ret = fileXioDevctl("genvmc:", GENVMC_DEVCTL_CREATE_VMC, (void *)&p, sizeof(p), NULL, 0);
202 if (ret == 0) {
203 DPRINTF("OK\n");
205 else {
206 DPRINTF("Error %d\n", ret);
209 memset(&vmc_stats, 0, sizeof(statusVMCparam_t));
210 DPRINTF("waiting VMC file created...\n");
211 while (1) {
213 ret = fileXioDevctl("genvmc:", GENVMC_DEVCTL_STATUS, NULL, 0, (void *)&vmc_stats, sizeof(vmc_stats));
214 if (ret == 0) {
215 printf("progress: %d message: %s\n", vmc_stats.VMC_progress, vmc_stats.VMC_msg);
216 if (vmc_stats.VMC_status == GENVMC_STAT_AVAIL)
217 break;
220 delay(2);
222 DPRINTF("Done\n");
223 DPRINTF("VMC Error = %d\n", vmc_stats.VMC_error);
225 // ----------------------------------------------------------------
226 // how to get a vmc file created from an existing MC
227 // ----------------------------------------------------------------
228 memset(&p, 0, sizeof(createVMCparam_t));
229 strcpy(p.VMC_filename, "mass:8MB_VMC1.bin");
230 p.VMC_card_slot = 0; // 0=slot 1, 1=slot 2
231 p.VMC_thread_priority = 0xf;
232 DPRINTF("requesting VMC file creation... ");
233 ret = fileXioDevctl("genvmc:", GENVMC_DEVCTL_CREATE_VMC, (void *)&p, sizeof(p), NULL, 0);
234 if (ret == 0) {
235 DPRINTF("OK\n");
237 else {
238 DPRINTF("Error %d\n", ret);
241 memset(&vmc_stats, 0, sizeof(statusVMCparam_t));
242 DPRINTF("waiting VMC file created...\n");
243 while (1) {
245 ret = fileXioDevctl("genvmc:", GENVMC_DEVCTL_STATUS, NULL, 0, (void *)&vmc_stats, sizeof(vmc_stats));
246 if (ret == 0) {
247 printf("progress: %d message: %s\n", vmc_stats.VMC_progress, vmc_stats.VMC_msg);
248 if (vmc_stats.VMC_status == GENVMC_STAT_AVAIL)
249 break;
252 delay(2);
254 DPRINTF("Done\n");
255 DPRINTF("VMC Error = %d\n", vmc_stats.VMC_error);
257 SleepThread();
258 return 0;