[FREELDR]
[reactos.git] / reactos / boot / freeldr / freeldr / arch / i386 / 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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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[] = {
37 "Disk",
38 "Partition",
39 "Boot Sector File",
40 "ReactOS",
41 "Linux"
42 };
43 ULONG CustomBootMenuCount = sizeof(CustomBootMenuList) / sizeof(CustomBootMenuList[0]);
44 ULONG SelectedMenuItem;
45
46 if (!UiDisplayMenu("Please choose a boot method:",
47 CustomBootMenuList,
48 CustomBootMenuCount,
49 0, -1,
50 &SelectedMenuItem,
51 TRUE,
52 NULL))
53 {
54 // The user pressed ESC
55 return;
56 }
57
58 switch (SelectedMenuItem)
59 {
60 case 0: // Disk
61 OptionMenuCustomBootDisk();
62 break;
63 case 1: // Partition
64 OptionMenuCustomBootPartition();
65 break;
66 case 2: // Boot Sector File
67 OptionMenuCustomBootBootSectorFile();
68 break;
69 case 4: // Linux
70 OptionMenuCustomBootLinux();
71 break;
72 }
73 }
74
75 VOID OptionMenuCustomBootDisk(VOID)
76 {
77 ULONG_PTR SectionId;
78 CHAR SectionName[100];
79 CHAR BootDriveString[20];
80 TIMEINFO* TimeInfo;
81 OperatingSystemItem OperatingSystem;
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 TimeInfo = ArcGetTime();
93 sprintf(SectionName, "CustomBootDisk%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
94
95 // Add the section
96 if (!IniAddSection(SectionName, &SectionId))
97 {
98 return;
99 }
100
101 // Add the BootType
102 if (!IniAddSettingValueToSection(SectionId, "BootType", "Drive"))
103 {
104 return;
105 }
106
107 // Add the BootDrive
108 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
109 {
110 return;
111 }
112
113 UiMessageBox(CustomBootPrompt);
114
115 OperatingSystem.SystemPartition = SectionName;
116 OperatingSystem.LoadIdentifier = NULL;
117 OperatingSystem.OsLoadOptions = NULL;
118
119 LoadAndBootDrive(&OperatingSystem, 0);
120 }
121
122 VOID OptionMenuCustomBootPartition(VOID)
123 {
124 ULONG_PTR SectionId;
125 CHAR SectionName[100];
126 CHAR BootDriveString[20];
127 CHAR BootPartitionString[20];
128 TIMEINFO* TimeInfo;
129 OperatingSystemItem OperatingSystem;
130
131 RtlZeroMemory(SectionName, sizeof(SectionName));
132 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
133 RtlZeroMemory(BootPartitionString, sizeof(BootPartitionString));
134
135 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
136 {
137 return;
138 }
139
140 if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
141 {
142 return;
143 }
144
145 // Generate a unique section name
146 TimeInfo = ArcGetTime();
147 sprintf(SectionName, "CustomBootPartition%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
148
149 // Add the section
150 if (!IniAddSection(SectionName, &SectionId))
151 {
152 return;
153 }
154
155 // Add the BootType
156 if (!IniAddSettingValueToSection(SectionId, "BootType", "Partition"))
157 {
158 return;
159 }
160
161 // Add the BootDrive
162 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
163 {
164 return;
165 }
166
167 // Add the BootPartition
168 if (!IniAddSettingValueToSection(SectionId, "BootPartition", BootPartitionString))
169 {
170 return;
171 }
172
173 UiMessageBox(CustomBootPrompt);
174
175 OperatingSystem.SystemPartition = SectionName;
176 OperatingSystem.LoadIdentifier = NULL;
177 OperatingSystem.OsLoadOptions = NULL;
178
179 LoadAndBootPartition(&OperatingSystem, 0);
180 }
181
182 VOID OptionMenuCustomBootBootSectorFile(VOID)
183 {
184 ULONG_PTR SectionId;
185 CHAR SectionName[100];
186 CHAR BootDriveString[20];
187 CHAR BootPartitionString[20];
188 CHAR BootSectorFileString[200];
189 TIMEINFO* TimeInfo;
190 OperatingSystemItem OperatingSystem;
191
192 RtlZeroMemory(SectionName, sizeof(SectionName));
193 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
194 RtlZeroMemory(BootPartitionString, sizeof(BootPartitionString));
195 RtlZeroMemory(BootSectorFileString, sizeof(BootSectorFileString));
196
197 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
198 {
199 return;
200 }
201
202 if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
203 {
204 return;
205 }
206
207 if (!UiEditBox(BootSectorFilePrompt, BootSectorFileString, 200))
208 {
209 return;
210 }
211
212 // Generate a unique section name
213 TimeInfo = ArcGetTime();
214 sprintf(SectionName, "CustomBootSectorFile%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
215
216 // Add the section
217 if (!IniAddSection(SectionName, &SectionId))
218 {
219 return;
220 }
221
222 // Add the BootType
223 if (!IniAddSettingValueToSection(SectionId, "BootType", "BootSector"))
224 {
225 return;
226 }
227
228 // Add the BootDrive
229 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
230 {
231 return;
232 }
233
234 // Add the BootPartition
235 if (!IniAddSettingValueToSection(SectionId, "BootPartition", BootPartitionString))
236 {
237 return;
238 }
239
240 // Add the BootSectorFile
241 if (!IniAddSettingValueToSection(SectionId, "BootSectorFile", BootSectorFileString))
242 {
243 return;
244 }
245
246 UiMessageBox(CustomBootPrompt);
247
248 OperatingSystem.SystemPartition = SectionName;
249 OperatingSystem.LoadIdentifier = NULL;
250 OperatingSystem.OsLoadOptions = NULL;
251
252 LoadAndBootBootSector(&OperatingSystem, 0);
253 }
254
255 VOID OptionMenuCustomBootLinux(VOID)
256 {
257 ULONG_PTR SectionId;
258 CHAR SectionName[100];
259 CHAR BootDriveString[20];
260 CHAR BootPartitionString[20];
261 CHAR LinuxKernelString[200];
262 CHAR LinuxInitrdString[200];
263 CHAR LinuxCommandLineString[200];
264 TIMEINFO* TimeInfo;
265 OperatingSystemItem OperatingSystem;
266
267 RtlZeroMemory(SectionName, sizeof(SectionName));
268 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
269 RtlZeroMemory(BootPartitionString, sizeof(BootPartitionString));
270 RtlZeroMemory(LinuxKernelString, sizeof(LinuxKernelString));
271 RtlZeroMemory(LinuxInitrdString, sizeof(LinuxInitrdString));
272 RtlZeroMemory(LinuxCommandLineString, sizeof(LinuxCommandLineString));
273
274 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
275 {
276 return;
277 }
278
279 if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
280 {
281 return;
282 }
283
284 if (!UiEditBox(LinuxKernelPrompt, LinuxKernelString, 200))
285 {
286 return;
287 }
288
289 if (!UiEditBox(LinuxInitrdPrompt, LinuxInitrdString, 200))
290 {
291 return;
292 }
293
294 if (!UiEditBox(LinuxCommandLinePrompt, LinuxCommandLineString, 200))
295 {
296 return;
297 }
298
299 // Generate a unique section name
300 TimeInfo = ArcGetTime();
301 sprintf(SectionName, "CustomLinux%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
302
303 // Add the section
304 if (!IniAddSection(SectionName, &SectionId))
305 {
306 return;
307 }
308
309 // Add the BootType
310 if (!IniAddSettingValueToSection(SectionId, "BootType", "Linux"))
311 {
312 return;
313 }
314
315 // Add the BootDrive
316 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
317 {
318 return;
319 }
320
321 // Add the BootPartition
322 if (!IniAddSettingValueToSection(SectionId, "BootPartition", BootPartitionString))
323 {
324 return;
325 }
326
327 // Add the Kernel
328 if (!IniAddSettingValueToSection(SectionId, "Kernel", LinuxKernelString))
329 {
330 return;
331 }
332
333 // Add the Initrd
334 if (strlen(LinuxInitrdString) > 0)
335 {
336 if (!IniAddSettingValueToSection(SectionId, "Initrd", LinuxInitrdString))
337 {
338 return;
339 }
340 }
341
342 // Add the CommandLine
343 if (!IniAddSettingValueToSection(SectionId, "CommandLine", LinuxCommandLineString))
344 {
345 return;
346 }
347
348 UiMessageBox(CustomBootPrompt);
349
350 OperatingSystem.SystemPartition = SectionName;
351 OperatingSystem.LoadIdentifier = "Custom Linux Setup";
352 OperatingSystem.OsLoadOptions = NULL;
353
354 LoadAndBootLinux(&OperatingSystem, 0);
355 }
356
357 VOID OptionMenuReboot(VOID)
358 {
359 UiMessageBox("The system will now reboot.");
360
361 DiskStopFloppyMotor();
362 Reboot();
363 }