Move xbox's i2c support to a separate file, and add support of xbox's LEDs switching...
[reactos.git] / reactos / boot / freeldr / freeldr / custom.c
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <freeldr.h>
21
22
23 const CHAR BootDrivePrompt[] = "Enter the boot drive.\n\nExamples:\nfd0 - first floppy drive\nhd0 - first hard drive\nhd1 - second hard drive\ncd0 - first CD-ROM drive.\n\nBIOS drive numbers may also be used:\n0 - first floppy drive\n0x80 - first hard drive\n0x81 - second hard drive";
24 const CHAR BootPartitionPrompt[] = "Enter the boot partition.\n\nEnter 0 for the active (bootable) partition.";
25 const CHAR BootSectorFilePrompt[] = "Enter the boot sector file path.\n\nExamples:\n\\BOOTSECT.DOS\n/boot/bootsect.dos";
26 const CHAR LinuxKernelPrompt[] = "Enter the Linux kernel image path.\n\nExamples:\n/vmlinuz\n/boot/vmlinuz-2.4.18";
27 const CHAR LinuxInitrdPrompt[] = "Enter the initrd image path.\n\nExamples:\n/initrd.gz\n/boot/root.img.gz\n\nLeave blank for no initial ram disk.";
28 const CHAR LinuxCommandLinePrompt[] = "Enter the Linux kernel command line.\n\nExamples:\nroot=/dev/hda1\nroot=/dev/fd0 read-only\nroot=/dev/sdb1 init=/sbin/init";
29 const CHAR ReactOSSystemPathPrompt[] = "Enter the path to your ReactOS system directory.\n\nExamples:\n\\REACTOS\n\\ROS";
30 const CHAR ReactOSOptionsPrompt[] = "Enter the options you want passed to the kernel.\n\nExamples:\n/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200\n/FASTDETECT /SOS /NOGUIBOOT\n/BASEVIDEO /MAXMEM=64\n/KERNEL=NTKRNLMP.EXE /HAL=HALMPS.DLL";
31
32 const CHAR CustomBootPrompt[] = "Press ENTER to boot your custom boot setup.";
33
34 VOID OptionMenuCustomBoot(VOID)
35 {
36 PCSTR CustomBootMenuList[] = { "Disk", "Partition", "Boot Sector File", "ReactOS", "Linux" };
37 ULONG CustomBootMenuCount = sizeof(CustomBootMenuList) / sizeof(CustomBootMenuList[0]);
38 ULONG SelectedMenuItem;
39
40 if (!UiDisplayMenu(CustomBootMenuList, CustomBootMenuCount, 0, -1, &SelectedMenuItem, TRUE, NULL))
41 {
42 // The user pressed ESC
43 return;
44 }
45
46 switch (SelectedMenuItem)
47 {
48 case 0: // Disk
49 OptionMenuCustomBootDisk();
50 break;
51 case 1: // Partition
52 OptionMenuCustomBootPartition();
53 break;
54 case 2: // Boot Sector File
55 OptionMenuCustomBootBootSectorFile();
56 break;
57 case 3: // ReactOS
58 OptionMenuCustomBootReactOS();
59 break;
60 case 4: // Linux
61 OptionMenuCustomBootLinux();
62 break;
63 }
64 }
65
66 VOID OptionMenuCustomBootDisk(VOID)
67 {
68 CHAR SectionName[100];
69 CHAR BootDriveString[20];
70 ULONG SectionId;
71 ULONG Year, Month, Day, Hour, Minute, Second;
72
73 RtlZeroMemory(SectionName, sizeof(SectionName));
74 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
75
76 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
77 {
78 return;
79 }
80
81 // Generate a unique section name
82 MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second);
83 sprintf(SectionName, "CustomBootDisk%d%d%d%d%d%d", Year, Day, Month, Hour, Minute, Second);
84
85 // Add the section
86 if (!IniAddSection(SectionName, &SectionId))
87 {
88 return;
89 }
90
91 // Add the BootType
92 if (!IniAddSettingValueToSection(SectionId, "BootType", "Drive"))
93 {
94 return;
95 }
96
97 // Add the BootDrive
98 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
99 {
100 return;
101 }
102
103 UiMessageBox(CustomBootPrompt);
104
105 LoadAndBootDrive(SectionName);
106 }
107
108 VOID OptionMenuCustomBootPartition(VOID)
109 {
110 CHAR SectionName[100];
111 CHAR BootDriveString[20];
112 CHAR BootPartitionString[20];
113 ULONG SectionId;
114 ULONG Year, Month, Day, Hour, Minute, Second;
115
116 RtlZeroMemory(SectionName, sizeof(SectionName));
117 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
118 RtlZeroMemory(BootPartitionString, sizeof(BootPartitionString));
119
120 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
121 {
122 return;
123 }
124
125 if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
126 {
127 return;
128 }
129
130 // Generate a unique section name
131 MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second);
132 sprintf(SectionName, "CustomBootPartition%d%d%d%d%d%d", Year, Day, Month, Hour, Minute, Second);
133
134 // Add the section
135 if (!IniAddSection(SectionName, &SectionId))
136 {
137 return;
138 }
139
140 // Add the BootType
141 if (!IniAddSettingValueToSection(SectionId, "BootType", "Partition"))
142 {
143 return;
144 }
145
146 // Add the BootDrive
147 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
148 {
149 return;
150 }
151
152 // Add the BootPartition
153 if (!IniAddSettingValueToSection(SectionId, "BootPartition", BootPartitionString))
154 {
155 return;
156 }
157
158 UiMessageBox(CustomBootPrompt);
159
160 LoadAndBootPartition(SectionName);
161 }
162
163 VOID OptionMenuCustomBootBootSectorFile(VOID)
164 {
165 CHAR SectionName[100];
166 CHAR BootDriveString[20];
167 CHAR BootPartitionString[20];
168 CHAR BootSectorFileString[200];
169 ULONG SectionId;
170 ULONG Year, Month, Day, Hour, Minute, Second;
171
172 RtlZeroMemory(SectionName, sizeof(SectionName));
173 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
174 RtlZeroMemory(BootPartitionString, sizeof(BootPartitionString));
175 RtlZeroMemory(BootSectorFileString, sizeof(BootSectorFileString));
176
177 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
178 {
179 return;
180 }
181
182 if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
183 {
184 return;
185 }
186
187 if (!UiEditBox(BootSectorFilePrompt, BootSectorFileString, 200))
188 {
189 return;
190 }
191
192 // Generate a unique section name
193 MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second);
194 sprintf(SectionName, "CustomBootSectorFile%d%d%d%d%d%d", Year, Day, Month, Hour, Minute, Second);
195
196 // Add the section
197 if (!IniAddSection(SectionName, &SectionId))
198 {
199 return;
200 }
201
202 // Add the BootType
203 if (!IniAddSettingValueToSection(SectionId, "BootType", "BootSector"))
204 {
205 return;
206 }
207
208 // Add the BootDrive
209 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
210 {
211 return;
212 }
213
214 // Add the BootPartition
215 if (!IniAddSettingValueToSection(SectionId, "BootPartition", BootPartitionString))
216 {
217 return;
218 }
219
220 // Add the BootSectorFile
221 if (!IniAddSettingValueToSection(SectionId, "BootSectorFile", BootSectorFileString))
222 {
223 return;
224 }
225
226 UiMessageBox(CustomBootPrompt);
227
228 LoadAndBootBootSector(SectionName);
229 }
230
231 VOID OptionMenuCustomBootReactOS(VOID)
232 {
233 CHAR SectionName[100];
234 CHAR BootDriveString[20];
235 CHAR BootPartitionString[20];
236 CHAR ReactOSSystemPath[200];
237 CHAR ReactOSARCPath[200];
238 CHAR ReactOSOptions[200];
239 ULONG SectionId;
240 ULONG Year, Month, Day, Hour, Minute, Second;
241
242 RtlZeroMemory(SectionName, sizeof(SectionName));
243 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
244 RtlZeroMemory(BootPartitionString, sizeof(BootPartitionString));
245 RtlZeroMemory(ReactOSSystemPath, sizeof(ReactOSSystemPath));
246 RtlZeroMemory(ReactOSOptions, sizeof(ReactOSOptions));
247
248 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
249 {
250 return;
251 }
252
253 if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
254 {
255 return;
256 }
257
258 if (!UiEditBox(ReactOSSystemPathPrompt, ReactOSSystemPath, 200))
259 {
260 return;
261 }
262
263 if (!UiEditBox(ReactOSOptionsPrompt, ReactOSOptions, 200))
264 {
265 return;
266 }
267
268 // Generate a unique section name
269 MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second);
270 sprintf(SectionName, "CustomReactOS%d%d%d%d%d%d", Year, Day, Month, Hour, Minute, Second);
271
272 // Add the section
273 if (!IniAddSection(SectionName, &SectionId))
274 {
275 return;
276 }
277
278 // Add the BootType
279 if (!IniAddSettingValueToSection(SectionId, "BootType", "ReactOS"))
280 {
281 return;
282 }
283
284 // Construct the ReactOS ARC system path
285 ConstructArcPath(ReactOSARCPath, ReactOSSystemPath, DriveMapGetBiosDriveNumber(BootDriveString), atoi(BootPartitionString));
286
287 // Add the system path
288 if (!IniAddSettingValueToSection(SectionId, "SystemPath", ReactOSARCPath))
289 {
290 return;
291 }
292
293 // Add the CommandLine
294 if (!IniAddSettingValueToSection(SectionId, "Options", ReactOSOptions))
295 {
296 return;
297 }
298
299 UiMessageBox(CustomBootPrompt);
300
301 LoadAndBootReactOS(SectionName);
302 }
303
304 VOID OptionMenuCustomBootLinux(VOID)
305 {
306 CHAR SectionName[100];
307 CHAR BootDriveString[20];
308 CHAR BootPartitionString[20];
309 CHAR LinuxKernelString[200];
310 CHAR LinuxInitrdString[200];
311 CHAR LinuxCommandLineString[200];
312 ULONG SectionId;
313 ULONG Year, Month, Day, Hour, Minute, Second;
314
315 RtlZeroMemory(SectionName, sizeof(SectionName));
316 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
317 RtlZeroMemory(BootPartitionString, sizeof(BootPartitionString));
318 RtlZeroMemory(LinuxKernelString, sizeof(LinuxKernelString));
319 RtlZeroMemory(LinuxInitrdString, sizeof(LinuxInitrdString));
320 RtlZeroMemory(LinuxCommandLineString, sizeof(LinuxCommandLineString));
321
322 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
323 {
324 return;
325 }
326
327 if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
328 {
329 return;
330 }
331
332 if (!UiEditBox(LinuxKernelPrompt, LinuxKernelString, 200))
333 {
334 return;
335 }
336
337 if (!UiEditBox(LinuxInitrdPrompt, LinuxInitrdString, 200))
338 {
339 return;
340 }
341
342 if (!UiEditBox(LinuxCommandLinePrompt, LinuxCommandLineString, 200))
343 {
344 return;
345 }
346
347 // Generate a unique section name
348 MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second);
349 sprintf(SectionName, "CustomLinux%d%d%d%d%d%d", Year, Day, Month, Hour, Minute, Second);
350
351 // Add the section
352 if (!IniAddSection(SectionName, &SectionId))
353 {
354 return;
355 }
356
357 // Add the BootType
358 if (!IniAddSettingValueToSection(SectionId, "BootType", "Linux"))
359 {
360 return;
361 }
362
363 // Add the BootDrive
364 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
365 {
366 return;
367 }
368
369 // Add the BootPartition
370 if (!IniAddSettingValueToSection(SectionId, "BootPartition", BootPartitionString))
371 {
372 return;
373 }
374
375 // Add the Kernel
376 if (!IniAddSettingValueToSection(SectionId, "Kernel", LinuxKernelString))
377 {
378 return;
379 }
380
381 // Add the Initrd
382 if (strlen(LinuxInitrdString) > 0)
383 {
384 if (!IniAddSettingValueToSection(SectionId, "Initrd", LinuxInitrdString))
385 {
386 return;
387 }
388 }
389
390 // Add the CommandLine
391 if (!IniAddSettingValueToSection(SectionId, "CommandLine", LinuxCommandLineString))
392 {
393 return;
394 }
395
396 UiMessageBox(CustomBootPrompt);
397
398 LoadAndBootLinux(SectionName, "Custom Linux Setup");
399 }