[ROSTESTS]
[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(CustomBootMenuList, CustomBootMenuCount, 0, -1, &SelectedMenuItem, TRUE, NULL))
47 {
48 // The user pressed ESC
49 return;
50 }
51
52 switch (SelectedMenuItem)
53 {
54 case 0: // Disk
55 OptionMenuCustomBootDisk();
56 break;
57 case 1: // Partition
58 OptionMenuCustomBootPartition();
59 break;
60 case 2: // Boot Sector File
61 OptionMenuCustomBootBootSectorFile();
62 break;
63 case 4: // Linux
64 OptionMenuCustomBootLinux();
65 break;
66 }
67 }
68
69 VOID OptionMenuCustomBootDisk(VOID)
70 {
71 CHAR SectionName[100];
72 CHAR BootDriveString[20];
73 ULONG SectionId;
74 TIMEINFO* TimeInfo;
75
76 RtlZeroMemory(SectionName, sizeof(SectionName));
77 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
78
79 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
80 {
81 return;
82 }
83
84 // Generate a unique section name
85 TimeInfo = ArcGetTime();
86 sprintf(SectionName, "CustomBootDisk%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
87
88 // Add the section
89 if (!IniAddSection(SectionName, &SectionId))
90 {
91 return;
92 }
93
94 // Add the BootType
95 if (!IniAddSettingValueToSection(SectionId, "BootType", "Drive"))
96 {
97 return;
98 }
99
100 // Add the BootDrive
101 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
102 {
103 return;
104 }
105
106 UiMessageBox(CustomBootPrompt);
107
108 LoadAndBootDrive(SectionName);
109 }
110
111 VOID OptionMenuCustomBootPartition(VOID)
112 {
113 CHAR SectionName[100];
114 CHAR BootDriveString[20];
115 CHAR BootPartitionString[20];
116 ULONG SectionId;
117 TIMEINFO* TimeInfo;
118
119 RtlZeroMemory(SectionName, sizeof(SectionName));
120 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
121 RtlZeroMemory(BootPartitionString, sizeof(BootPartitionString));
122
123 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
124 {
125 return;
126 }
127
128 if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
129 {
130 return;
131 }
132
133 // Generate a unique section name
134 TimeInfo = ArcGetTime();
135 sprintf(SectionName, "CustomBootPartition%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
136
137 // Add the section
138 if (!IniAddSection(SectionName, &SectionId))
139 {
140 return;
141 }
142
143 // Add the BootType
144 if (!IniAddSettingValueToSection(SectionId, "BootType", "Partition"))
145 {
146 return;
147 }
148
149 // Add the BootDrive
150 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
151 {
152 return;
153 }
154
155 // Add the BootPartition
156 if (!IniAddSettingValueToSection(SectionId, "BootPartition", BootPartitionString))
157 {
158 return;
159 }
160
161 UiMessageBox(CustomBootPrompt);
162
163 LoadAndBootPartition(SectionName);
164 }
165
166 VOID OptionMenuCustomBootBootSectorFile(VOID)
167 {
168 CHAR SectionName[100];
169 CHAR BootDriveString[20];
170 CHAR BootPartitionString[20];
171 CHAR BootSectorFileString[200];
172 ULONG SectionId;
173 TIMEINFO* TimeInfo;
174
175 RtlZeroMemory(SectionName, sizeof(SectionName));
176 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
177 RtlZeroMemory(BootPartitionString, sizeof(BootPartitionString));
178 RtlZeroMemory(BootSectorFileString, sizeof(BootSectorFileString));
179
180 if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
181 {
182 return;
183 }
184
185 if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
186 {
187 return;
188 }
189
190 if (!UiEditBox(BootSectorFilePrompt, BootSectorFileString, 200))
191 {
192 return;
193 }
194
195 // Generate a unique section name
196 TimeInfo = ArcGetTime();
197 sprintf(SectionName, "CustomBootSectorFile%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
198
199 // Add the section
200 if (!IniAddSection(SectionName, &SectionId))
201 {
202 return;
203 }
204
205 // Add the BootType
206 if (!IniAddSettingValueToSection(SectionId, "BootType", "BootSector"))
207 {
208 return;
209 }
210
211 // Add the BootDrive
212 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
213 {
214 return;
215 }
216
217 // Add the BootPartition
218 if (!IniAddSettingValueToSection(SectionId, "BootPartition", BootPartitionString))
219 {
220 return;
221 }
222
223 // Add the BootSectorFile
224 if (!IniAddSettingValueToSection(SectionId, "BootSectorFile", BootSectorFileString))
225 {
226 return;
227 }
228
229 UiMessageBox(CustomBootPrompt);
230
231 LoadAndBootBootSector(SectionName);
232 }
233
234 VOID OptionMenuCustomBootLinux(VOID)
235 {
236 CHAR SectionName[100];
237 CHAR BootDriveString[20];
238 CHAR BootPartitionString[20];
239 CHAR LinuxKernelString[200];
240 CHAR LinuxInitrdString[200];
241 CHAR LinuxCommandLineString[200];
242 ULONG SectionId;
243 TIMEINFO* TimeInfo;
244
245 RtlZeroMemory(SectionName, sizeof(SectionName));
246 RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
247 RtlZeroMemory(BootPartitionString, sizeof(BootPartitionString));
248 RtlZeroMemory(LinuxKernelString, sizeof(LinuxKernelString));
249 RtlZeroMemory(LinuxInitrdString, sizeof(LinuxInitrdString));
250 RtlZeroMemory(LinuxCommandLineString, sizeof(LinuxCommandLineString));
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(LinuxKernelPrompt, LinuxKernelString, 200))
263 {
264 return;
265 }
266
267 if (!UiEditBox(LinuxInitrdPrompt, LinuxInitrdString, 200))
268 {
269 return;
270 }
271
272 if (!UiEditBox(LinuxCommandLinePrompt, LinuxCommandLineString, 200))
273 {
274 return;
275 }
276
277 // Generate a unique section name
278 TimeInfo = ArcGetTime();
279 sprintf(SectionName, "CustomLinux%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
280
281 // Add the section
282 if (!IniAddSection(SectionName, &SectionId))
283 {
284 return;
285 }
286
287 // Add the BootType
288 if (!IniAddSettingValueToSection(SectionId, "BootType", "Linux"))
289 {
290 return;
291 }
292
293 // Add the BootDrive
294 if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
295 {
296 return;
297 }
298
299 // Add the BootPartition
300 if (!IniAddSettingValueToSection(SectionId, "BootPartition", BootPartitionString))
301 {
302 return;
303 }
304
305 // Add the Kernel
306 if (!IniAddSettingValueToSection(SectionId, "Kernel", LinuxKernelString))
307 {
308 return;
309 }
310
311 // Add the Initrd
312 if (strlen(LinuxInitrdString) > 0)
313 {
314 if (!IniAddSettingValueToSection(SectionId, "Initrd", LinuxInitrdString))
315 {
316 return;
317 }
318 }
319
320 // Add the CommandLine
321 if (!IniAddSettingValueToSection(SectionId, "CommandLine", LinuxCommandLineString))
322 {
323 return;
324 }
325
326 UiMessageBox(CustomBootPrompt);
327
328 LoadAndBootLinux(SectionName, "Custom Linux Setup");
329 }
330
331 VOID OptionMenuReboot(VOID)
332 {
333 UiMessageBox("The system will now reboot.");
334
335 DiskStopFloppyMotor();
336 SoftReboot();
337 }