VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/ipxe/contrib/rom-o-matic/build.php@ 91703

Last change on this file since 91703 was 47928, checked in by vboxsync, 12 years ago

Devices/PC: export iPXE to OSE

  • Property svn:eol-style set to native
File size: 9.1 KB
Line 
1<?php // -*- Mode: PHP; -*-
2
3/**
4 * Copyright (C) 2009 Marty Connor <mdc@etherboot.org>.
5 * Copyright (C) 2009 Entity Cyber, Inc.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22// Get utility functions and set globals
23require_once "utils.php";
24
25// Make sure at least $A (action) was supplied
26if ( ! isset ( $_POST['A'] ) ) {
27
28 // Present user with form to customize build options
29 require_once "customize-flags.php";
30
31 exit ();
32
33// If user chose "Customize" option on form
34} else if ( $_POST['A'] == "Customize" ) {
35
36 // Present user with form to customize build options
37 require_once "customize-flags.php";
38
39 exit ();
40
41// The following conditional includes all other cases except "Get Image"
42// particularly the explicit ($A == "Start Over") case
43} else if ( $_POST['A'] != "Get Image" ) {
44
45 // Note that this method of redirections discards all the
46 // configuration flags, which is intentional in this case.
47
48 $dest = curDirURL ();
49 header ( "Location: $dest" );
50
51 // This next "echo" should normally not be seen, because
52 // the "header" statement above should cause immediate
53 // redirection but just in case...
54
55 echo "Try this link: <a href=\"$dest\">$dest</a>";
56
57 exit ();
58}
59
60// OK, we're going to try to use whatever options have been set
61// to build an image.
62
63// Make sure at least $nic was supplied
64if ( ! isset ( $_POST['nic'] ) ) {
65 die ( "No NIC supplied!" );
66}
67if ( isset ( $nics[$_POST['nic']] ) ) {
68 $nic = $nics[$_POST['nic']];
69} else {
70 die ( "Invalid NIC \"${_POST['nic']}\" supplied!" );
71}
72
73// Fetch flags
74$flags = get_flags ();
75
76// Get requested format
77$ofmt = isset ( $_POST['ofmt'] ) ? $_POST['ofmt'] : "";
78$fmt_extension = isset ( $ofmts[$ofmt] ) ? $ofmts[$ofmt] : 'dsk';
79
80// Handle some special cases
81
82$pci_vendor_code = "";
83$pci_device_code = "";
84
85if ( $nic == 'undionly' && $fmt_extension == "pxe" ) {
86
87 // undionly.pxe can't work because it unloads the PXE stack
88 // that it needs to communicate with, so we set the extension
89 // to .kpxe, which has a chance of working. The extension
90 // .kkpxe is another option.
91
92 $fmt_extension = "kpxe";
93
94} else if ( $fmt_extension == "rom" ) {
95
96 if ( ! isset ( $_POST['pci_vendor_code'] )
97 || ! isset ( $_POST['pci_device_code'] ) ) {
98 die ( "rom output format selected but PCI code(s) missing!" );
99 }
100
101 $pci_vendor_code = $_POST['pci_vendor_code'];
102 $pci_device_code = $_POST['pci_device_code'];
103
104 if ( $pci_vendor_code == ""
105 || $pci_device_code == "" ) {
106 die ( "rom output format selected but PCI code(s) missing!" );
107 }
108
109 // Try to be forgiving of 0xAAAA format
110 if ( strtolower ( substr ( $pci_vendor_code, 0, 2 ) ) == "0x"
111 && strlen ( $pci_vendor_code ) == 6 ) {
112 $pci_vendor_code = substr ( $pci_vendor_code, 2, 4 );
113 }
114 if ( strtolower ( substr ( $pci_device_code, 0, 2 ) ) == "0x"
115 && strlen ( $pci_device_code ) == 6 ) {
116 $pci_device_code = substr ( $pci_device_code, 2, 4 );
117 }
118
119 // concatenate the pci codes to get the $nic part of the
120 // Make target
121 $pci_codes = strtolower ( $pci_vendor_code . $pci_device_code );
122
123 $nic = $pci_codes;
124 if ( ! isset ( $roms[$pci_codes] ) ) {
125 die ( "Sorry, no network driver supports PCI codes<br>"
126 . "${_POST['pci_vendor_code']}:"
127 . "${_POST['pci_device_code']}" );
128 }
129} else if ( $fmt_extension != "rom"
130 && ( $pci_vendor_code != "" || $pci_device_code != "" ) ) {
131 die ( "'$fmt_extension' format was selected but PCI IDs were"
132 . " also entered.<br>Did you mean to select 'rom' output format"
133 . " instead?" );
134}
135
136/**
137 * remove temporary build directory
138 *
139 * @return bool true if removal is successful, false otherwise
140 */
141function rm_build_dir ()
142{
143 global $build_dir;
144 global $keep_build_dir;
145
146 if ( $keep_build_dir !== true ) {
147 rm_file_or_dir ( $build_dir );
148 }
149}
150
151// Arrange for the build directory to always be removed on exit.
152$build_dir = "";
153$keep_build_dir = false;
154register_shutdown_function ( 'rm_build_dir' );
155
156// Make temporary copy of src directory
157$build_dir = mktempcopy ( "$src_dir", "/tmp", "MDCROM" );
158$config_dir = $build_dir . "/config";
159
160// Write config files with supplied flags
161write_ipxe_config_files ( $config_dir, $flags );
162
163// Handle a possible embedded script
164$emb_script_cmd = "";
165$embedded_script = isset ( $_POST['embedded_script'] ) ? $_POST['embedded_script'] : "";
166if ( $embedded_script != "" ) {
167 $emb_script_path = "$build_dir" . "/script0.ipxe";
168
169 if ( substr ( $embedded_script, 0, 5 ) != "#!ipxe" ) {
170 $embedded_script = "#!ipxe\n" . $embedded_script;
171 }
172
173 // iPXE 0.9.7 doesn't like '\r\n" in the shebang...
174 $embedded_script = str_replace ( "\r\n", "\n", $embedded_script );
175
176 write_file_from_string ( $emb_script_path, $embedded_script );
177 $emb_script_cmd = "EMBEDDED_IMAGE=${emb_script_path}";
178}
179
180// Make the requested image. $status is set to 0 on success
181$make_target = "bin/${nic}.${fmt_extension}";
182$make_cmd = "make -C '$build_dir' '$make_target' $emb_script_cmd 2>&1";
183
184exec ( $make_cmd, $maketxt, $status );
185
186// Uncomment the following section for debugging
187
188/**
189
190echo "<h2>build.php:</h2>";
191echo "<h3>Begin debugging output</h3>";
192
193//echo "<h3>\$_POST variables</h3>";
194//echo "<pre>"; var_dump ( $_POST ); echo "</pre>";
195
196echo "<h3>Build options:</h3>";
197echo "<strong>Build directory is:</strong> $build_dir" . "<br><br>";
198echo "\$_POST['ofmt'] = " . "\"${_POST['ofmt']}\"" . "<br>";
199echo "\$_POST['nic'] = " . "\"${_POST['nic']}\"" . "<br>";
200echo "\$_POST['pci_vendor_code'] = " . "\"${_POST['pci_vendor_code']}\"" . "<br>";
201echo "\$_POST['pci_device_code'] = " . "\"${_POST['pci_device_code']}\"" . "<br>";
202
203echo "<h3>Flags:</h3>";
204show_flags ( $flags );
205
206if ( $embedded_script != "" ) {
207 echo "<h3>Embedded script:</h3>";
208 echo "<blockquote>"."<pre>";
209 echo $embedded_script;
210 echo "</pre>"."</blockquote>";
211}
212
213echo "<h3>Make output:</h3>";
214echo "Make command: " . $make_cmd . "<br>";
215echo "Build status = <? echo $status ?>" . "<br>";
216echo "<blockquote>"."<pre>";
217echo htmlentities ( implode ("\n", $maketxt ) );
218echo "</pre>"."</blockquote>";
219// Uncomment the next line if you want to keep the
220// build directory around for inspection after building.
221$keep_build_dir = true;
222die ( "<h3>End debugging output</h3>" );
223
224**/ // End debugging section
225
226// Send ROM to browser (with extreme prejudice)
227
228if ( $status == 0 ) {
229
230 $fp = fopen("${build_dir}/${make_target}", "rb" );
231 if ( $fp > 0 ) {
232
233 $len = filesize ( "${build_dir}/${make_target}" );
234 if ( $len > 0 ) {
235
236 $buf = fread ( $fp, $len );
237 fclose ( $fp );
238
239 // Delete build directory as soon as it is not needed
240 rm_build_dir ();
241
242 $output_filename = "ipxe-${version}-${nic}.${fmt_extension}";
243
244 // Try to force IE to handle downloading right.
245 Header ( "Cache-control: private");
246 Header ( "Content-Type: application/x-octet-stream; " .
247 "name=$output_filename");
248 Header ( "Content-Disposition: attachment; " .
249 "Filename=$output_filename");
250 Header ( "Content-Location: $output_filename");
251 Header ( "Content-Length: $len");
252
253 echo $buf;
254
255 exit ();
256 }
257 }
258}
259
260/*
261 * If we reach this point, the build has failed, and we provide
262 * debugging information for a potential bug report
263 *
264 */
265
266// Remove build directory
267rm_build_dir ();
268
269// Announce failure if $status from make was non-zero
270echo "<h2>Build failed. Status = " . $status . "</h2>";
271echo "<h2>build.php:</h2>";
272echo "<h3>Build options:</h3>";
273echo "<strong>Build directory is:</strong> $build_dir" . "<br><br>";
274echo "\$_POST['ofmt'] = " . "\"${_POST['ofmt']}\"" . "<br>";
275echo "\$_POST['nic'] = " . "\"${_POST['nic']}\"" . "<br>";
276echo "\$_POST['pci_vendor_code'] = " . "\"${_POST['pci_vendor_code']}\"" . "<br>";
277echo "\$_POST['pci_device_code'] = " . "\"${_POST['pci_device_code']}\"" . "<br>";
278
279echo "<h3>Flags:</h3>";
280show_flags ( $flags );
281
282if ( $embedded_script != "" ) {
283 echo "<h3>Embedded script:</h3>";
284 echo "<blockquote>"."<pre>";
285 echo $embedded_script;
286 echo "</pre>"."</blockquote>";
287}
288
289echo "<h3>Make output:</h3>";
290echo "Make command: " . $make_cmd . "<br>";
291echo "<blockquote>"."<pre>";
292echo htmlentities ( implode ("\n", $maketxt ) );
293echo "</pre>"."</blockquote>";
294
295echo "Please let us know that this happened, and paste the above output into your email message.<br>";
296
297include_once $bottom_inc;
298
299// For emacs:
300// Local variables:
301// c-basic-offset: 4
302// c-indent-level: 4
303// tab-width: 4
304// End:
305
306?>
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette