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

Update http://floppy.slitaz.org/
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jul 28 11:28:54 2012 +0200 (2012-07-28)
parents 116c7b18fea2
children f87dfeb80d51
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/home.png" alt="[ home ]" /></a>
84 <a href="bootloader" title="Build your floppy sets without Internet">Shell builder</a> |
85 <a href="../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;
132 $info_size = 0;
134 // Upload kernel
136 foreach($_FILES as $data) {
137 $msg="The file ".$data['name']." ";
138 switch ($data["error"]) {
139 case UPLOAD_ERR_INI_SIZE :
140 error($msg."exceeds upload_max_filesize.");
141 break;
142 case UPLOAD_ERR_FORM_SIZE :
143 error($msg."exceeds max_post_size.");
144 break;
145 case UPLOAD_ERR_PARTIAL :
146 error($msg."was only partially uploaded.");
147 break;
148 case UPLOAD_ERR_NO_TMP_DIR :
149 error("Missing a temporary folder.");
150 break;
151 case UPLOAD_ERR_CANT_WRITE :
152 error("Failed to write file to disk.");
153 break;
154 }
155 }
156 if (isset($_FILES["kernel"]['tmp_name']) &&
157 is_uploaded_file($_FILES["kernel"]['tmp_name'])) {
158 $tmp_dir = tempnam('','fdbuild');
159 if (file_exists($tmp_dir)) unlink($tmp_dir);
160 mkdir($tmp_dir);
161 $tmp_dir .= '/';
162 move_uploaded_file($_FILES["kernel"]['tmp_name'],
163 $tmp_dir."kernel");
164 $kernel = $tmp_dir."kernel";
165 $boot_version = get_long($kernel,0x206) & 255;
166 if (get_long($kernel,0x202) != 0x53726448) // 'HdrS' magic
167 $boot_version = 0;
168 $size = get_long($kernel,0x1F4); // syssize paragraphs
169 if ($boot_version < 4) $size &= 0xFFFF; // 16 bits before 2.4
170 $size = ($size + 0xFFF) & 0xFFFF000; // round up to 64K
171 $size <<= 4; // paragraphs -> bytes
172 $msg = "The size of the file ".$_FILES["kernel"]['name'];
173 }
175 if ($size && isset($_FILES["info"]['tmp_name']) &&
176 is_uploaded_file($_FILES["info"]['tmp_name'])) {
177 move_uploaded_file($_FILES["info"]['tmp_name'],
178 $tmp_dir."info");
179 $info_size = $_FILES["info"]['size'];
180 }
182 // Upload initrd
184 if ($size && isset($_FILES["initrd"]['tmp_name']) &&
185 is_uploaded_file($_FILES["initrd"]['tmp_name'])) {
186 move_uploaded_file($_FILES["initrd"]['tmp_name'],
187 $tmp_dir."initrd");
188 $initrd_size = $_FILES["initrd"]['size'];
189 $size += $initrd_size;
190 $msg = "The total size of the files ".$_FILES["kernel"]['name'].
191 " and ".$_FILES["initrd"]['name'];
192 }
193 if ($initrd_size && isset($_FILES["initrd2"]['tmp_name']) &&
194 is_uploaded_file($_FILES["initrd2"]['tmp_name'])) {
195 move_uploaded_file($_FILES["initrd2"]['tmp_name'],
196 $tmp_dir."initrd2");
197 $initrd2_size = $_FILES["initrd2"]['size'];
198 $size += $initrd2_size;
199 $msg = "The total size of the files ".$_FILES["kernel"]['name'].
200 ", ".$_FILES["initrd"]['name'].
201 " and ".$_FILES["initrd2"]['name'];
202 }
203 if ($size >= 15 * 1024 * 1024) {
204 error($msg." exceeds 15 MB.");
205 $size = 0;
206 }
207 if ($size == 0) {
208 if (isset($tmp_dir))
209 system("rm -f $tmp_dir");
210 }
211 else {
212 $cmd = "./bootloader ".$tmp_dir."kernel --prefix "
213 . $tmp_dir."fd --format 0 --flags ".$_POST['flags']
214 . " --video ".$_POST['video']." --mem ".$_POST['ram'];
215 if ($_POST['edit'] == "")
216 $cmd .= " --dont-edit-cmdline";
217 if ($_POST['cmdline'])
218 $cmd .= " --cmdline '".$_POST['cmdline']."'";
219 if ($info_size)
220 $cmd .= " --info ".$tmp_dir."info";
221 if (file_exists($_POST['rdev']))
222 $cmd .= " --rdev ".$_POST['rdev'];
223 if ($initrd_size)
224 $cmd .= " --initrd ".$tmp_dir."initrd";
225 if ($initrd2_size)
226 $cmd .= " --initrd ".$tmp_dir."initrd2";
227 switch ($_POST['size']) {
228 case 1763328 :
229 case 2015232 :
230 case 3526656 :
231 case 4030464 :
232 $cmd .= " --tracks 82"; break;
233 case 1784832 :
234 $cmd .= " --tracks 83"; break;
235 }
236 shell_exec($cmd);
237 $count = 1;
238 if ($_POST['size'] != 0) {
239 $count += (filesize($tmp_dir."fd") -1) / $_POST['size'];
240 $padding = $_POST['size'] -
241 (filesize($tmp_dir."fd") % $_POST['size']);
242 }
243 }
244 $sizes = array(
245 "368640" => "360 KB", "737280" => "720 KB",
246 "1228800" => "1.20 MB",
247 "1474560" => "1.44 MB", "1638400" => "1.60 MB",
248 "1720320" => "1.68 MB", "1763328" => "1.72 MB",
249 "1784832" => "1.74 MB", "1802240" => "1.76 MB",
250 "1884160" => "1.84 MB", "1966080" => "1.92 MB",
251 "2015232" => "1.96 MB", "2949120" => "2.88 MB",
252 "3440640" => "3.36 MB", "3526656" => "3.44 MB",
253 "3932160" => "3.84 MB", "4030464" => "3.92 MB",
254 "0" => "no limit"
255 );
257 function show_size($size)
258 {
259 global $sizes;
260 if ($size != 0) return " ".$sizes[$size];
261 }
262 ?>
264 <!-- End navigation menu -->
265 </div>
267 <!-- Content top. -->
268 <div id="content_top">
269 <div class="top_left"></div>
270 <div class="top_right"></div>
271 </div>
273 <!-- Content -->
274 <div id="content">
276 <h2>Floppy image set builder</h2>
278 <?php
279 if (!isset($count)) {
280 $max = rtrim(ini_get('upload_max_filesize'),"M");
281 $max_post = rtrim(ini_get('post_max_size'),"M");
282 if ($max_post < $max) $max = $max_post;
283 $msg = "the tiny boot loader can't load more than 15 MB";
284 if ($max < 16)
285 $msg = "the web server can't upload more than $max MB";
286 ?>
287 <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
288 <table>
289 <tr>
290 <td>Linux kernel:</td>
291 <td><input type="file" name="kernel" size="37" /> <i>required</i></td>
292 </tr>
293 <tr>
294 <td>Initramfs / Initrd:</td>
295 <td><input type="file" name="initrd" size="37" /> <i>optional</i></td>
296 </tr>
297 <tr>
298 <td>Extra initramfs:</td>
299 <td><input type="file" name="initrd2" size="37" /> <i>optional</i></td>
300 </tr>
301 <tr>
302 <td>Boot message:</td>
303 <td><input type="file" name="info" size="37" /> <i>optional</i></td>
304 </tr>
305 <tr>
306 <td>Default cmdline:</td>
307 <td><input type="text" name="cmdline" size="36" <?php
308 if (isset($_GET['cmdline'])) echo 'value="'.$_GET['cmdline'].'"';
309 ?>/> <input type="checkbox" name="edit" checked="checked" />edit
310 <i>optional</i></td>
311 </tr>
312 <tr>
313 <td>Root device:</td>
314 <td><input type="text" name="rdev" size="8" value="<?php
315 if (isset($_GET['rdev'])) echo $_GET['rdev'];
316 else echo "/dev/fd0";
317 ?>" />
318 &nbsp;&nbsp;Flags: <select name="flags">
319 <option value="1">R/O</option>
320 <option value="0" <?php
321 if (isset($_GET['rdev']) && $_GET['rdev'] == "0")
322 echo ' selected="selected"'
323 ?>>R/W</option>
324 </select>
325 &nbsp;&nbsp;VESA: <select name="video">
326 <?php
327 $selected=-1;
328 if (isset($_GET['video'])) $selected = $_GET['video'];
329 $options = array();
330 $options[-3] = "Ask";
331 $options[-2] = "Extended";
332 $options[-1] = "Standard";
333 for ($i = 0; $i < 16; $i++) $options[$i] = $i;
334 $options[0xF00] = "80x25";
335 $options[0xF01] = "80x50";
336 $options[0xF02] = "80x43";
337 $options[0xF03] = "80x28";
338 $options[0xF05] = "80x30";
339 $options[0xF06] = "80x34";
340 $options[0xF07] = "80x60";
341 $options[0x30A] = "132x43";
342 $options[0x309] = "132x25";
343 $options[0x338] = "320x200x8"; // 382?
344 $options[0x30D] = "320x200x15";
345 $options[0x30E] = "320x200x16";
346 $options[0x30F] = "320x200x24";
347 $options[0x320] = "320x200x32";
348 $options[0x332] = "320x240x8"; // 392?
349 $options[0x393] = "320x240x15";
350 $options[0x335] = "320x240x16";// 394?
351 $options[0x395] = "320x240x24";
352 $options[0x396] = "320x240x32";
353 $options[0x333] = "400x300x8";// 3A2?
354 $options[0x3A3] = "400x300x15";
355 $options[0x336] = "400x300x16";// 3A4?
356 $options[0x3A5] = "400x300x24";
357 $options[0x3A6] = "400x300x32";
358 $options[0x334] = "512x384x8";// 3B2?
359 $options[0x3B3] = "512x384x15";
360 $options[0x337] = "512x384x16";// 3B4?
361 $options[0x3B5] = "512x384x24";
362 $options[0x3B6] = "512x384x32";
363 $options[0x3C2] = "640x350x8";
364 $options[0x3C3] = "640x350x15";
365 $options[0x3C4] = "640x350x16";
366 $options[0x3C5] = "640x350x24";
367 $options[0x3C6] = "640x350x32";
368 $options[0x300] = "640x400x8";
369 $options[0x383] = "640x400x15";
370 $options[0x339] = "640x400x16";// 384?
371 $options[0x385] = "640x400x24";
372 $options[0x386] = "640x400x32";
373 $options[0x301] = "640x480x8";
374 $options[0x310] = "640x480x15";
375 $options[0x311] = "640x480x16";
376 $options[0x312] = "640x480x24";
377 $options[0x33A] = "640x480x32";// 321?
378 //$options[770] = "800x600x4";
379 $options[0x303] = "800x600x8";
380 $options[0x313] = "800x600x15";
381 $options[0x314] = "800x600x16";
382 $options[0x315] = "800x600x24";
383 $options[0x33B] = "800x600x32";//322?
384 //$options[772] = "1024x768x4";
385 $options[0x305] = "1024x768x8";
386 $options[0x316] = "1024x768x15";
387 $options[0x317] = "1024x768x16";
388 $options[0x318] = "1024x768x24";
389 $options[0x33C] = "1024x768x32";//323?
390 $options[0x307] = "1280x1024x8";
391 $options[0x319] = "1280x1024x15";
392 $options[0x31A] = "1280x1024x16";
393 $options[0x31B] = "1280x1024x24";
394 $options[0x33D] = "1280x1024x32";
395 $options[0x330] = "1600x1200x8";
396 $options[0x331] = "1600x1200x16";
397 foreach ($options as $key => $value) {
398 echo '<option value="'.$key.'"';
399 if ($key == $selected || $value == $selected)
400 echo ' selected="selected"';
401 echo '>'.$value."</option>\n";
402 }
403 ?>
404 </select>
405 </td>
406 </tr>
407 <tr>
408 <td>Floppy size:</td>
409 <td><select name="size">
410 <?php
411 foreach ($sizes as $key => $value) {
412 echo " <option value=\"$key\"";
413 if ($key == "1474560") echo " selected='selected'";
414 echo ">$value</option>\n";
415 }
416 ?>
417 </select>&nbsp;
418 RAM used&nbsp;<select name="ram">
419 <?php
420 for ($i = 16; $i >= 4; $i--)
421 echo " <option value=\"$i\">$i MB</option>\n";
422 ?>
423 </select>&nbsp;
424 <input name="build" value="Build floppy set" type="submit" />
425 </td>
426 </tr>
427 </table>
428 </form>
429 <?php
430 echo <<<EOT
431 <p>
432 Note 1: $msg of files (kernel and initramfs) in memory.
433 </p>
434 <p>
435 Note 2: the extra initramfs may be useful to add your own configuration files.
436 </p>
437 <p>
438 Note 3: the keyboard is read for ESC or ENTER on every form feed (ASCII 12) in the boot message.
439 </p>
440 EOT;
441 }
442 else {
443 ?>
444 <h4>Download image<?php if ($count >= 2) echo "s"; ?></h4>
445 <ul>
446 <?php
447 for ($i = 1; $i <= $count; $i++) {
448 echo ' <li><a href="'.$_SERVER["PHP_SELF"].
449 "?id=".basename($tmp_dir)."&amp;n=$i&amp;s=".
450 $_POST["size"].'">'.sprintf("fd%03d.img",$i).
451 show_size($_POST["size"])."</a></li>\n";
452 }
453 echo "</ul>\n".floor($padding/1024)."KB padding.\n";
454 ?>
456 <p>
457 You can write floppies with SliTaz <i>bootfloppybox</i>,
458 <a href="http://en.wikipedia.org/wiki/RaWrite">Windows rawrite</a> or simply dd:
459 </p>
460 <pre># dd if=fd001.img of=/dev/fd0
461 </pre>
463 <p>
464 Start your computer with <i>fd001.img</i>. It will show the kernel version string and
465 the kernel cmdline line. You can edit the cmdline. Most users can just press Enter.
466 </p>
468 <?php
469 if ($count >= 2) {
470 ?>
471 <p>
472 The floppy is then loaded into memory (one dot each 64k) and you will be prompted to
473 insert the next floppy, <i>fd002.img</i>. And so on.
474 </p>
476 <p>
477 The floppy set detects disk swaps and can be used without a keyboard.
478 </p>
479 <?php
480 }
481 ?>
482 <p>
483 Good luck.
484 </p>
485 <?php
486 }
487 ?>
489 <div class="nav_box">
490 <h4>How does it work ?</h4>
491 <p>
492 This tool updates the boot sector of your kernel with
493 <a href="http://hg.slitaz.org/wok/raw-file/66e38bd6a132/linux/stuff/linux-header.u">this patch</a>.
494 You may add a default cmdline and an initramfs. The cmdline can be edited at boot
495 time but the keyboard is not mandatory.
496 A <a href="bootloader"> standalone version</a> is available.
497 </p>
498 <p>
499 Each part (boot, setup, cmdline, kernel, initramfs) is aligned to 512 bytes.
500 The result is split to fit the floppy size.
501 The last floppy image is padded with zeros.
502 </p>
503 <p>
504 You can extract the <u>kernel</u>, <u>cmdline</u> and <u>rootfs</u> files with
505 <a href="../floppies">this tool</a> from the floppy images.
506 </p>
507 </div>
509 <!-- End of content with round corner -->
510 </div>
511 <div id="content_bottom">
512 <div class="bottom_left"></div>
513 <div class="bottom_right"></div>
514 </div>
516 <!-- Start of footer and copy notice -->
517 <div id="copy">
518 <p>
519 Copyright &copy; <?php echo date('Y'); ?> <a href="http://www.slitaz.org/">SliTaz</a> -
520 <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>
521 </p>
522 <!-- End of copy -->
523 </div>
525 <!-- Bottom and logo's -->
526 <div id="bottom">
527 <p>
528 <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>
529 </p>
530 </div>
532 </body>
533 </html>