slitaz-dev-tools view mirror-tools/slitaz/mirror/floppies/builder/index.php @ rev 167

Tiny edits
author Paul Issott <paul@slitaz.org>
date Fri Mar 23 22:06:42 2012 +0000 (2012-03-23)
parents a1732b0d78aa
children 82786012f589
line source
1 <?php
2 if (false) { // no php support on this mirror !
3 ?>
4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
7 <head>
8 <title>SliTaz Boot Floppies redirection</title>
9 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
10 <meta name="description" content="slitaz boot floppies builder redirection" />
11 <meta name="robots" content="index, nofollow" />
12 <meta name="author" content="SliTaz Contributors" />
13 <meta http-equiv="Refresh" content="0;url=http://mirror.slitaz.org/floppies/builder/index.php">
14 </head>
15 <?php
16 }
17 ini_set('upload_max_filesize','16M');
18 ini_set('post_max_size','16M');
19 if (isset($_GET['id']) && is_file("/tmp/".$_GET['id']."/fd")) {
21 // Download a floppy image
23 $size = $_GET['s'];
24 if ($size == 0)
25 $size = filesize("/tmp/".$_GET['id']."/fd");
26 header("Content-Type: application/octet-stream");
27 header("Content-Length: ".$size);
28 header("Content-Disposition: attachment; filename=".
29 sprintf("fd%03d.img",$_GET['n']));
30 $cmd = "cat /tmp/".$_GET['id']."/fd";
31 if ($_GET['s'] != 0) {
32 $cmd .= " /dev/zero | dd count=1 bs=".$_GET['s'];
33 if ($_GET['n'] > 1)
34 $cmd .= " skip=".($_GET['n']-1);
35 }
36 echo `$cmd 2> /dev/null`;
37 exit;
38 }
39 ?>
40 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
41 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
42 <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
43 <head>
44 <title>SliTaz Boot Floppies</title>
45 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
46 <meta name="description" content="slitaz boot floppies builder" />
47 <meta name="robots" content="index, nofollow" />
48 <meta name="author" content="SliTaz Contributors" />
49 <link rel="shortcut icon" href="/static/favicon.ico" />
50 <link rel="stylesheet" type="text/css" href="/static/slitaz.css" />
51 <style type="text/css">
53 input[type=text] {
54 width: inherit;
55 }
57 #content {
58 margin: 6px 280px 0px 0px;
59 padding: 0px 3% 20px 4%;
60 }
62 #nav {
63 right: 4%;
64 }
66 #copy {
67 text-align: center;
68 }
70 #bottom {
71 text-align: center;
72 }
74 </style>
75 </head>
76 <body bgcolor="#ffffff">
77 <!-- Header -->
78 <div id="header">
79 <a name="top"></a>
80 <div id="logo"></div>
81 <div id="network">
82 <a href="http://www.slitaz.org/">
83 <img src="/static/network.png" alt="[ home ]" /></a>
84 <a href="bootloader" title="Build your floppy sets without Internet">Shell builder</a> |
85 <a href="../../boot/floppy-grub4dos" title="Boot tools">Generic boot floppy</a>
86 </div>
87 <h1><a href="http://www.slitaz.org/">Boot floppies builder</a></h1>
88 </div>
90 <!-- Navigation menu -->
91 <div id="nav">
93 <?php
95 // Cleanup old sessions
97 $dir = opendir("/tmp");
98 while (($name = readdir($dir)) !== false) {
99 if (preg_match('/^fdbuild/',$name) == 0) continue;
100 if (filemtime("/tmp/$name") > strtotime("-1 hour")) continue;
101 system("rm -rf /tmp/$name");
102 }
103 closedir($dir);
105 function get_long($file, $offset)
106 {
107 $value = 0;
108 if ($fp = fopen($file,"r")) {
109 fseek($fp,$offset,SEEK_SET);
110 for ($i = 0; $i < 32; $i += 8) {
111 $value += ord(fgetc($fp)) << $i;
112 }
113 fclose($fp);
114 }
115 return $value;
116 }
118 function error($string, $title="Error")
119 {
120 echo <<<EOT
121 <div class="nav_box">
122 <h4>$title</h4>
123 <p>
124 $string
125 </p>
126 </div>
127 EOT;
128 }
130 $size = 0;
131 $initrd_size = 0;
133 // Upload kernel
135 foreach($_FILES as $data) {
136 $msg="The file ".$_FILES["kernel"]['name']." ";
137 switch ($data["error"]) {
138 case UPLOAD_ERR_INI_SIZE :
139 error($msg."exceeds upload_max_filesize.");
140 break;
141 case UPLOAD_ERR_FORM_SIZE :
142 error($msg."exceeds max_post_size.");
143 break;
144 case UPLOAD_ERR_PARTIAL :
145 error($msg."was only partially uploaded.");
146 break;
147 case UPLOAD_ERR_NO_TMP_DIR :
148 error("Missing a temporary folder.");
149 break;
150 case UPLOAD_ERR_CANT_WRITE :
151 error("Failed to write file to disk.");
152 break;
153 }
154 }
155 if (isset($_FILES["kernel"]['tmp_name']) &&
156 is_uploaded_file($_FILES["kernel"]['tmp_name'])) {
157 $tmp_dir = tempnam('','fdbuild');
158 if (file_exists($tmp_dir)) unlink($tmp_dir);
159 mkdir($tmp_dir);
160 $tmp_dir .= '/';
161 move_uploaded_file($_FILES["kernel"]['tmp_name'],
162 $tmp_dir."kernel");
163 $kernel = $tmp_dir."kernel";
164 $boot_version = get_long($kernel,0x206) & 255;
165 $size = get_long($kernel,0x1F4); // syssize paragraphs
166 if ($boot_version < 4) $size &= 0xFFFF; // 16 bits before 2.4
167 $size = ($size + 0xFFF) & 0xFFFF000; // round up to 64K
168 $size <<= 4; // paragraphs -> bytes
169 if (get_long($kernel,0x202) != 0x53726448 || // 'HdrS' magic
170 (get_long($kernel,0x211) & 1 != 1)) { // bzImage flag
171 error("The file ".$_FILES["kernel"]['name'].
172 " is not a bzImage Linux kernel.");
173 $size = 0;
174 }
175 else if ($boot_version < 2 && $_POST['cmdline']) { // before 2.2
176 unset($_POST['cmdline']);
177 error("This boot loader does not support Linux kernel ".
178 "prior 2.4.0-test3-pre3 command line.",
179 "Warning");
180 }
181 $msg = "The size of the file ".$_FILES["kernel"]['name'];
182 }
184 // Upload initrd
186 if ($size && isset($_FILES["initrd"]['tmp_name']) &&
187 is_uploaded_file($_FILES["initrd"]['tmp_name'])) {
188 move_uploaded_file($_FILES["initrd"]['tmp_name'],
189 $tmp_dir."initrd");
190 $initrd_size = $_FILES["initrd"]['size'];
191 $size += $initrd_size;
192 $msg = "The total size of the files ".$_FILES["kernel"]['name'].
193 " and ".$_FILES["initrd"]['name'];
194 }
195 if ($initrd_size && isset($_FILES["initrd2"]['tmp_name']) &&
196 is_uploaded_file($_FILES["initrd2"]['tmp_name'])) {
197 move_uploaded_file($_FILES["initrd2"]['tmp_name'],
198 $tmp_dir."initrd2");
199 $initrd2_size = $_FILES["initrd2"]['size'];
200 $size += $initrd2_size;
201 $msg = "The total size of the files ".$_FILES["kernel"]['name'].
202 ", ".$_FILES["initrd"]['name'].
203 " and ".$_FILES["initrd2"]['name'];
204 }
205 if ($size >= 15 * 1024 * 1024) {
206 error($msg." exceeds 15 MB.");
207 $size = 0;
208 }
209 if ($size == 0) {
210 if (isset($tmp_dir))
211 system("rm -f $tmp_dir");
212 }
213 else {
214 $cmd = "./bootloader ".$tmp_dir."kernel --prefix "
215 . $tmp_dir."fd --format 0 --flags ".$_POST['flags']
216 . " --video ".$_POST['video'];
217 if ($_POST['cmdline'])
218 $cmd .= " --cmdline '".$_POST['cmdline']."'";
219 if (file_exists($_POST['rdev']))
220 $cmd .= " --rdev ".$_POST['rdev'];
221 if ($initrd_size)
222 $cmd .= " --initrd ".$tmp_dir."initrd";
223 if ($initrd2_size)
224 $cmd .= " --initrd ".$tmp_dir."initrd2";
225 switch ($_POST['size']) {
226 case 1763328 :
227 case 2015232 :
228 case 3526656 :
229 case 4030464 :
230 $cmd .= " --tracks 82"; break;
231 case 1784832 :
232 $cmd .= " --tracks 83"; break;
233 }
234 shell_exec($cmd);
235 $count = 1;
236 if ($_POST['size'] != 0) {
237 $count += (filesize($tmp_dir."fd") -1) / $_POST['size'];
238 $padding = $_POST['size'] -
239 (filesize($tmp_dir."fd") % $_POST['size']);
240 }
241 }
242 $sizes = array(
243 "368640" => "360 KB", "737280" => "720 KB",
244 "1228800" => "1.20 MB",
245 "1474560" => "1.44 MB", "1638400" => "1.60 MB",
246 "1720320" => "1.68 MB", "1763328" => "1.72 MB",
247 "1784832" => "1.74 MB", "1802240" => "1.76 MB",
248 "1884160" => "1.84 MB", "1966080" => "1.92 MB",
249 "2015232" => "1.96 MB", "2949120" => "2.88 MB",
250 "3440640" => "3.36 MB", "3526656" => "3.44 MB",
251 "3932160" => "3.84 MB", "4030464" => "3.92 MB",
252 "0" => "no limit"
253 );
255 function show_size($size)
256 {
257 global $sizes;
258 if ($size != 0) return " ".$sizes[$size];
259 }
260 ?>
262 <!-- End navigation menu -->
263 </div>
265 <!-- Content top. -->
266 <div id="content_top">
267 <div class="top_left"></div>
268 <div class="top_right"></div>
269 </div>
271 <!-- Content -->
272 <div id="content">
274 <h2>Floppy image set builder</h2>
276 <?php
277 if (!isset($count)) {
278 $max = rtrim(ini_get('upload_max_filesize'),"M");
279 $max_post = rtrim(ini_get('post_max_size'),"M");
280 if ($max_post < $max) $max = $max_post;
281 $msg = "the tiny boot loader can't load more than 15 MB";
282 if ($max < 16)
283 $msg = "the web server can't upload more than $max MB";
284 ?>
285 <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
286 <table>
287 <tr>
288 <td>Linux kernel:</td>
289 <td><input type="file" name="kernel" size="25" /> <i>required</i></td>
290 </tr>
291 <tr>
292 <td>Initramfs / Initrd:</td>
293 <td><input type="file" name="initrd" size="25" /> <i>optional</i></td>
294 </tr>
295 <tr>
296 <td>Extra initramfs:</td>
297 <td><input type="file" name="initrd2" size="25" /> <i>optional</i></td>
298 </tr>
299 <tr>
300 <td>Default cmdline:</td>
301 <td><input type="text" name="cmdline" size="36" <?php
302 if (isset($_GET['cmdline'])) echo 'value="'.$_GET['cmdline'].'"';
303 ?>/> <i>optional</i></td>
304 </tr>
305 <tr>
306 <td>Root device:</td>
307 <td><input type="text" name="rdev" size="8" value="<?php
308 if (isset($_GET['rdev'])) echo $_GET['rdev'];
309 else echo "/dev/fd0";
310 ?>" />
311 &nbsp;&nbsp;Root flags: <select name="flags">
312 <option value="1">R/O</option>
313 <option value="0" <?php
314 if (isset($_GET['rdev']) && $_GET['rdev'] == "0")
315 echo ' selected="selected"'
316 ?>>R/W</option>
317 </select>
318 &nbsp;&nbsp;VGA mode: <select name="video">
319 <?php
320 $selected=-1;
321 if (isset($_GET['video'])) $selected = $_GET['video'];
322 $options = array();
323 $options[-3] = "Ask";
324 $options[-2] = "Ext";
325 $options[-1] = "Std";
326 for ($i = 0; $i < 64; $i++) $options[$i] = $i;
327 foreach ($options as $key => $value) {
328 echo '<option value="'.$key.'"';
329 if ($key == $selected || $value == $selected)
330 echo ' selected="selected"';
331 echo '>'.$value."</option>\n";
332 }
333 ?>
334 </select>
335 </td>
336 </tr>
337 <tr>
338 <td>Floppy size:</td>
339 <td><select name="size">
340 <?php
341 foreach ($sizes as $key => $value) {
342 echo " <option value=\"$key\"";
343 if ($key == "1474560") echo " selected='selected'";
344 echo ">$value</option>\n";
345 }
346 ?>
347 </select>
348 <input name="build" value="Build floppy set" type="submit" />
349 </td>
350 </tr>
351 </table>
352 </form>
353 <?php
354 echo <<<EOT
355 <p>
356 Note 1: $msg of files (kernel and initramfs) in memory.
357 </p>
358 <p>
359 Note 2: the extra initramfs may be useful to add your own configuration files.
360 </p>
361 EOT;
362 }
363 else {
364 ?>
365 <h4>Download image<?php if ($count >= 2) echo "s"; ?></h4>
366 <ul>
367 <?php
368 for ($i = 1; $i <= $count; $i++) {
369 echo ' <li><a href="'.$_SERVER["PHP_SELF"].
370 "?id=".basename($tmp_dir)."&amp;n=$i&amp;s=".
371 $_POST["size"].'">'.sprintf("fd%03d.img",$i).
372 show_size($_POST["size"])."</a></li>\n";
373 }
374 echo "</ul>\n".floor($padding/1024)."KB padding.\n";
375 ?>
377 <p>
378 You can write floppies with SliTaz <i>bootfloppybox</i>,
379 <a href="http://en.wikipedia.org/wiki/RaWrite">Windows rawrite</a> or simply dd:
380 </p>
381 <pre># dd if=fd001.img of=/dev/fd0
382 </pre>
384 <p>
385 Start your computer with <i>fd001.img</i>. It will show the kernel version string and
386 the kernel cmdline line. You can edit the cmdline. Most users can just press Enter.
387 </p>
389 <?php
390 if ($count >= 2) {
391 ?>
392 <p>
393 The floppy is then loaded into memory (one dot each 64k) and you will be prompted to
394 insert the next floppy, <i>fd002.img</i>. And so on.
395 </p>
397 <p>
398 The floppy set detects disk swaps and can be used without a keyboard.
399 </p>
400 <?php
401 }
402 ?>
403 <p>
404 Good luck.
405 </p>
406 <?php
407 }
408 ?>
410 <div class="nav_box">
411 <h4>How does it work ?</h4>
412 <p>
413 This tool updates the boot sector of your kernel with
414 <a href="http://hg.slitaz.org/wok/raw-file/b84ff32e3457/linux/stuff/linux-header-2.6.34.u">this patch</a>.
415 You may add a default cmdline and an initramfs. The cmdline can be edited at boot
416 time but the keyboard is not mandatory.
417 A <a href="bootloader"> standalone version</a> is available.
418 </p>
419 <p>
420 Each part (boot, setup, cmdline, kernel, initramfs) is aligned to 512 bytes.
421 The result is split to fit the floppy size.
422 The last floppy image is padded with zeros.
423 </p>
424 </div>
426 <!-- End of content with round corner -->
427 </div>
428 <div id="content_bottom">
429 <div class="bottom_left"></div>
430 <div class="bottom_right"></div>
431 </div>
433 <!-- Start of footer and copy notice -->
434 <div id="copy">
435 <p>
436 Copyright &copy; <?php echo date('Y'); ?> <a href="http://www.slitaz.org/">SliTaz</a> -
437 <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>
438 </p>
439 <!-- End of copy -->
440 </div>
442 <!-- Bottom and logos -->
443 <div id="bottom">
444 <p>
445 <a href="http://validator.w3.org/check?uri=referer"><img src="/static/xhtml10.png" alt="Valid XHTML 1.0" title="Code validé XHTML 1.0" style="width: 80px; height: 15px;" /></a>
446 </p>
447 </div>
449 </body>
450 </html>