minor corrections by M.Taguchi
[reactos.git] / 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 #include <rtl.h>
22 #include <ui.h>
23 #include <options.h>
24 #include <miscboot.h>
25 #include <debug.h>
26 #include <disk.h>
27 #include <arch.h>
28 #include <inifile.h>
29 #include <linux.h>
30 #include <reactos.h>
31 #include <drivemap.h>
32
33
34 UCHAR 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";
35 UCHAR BootPartitionPrompt[] = "Enter the boot partition.\n\nEnter 0 for the active (bootable) partition.";
36 UCHAR BootSectorFilePrompt[] = "Enter the boot sector file path.\n\nExamples:\n\\BOOTSECT.DOS\n/boot/bootsect.dos";
37 UCHAR LinuxKernelPrompt[] = "Enter the Linux kernel image path.\n\nExamples:\n/vmlinuz\n/boot/vmlinuz-2.4.18";
38 UCHAR LinuxInitrdPrompt[] = "Enter the initrd image path.\n\nExamples:\n/initrd.gz\n/boot/root.img.gz\n\nLeave blank for no initial ram disk.";
39 UCHAR LinuxCommandLinePrompt[] = "Enter the Linux kernel command line.\n\nExamples:\nroot=/dev/hda1\nroot=/dev/fd0 read-only\nroot=/dev/sdb1 init=/sbin/init";
40 UCHAR ReactOSSystemPathPrompt[] = "Enter the path to your ReactOS system directory.\n\nExamples:\n\\REACTOS\n\\ROS";
41 UCHAR 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";
42
43 UCHAR CustomBootPrompt[] = "Press ENTER to boot your custom boot setup.";
44
45 VOID OptionMenuCustomBoot(VOID)
46 {
47 PUCHAR CustomBootMenuList[] = { "Disk", "Partition", "Boot Sector File", "ReactOS", "Linux" };
48 U32 CustomBootMenuCount = sizeof(CustomBootMenuList) / sizeof(CustomBootMenuList[0]);
49 U32 SelectedMenuItem;
50
51 if (!UiDisplayMenu(CustomBootMenuList, CustomBootMenuCount, 0, -1, &SelectedMenuItem, TRUE, NULL))
52 {
53 // The user pressed ESC
54 return;
55 }
56
57 switch (SelectedMenuItem)
58 {
59 case 0: // Disk
60 OptionMenuCustomBootDisk();
61 break;
62 case 1: // Partition
63 OptionMenuCustomBootPartition();
64 break;
65 case 2: // Boot Sector File
66 OptionMenuCustomBootBootSectorFile();
67 break;
68 case 3: // ReactOS
69 OptionMenuCustomBootReactOS();
70 break;
71 case 4: // Linux
72 OptionMenuCustomBootLinux();
73 break;
74 }
75 }
76
77 VOID OptionMenuCustomBootDisk(VOID)
78 {
79 UCHAR SectionName[100];
80 UCHAR BootDriveString[20];
81 U32 SectionId;
82
83 RtlZeroMemory(SectionName, sizeof(SectionName));
84 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
85
86 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
87 {
88 return;
89 }
90
91 // Generate a unique section name
92 sprintf(SectionName, "CustomBootDisk%d%d%d%d%d%d", getyear(), getday(), getmonth(), gethour(), getminute(), getsecond());
93
94 // Add the section
95 if (!IniAddSection(SectionName, &SectionId))
96 {
97 return;
98 }
99
100 // Add the BootType
101 if (!IniAddSettingValueToSection(SectionId, "BootType", "Drive"))
102 {
103 return;
104 }
105
106 // Add the BootDrive
107 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
108 {
109 return;
110 }
111
112 UiMessageBox(CustomBootPrompt);
113
114 LoadAndBootDrive(SectionName);
115 }
116
117 VOID OptionMenuCustomBootPartition(VOID)
118 {
119 UCHAR SectionName[100];
120 UCHAR BootDriveString[20];
121 UCHAR BootPartitionString[20];
122 U32 SectionId;
123
124 RtlZeroMemory(SectionName, sizeof(SectionName));
125 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
126 RtlZeroMemory(BootPartitionString, sizeof(BootPartitionString));
127
128 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
129 {
130 return;
131 }
132
133 if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
134 {
135 return;
136 }
137
138 // Generate a unique section name
139 sprintf(SectionName, "CustomBootPartition%d%d%d%d%d%d", getyear(), getday(), getmonth(), gethour(), getminute(), getsecond());
140
141 // Add the section
142 if (!IniAddSection(SectionName, &SectionId))
143 {
144 return;
145 }
146
147 // Add the BootType
148 if (!IniAddSettingValueToSection(SectionId, "BootType", "Partition"))
149 {
150 return;
151 }
152
153 // Add the BootDrive
154 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
155 {
156 return;
157 }
158
159 // Add the BootPartition
160 if (!IniAddSettingValueToSection(SectionId, "BootPartition", BootPartitionString))
161 {
162 return;
163 }
164
165 UiMessageBox(CustomBootPrompt);
166
167 LoadAndBootPartition(SectionName);
168 }
169
170 VOID OptionMenuCustomBootBootSectorFile(VOID)
171 {
172 UCHAR SectionName[100];
173 UCHAR BootDriveString[20];
174 UCHAR BootPartitionString[20];
175 UCHAR BootSectorFileString[200];
176 U32 SectionId;
177
178 RtlZeroMemory(SectionName, sizeof(SectionName));
179 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
180 RtlZeroMemory(BootPartitionString, sizeof(BootPartitionString));
181 RtlZeroMemory(BootSectorFileString, sizeof(BootSectorFileString));
182
183 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
184 {
185 return;
186 }
187
188 if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
189 {
190 return;
191 }
192
193 if (!UiEditBox(BootSectorFilePrompt, BootSectorFileString, 200))
194 {
195 return;
196 }
197
198 // Generate a unique section name
199 sprintf(SectionName, "CustomBootSectorFile%d%d%d%d%d%d", getyear(), getday(), getmonth(), gethour(), getminute(), getsecond());
200
201 // Add the section
202 if (!IniAddSection(SectionName, &SectionId))
203 {
204 return;
205 }
206
207 // Add the BootType
208 if (!IniAddSettingValueToSection(SectionId, "BootType", "BootSector"))
209 {
210 return;
211 }
212
213 // Add the BootDrive
214 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
215 {
216 return;
217 }
218
219 // Add the BootPartition
220 if (!IniAddSettingValueToSection(SectionId, "BootPartition", BootPartitionString))
221 {
222 return;
223 }
224
225 // Add the BootSectorFile
226 if (!IniAddSettingValueToSection(SectionId, "BootSectorFile", BootSectorFileString))
227 {
228 return;
229 }
230
231 UiMessageBox(CustomBootPrompt);
232
233 LoadAndBootBootSector(SectionName);
234 }
235
236 VOID OptionMenuCustomBootReactOS(VOID)
237 {
238 UCHAR SectionName[100];
239 UCHAR BootDriveString[20];
240 UCHAR BootPartitionString[20];
241 UCHAR ReactOSSystemPath[200];
242 UCHAR ReactOSARCPath[200];
243 UCHAR ReactOSOptions[200];
244 U32 SectionId;
245
246 RtlZeroMemory(SectionName, sizeof(SectionName));
247 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
248 RtlZeroMemory(BootPartitionString, sizeof(BootPartitionString));
249 RtlZeroMemory(ReactOSSystemPath, sizeof(ReactOSSystemPath));
250 RtlZeroMemory(ReactOSOptions, sizeof(ReactOSOptions));
251
252 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
253 {
254 return;
255 }
256
257 if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
258 {
259 return;
260 }
261
262 if (!UiEditBox(ReactOSSystemPathPrompt, ReactOSSystemPath, 200))
263 {
264 return;
265 }
266
267 if (!UiEditBox(ReactOSOptionsPrompt, ReactOSOptions, 200))
268 {
269 return;
270 }
271
272 // Generate a unique section name
273 sprintf(SectionName, "CustomReactOS%d%d%d%d%d%d", getyear(), getday(), getmonth(), gethour(), getminute(), getsecond());
274
275 // Add the section
276 if (!IniAddSection(SectionName, &SectionId))
277 {
278 return;
279 }
280
281 // Add the BootType
282 if (!IniAddSettingValueToSection(SectionId, "BootType", "ReactOS"))
283 {
284 return;
285 }
286
287 // Construct the ReactOS ARC system path
288 ConstructArcPath(ReactOSARCPath, ReactOSSystemPath, DriveMapGetBiosDriveNumber(BootDriveString), atoi(BootPartitionString));
289
290 // Add the system path
291 if (!IniAddSettingValueToSection(SectionId, "SystemPath", ReactOSARCPath))
292 {
293 return;
294 }
295
296 // Add the CommandLine
297 if (!IniAddSettingValueToSection(SectionId, "Options", ReactOSOptions))
298 {
299 return;
300 }
301
302 UiMessageBox(CustomBootPrompt);
303
304 LoadAndBootReactOS(SectionName);
305 }
306
307 VOID OptionMenuCustomBootLinux(VOID)
308 {
309 UCHAR SectionName[100];
310 UCHAR BootDriveString[20];
311 UCHAR BootPartitionString[20];
312 UCHAR LinuxKernelString[200];
313 UCHAR LinuxInitrdString[200];
314 UCHAR LinuxCommandLineString[200];
315 U32 SectionId;
316
317 RtlZeroMemory(SectionName, sizeof(SectionName));
318 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
319 RtlZeroMemory(BootPartitionString, sizeof(BootPartitionString));
320 RtlZeroMemory(LinuxKernelString, sizeof(LinuxKernelString));
321 RtlZeroMemory(LinuxInitrdString, sizeof(LinuxInitrdString));
322 RtlZeroMemory(LinuxCommandLineString, sizeof(LinuxCommandLineString));
323
324 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
325 {
326 return;
327 }
328
329 if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
330 {
331 return;
332 }
333
334 if (!UiEditBox(LinuxKernelPrompt, LinuxKernelString, 200))
335 {
336 return;
337 }
338
339 if (!UiEditBox(LinuxInitrdPrompt, LinuxInitrdString, 200))
340 {
341 return;
342 }
343
344 if (!UiEditBox(LinuxCommandLinePrompt, LinuxCommandLineString, 200))
345 {
346 return;
347 }
348
349 // Generate a unique section name
350 sprintf(SectionName, "CustomLinux%d%d%d%d%d%d", getyear(), getday(), getmonth(), gethour(), getminute(), getsecond());
351
352 // Add the section
353 if (!IniAddSection(SectionName, &SectionId))
354 {
355 return;
356 }
357
358 // Add the BootType
359 if (!IniAddSettingValueToSection(SectionId, "BootType", "Linux"))
360 {
361 return;
362 }
363
364 // Add the BootDrive
365 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
366 {
367 return;
368 }
369
370 // Add the BootPartition
371 if (!IniAddSettingValueToSection(SectionId, "BootPartition", BootPartitionString))
372 {
373 return;
374 }
375
376 // Add the Kernel
377 if (!IniAddSettingValueToSection(SectionId, "Kernel", LinuxKernelString))
378 {
379 return;
380 }
381
382 // Add the Initrd
383 if (strlen(LinuxInitrdString) > 0)
384 {
385 if (!IniAddSettingValueToSection(SectionId, "Initrd", LinuxInitrdString))
386 {
387 return;
388 }
389 }
390
391 // Add the CommandLine
392 if (!IniAddSettingValueToSection(SectionId, "CommandLine", LinuxCommandLineString))
393 {
394 return;
395 }
396
397 UiMessageBox(CustomBootPrompt);
398
399 LoadAndBootLinux(SectionName, "Custom Linux Setup");
400 }