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

mirror/floppies: ascii only for switch.ch
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Sep 03 18:03:50 2017 +0200 (2017-09-03)
parents 1c207a9e6d0c
children
line source
1 <?php
2 if (false) { // no php support on this mirror !
3 ?>
4 <!DOCTYPE html>
5 <html lang="en">
6 <head>
7 <meta charset="UTF-8">
8 <title>SliTaz Boot Floppies redirection</title>
9 <meta name="description" content="slitaz boot floppies builder redirection">
10 <meta name="robots" content="index, nofollow">
11 <meta name="viewport" content="width=device-width, initial-scale=1">
12 <meta name="author" content="SliTaz Contributors">
13 <meta http-equiv="Refresh" content="0;url=http://mirror1.slitaz.org/floppies/builder/index.php">
14 </head>
15 <body>
16 <script type="text/javascript">
17 window.location.replace('http://mirror1.slitaz.org/floppies/builder/index.php')
18 </script>
19 <noscript>
20 <frameset rows="100%">
21 <frame src="http://mirror1.slitaz.org/floppies/builder/index.php">
22 <noframes>
23 <body>Please follow <a href="http://mirror1.slitaz.org/floppies/builder/index.php
24 ">this link</a>.</body>
25 </noframes>
26 </frameset>
27 </noscript>
28 </body>
29 </html>
30 <?php
31 }
32 ini_set('upload_max_filesize','16M');
33 ini_set('post_max_size','16M');
34 if (isset($_GET['id']) && is_file("/tmp/".$_GET['id']."/fd")) {
36 // Download a floppy image
38 $size = $_GET['s'];
39 if ($size == 0)
40 $size = filesize("/tmp/".$_GET['id']."/fd");
41 header("Content-Type: application/octet-stream");
42 header("Content-Length: ".$size);
43 header("Content-Disposition: attachment; filename=".
44 sprintf("fd%03d.img",$_GET['n']));
45 $cmd = "cat /tmp/".$_GET['id']."/fd";
46 if ($_GET['s'] != 0) {
47 $cmd .= " /dev/zero | dd count=1 bs=".$_GET['s'];
48 if ($_GET['n'] > 1)
49 $cmd .= " skip=".($_GET['n']-1);
50 }
51 echo `$cmd 2> /dev/null`;
52 exit;
53 }
54 ?>
55 <!DOCTYPE html>
56 <html lang="en">
57 <head>
58 <meta charset="UTF-8">
59 <title>SliTaz Boot Floppies</title>
60 <meta name="description" content="slitaz boot floppies builder">
61 <meta name="robots" content="index, nofollow">
62 <meta name="viewport" content="width=device-width, initial-scale=1">
63 <meta name="author" content="SliTaz Contributors">
64 <link rel="shortcut icon" href="../static/favicon.ico">
65 <link rel="stylesheet" href="../static/slitaz.min.css">
66 <style>
67 input[type=text] { width: inherit; }
68 </style>
69 </head>
70 <body>
72 <script>de=document.documentElement;de.className+=(("ontouchstart" in de)?' touch':' no-touch');</script>
74 <header>
75 <h1 id="top"><a href="http://www.slitaz.org/">Boot floppies builder</a></h1>
76 <div class="network">
77 <a href="http://www.slitaz.org/" class="home"></a>
78 <a href="bootloader" title="Build your floppy sets without Internet">Shell builder</a>
79 <a href="../floppy-grub4dos" title="Boot tools">Generic boot floppy</a>
80 </div>
81 </header>
83 <!-- Block -->
84 <div class="block"><div>
86 <!-- Navigation menu -->
88 <?php
90 // Cleanup old sessions
92 $dir = opendir("/tmp");
93 while (($name = readdir($dir)) !== false) {
94 if (preg_match('/^fdbuild/',$name) == 0) continue;
95 if (filemtime("/tmp/$name") > strtotime("-1 hour")) continue;
96 system("rm -rf /tmp/$name");
97 }
98 closedir($dir);
100 function get_long($file, $offset)
101 {
102 $value = 0;
103 if ($fp = fopen($file,"r")) {
104 fseek($fp,$offset,SEEK_SET);
105 for ($i = 0; $i < 32; $i += 8) {
106 $value += ord(fgetc($fp)) << $i;
107 }
108 fclose($fp);
109 }
110 return $value;
111 }
113 function error($string, $title="Error")
114 {
115 echo <<<EOT
116 <nav>
117 <header>$title</header>
118 <p>$string</p>
119 </nav>
120 EOT;
121 }
123 $size = 0;
124 $initrd_size = 0;
125 $info_size = 0;
127 // Upload kernel
129 foreach($_FILES as $data) {
130 $msg="The file ".$data['name']." ";
131 switch ($data["error"]) {
132 case UPLOAD_ERR_INI_SIZE :
133 error($msg."exceeds upload_max_filesize.");
134 break;
135 case UPLOAD_ERR_FORM_SIZE :
136 error($msg."exceeds max_post_size.");
137 break;
138 case UPLOAD_ERR_PARTIAL :
139 error($msg."was only partially uploaded.");
140 break;
141 case UPLOAD_ERR_NO_TMP_DIR :
142 error("Missing a temporary folder.");
143 break;
144 case UPLOAD_ERR_CANT_WRITE :
145 error("Failed to write file to disk.");
146 break;
147 }
148 }
149 if (isset($_FILES["kernel"]['tmp_name']) &&
150 is_uploaded_file($_FILES["kernel"]['tmp_name'])) {
151 $tmp_dir = tempnam('','fdbuild');
152 if (file_exists($tmp_dir)) unlink($tmp_dir);
153 mkdir($tmp_dir);
154 $tmp_dir .= '/';
155 move_uploaded_file($_FILES["kernel"]['tmp_name'],
156 $tmp_dir."kernel");
157 $kernel = $tmp_dir."kernel";
158 $boot_version = get_long($kernel,0x206) & 255;
159 if (get_long($kernel,0x202) != 0x53726448) // 'HdrS' magic
160 $boot_version = 0;
161 $size = get_long($kernel,0x1F4); // syssize paragraphs
162 if ($boot_version < 4) $size &= 0xFFFF; // 16 bits before 2.4
163 $size = ($size + 0xFFF) & 0xFFFF000; // round up to 64K
164 $size <<= 4; // paragraphs -> bytes
165 $msg = "The size of the file ".$_FILES["kernel"]['name'];
166 }
168 if ($size && isset($_FILES["info"]['tmp_name']) &&
169 is_uploaded_file($_FILES["info"]['tmp_name'])) {
170 move_uploaded_file($_FILES["info"]['tmp_name'],
171 $tmp_dir."info");
172 $info_size = $_FILES["info"]['size'];
173 }
175 // Upload initrd
177 if ($size) for ($i = 0; $i < count($_FILES["initrd"]['name']); $i++)
178 if (isset($_FILES["initrd"]['tmp_name'][$i]) &&
179 is_uploaded_file($_FILES["initrd"]['tmp_name'][$i])) {
180 move_uploaded_file($_FILES["initrd"]['tmp_name'][$i],
181 $tmp_dir."initrd.".$i);
182 $initrd_cmd .= " --initrd ".$tmp_dir."initrd.".$i;
183 $initrd_size = $_FILES["initrd"]['size'][$i];
184 $size += $initrd_size;
185 if ($i == 0)
186 $msg = "The total size of the files ".$_FILES["kernel"]['name'].
187 " and ".$_FILES["initrd"]['name'][$i];
188 else $msg .= ", ".$FILE["initrd"]['name'][$i];
189 }
190 if ($initrd_size) for ($i = 0; $i < count($_FILES["initrd2"]['name']); $i++)
191 if (isset($_FILES["initrd2"]['tmp_name'][$i]) &&
192 is_uploaded_file($_FILES["initrd2"]['tmp_name'][$i])) {
193 move_uploaded_file($_FILES["initrd2"]['tmp_name'][$i],
194 $tmp_dir."initrd2.".$i);
195 $initrd2_cmd .= " --initrd ".$tmp_dir."initrd2.".$i;
196 $initrd2_size = $_FILES["initrd2"]['size'][$i];
197 $size += $initrd2_size;
198 $msg .= ", ".$FILE["initrd2"]['name'][$i];
199 }
200 if ($size == 0) {
201 if (isset($tmp_dir))
202 system("rm -f $tmp_dir");
203 }
204 else {
205 $cmd = "./bootloader ".$tmp_dir."kernel --prefix "
206 . $tmp_dir."fd --format 0 --flags ".$_POST['flags']
207 . " --video ".$_POST['video']." --mem ".$_POST['ram'];
208 if ($_POST['edit'] == "")
209 $cmd .= " --dont-edit-cmdline";
210 if ($_POST['cmdline'])
211 $cmd .= " --cmdline '".$_POST['cmdline']."'";
212 if ($info_size)
213 $cmd .= " --info ".$tmp_dir."info";
214 if (file_exists($_POST['rdev']))
215 $cmd .= " --rdev ".$_POST['rdev'];
216 if ($initrd_size)
217 $cmd .= $initrd_cmd;
218 if ($initrd2_size)
219 $cmd .= $initrd2_cmd;
220 switch ($_POST['size']) {
221 case 1763328 :
222 case 2015232 :
223 case 3526656 :
224 case 4030464 :
225 $cmd .= " --tracks 82"; break;
226 case 1784832 :
227 $cmd .= " --tracks 83"; break;
228 }
229 shell_exec($cmd);
230 $count = 1;
231 if ($_POST['size'] != 0) {
232 $count += (filesize($tmp_dir."fd") -1) / $_POST['size'];
233 $padding = $_POST['size'] -
234 (filesize($tmp_dir."fd") % $_POST['size']);
235 }
236 }
237 $sizes = array(
238 "368640" => "360 KB", "737280" => "720 KB",
239 "1228800" => "1.20 MB",
240 "1474560" => "1.44 MB", "1638400" => "1.60 MB",
241 "1720320" => "1.68 MB", "1763328" => "1.72 MB",
242 "1784832" => "1.74 MB", "1802240" => "1.76 MB",
243 "1884160" => "1.84 MB", "1966080" => "1.92 MB",
244 "2015232" => "1.96 MB", "2949120" => "2.88 MB",
245 "3440640" => "3.36 MB", "3526656" => "3.44 MB",
246 "3932160" => "3.84 MB", "4030464" => "3.92 MB",
247 "0" => "no limit"
248 );
250 function show_size($size)
251 {
252 global $sizes;
253 if ($size != 0) return " ".$sizes[$size];
254 }
255 ?>
257 <!-- End navigation menu -->
258 </div></div>
261 <!-- Content -->
262 <main>
264 <h2>Floppy image set builder</h2>
266 <script>
267 if (window.File && window.FileReader && window.FileList && window.Blob) {
268 try {
269 updateHtmlCode();
270 }
271 catch (any) {
272 var element = document.createElement("script");
273 element.src = "clientbuilder.js";
274 element.type = "text/javascript";
275 element.onload = function() {
276 updateHtmlCode();
277 };
278 document.body.appendChild(element);
279 }
280 }
281 </script>
282 <?php
283 if (!isset($count)) {
284 $max = rtrim(ini_get('upload_max_filesize'),"M");
285 $max_post = rtrim(ini_get('post_max_size'),"M");
286 if ($max_post < $max) $max = $max_post;
287 $msg = "the web server can't upload more than $max MB";
288 ?>
289 <form id="io" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
291 <div class="large"><table>
292 <tr>
293 <td>Linux kernel:</td>
294 <td><input type="file" name="kernel" size="37" /> <i>required</i></td>
295 </tr>
296 <tr>
297 <td>Initramfs / Initrd:</td>
298 <td><input type="file" name="initrd[]" size="37" multiple /> <i>optional</i></td>
299 </tr>
300 <tr>
301 <td>Extra initramfs:</td>
302 <td><input type="file" name="initrd2[]" size="37" multiple /> <i>optional</i></td>
303 </tr>
304 <tr>
305 <td>Boot message:</td>
306 <td><input type="file" name="info" size="37" /> <i>optional</i></td>
307 </tr>
308 <tr>
309 <td>Default cmdline:</td>
310 <td id="cmdline"><input type="text" name="cmdline" size="36" <?php
311 if (isset($_GET['cmdline'])) echo 'value="'.$_GET['cmdline'].'"';
312 ?>/> <input type="checkbox" name="edit" checked="checked" />edit
313 <i>optional</i></td>
314 </tr>
315 <tr>
316 <td>Root device:</td>
317 <td><input type="text" name="rdev" size="8" value="<?php
318 if (isset($_GET['rdev'])) echo $_GET['rdev'];
319 else echo "/dev/ram0";
320 ?>" />
321 &nbsp;&nbsp;Flags: <select name="flags">
322 <option value="1">R/O</option>
323 <option value="0" <?php
324 if (isset($_GET['rdev']) && $_GET['rdev'] == "0")
325 echo ' selected="selected"'
326 ?>>R/W</option>
327 </select>
328 &nbsp;&nbsp;VESA: <select name="video">
329 <?php
330 $selected=-1;
331 if (isset($_GET['video'])) $selected = $_GET['video'];
332 $options = array();
333 $options[-3] = "Ask";
334 $options[-2] = "Extended";
335 $options[-1] = "Standard";
336 for ($i = 0; $i < 16; $i++) $options[$i] = $i;
337 $options[0xF00] = "80x25";
338 $options[0xF01] = "80x50";
339 $options[0xF02] = "80x43";
340 $options[0xF03] = "80x28";
341 $options[0xF05] = "80x30";
342 $options[0xF06] = "80x34";
343 $options[0xF07] = "80x60";
344 $options[0x30A] = "132x43";
345 $options[0x309] = "132x25";
346 $options[0x338] = "320x200x8"; // 382?
347 $options[0x30D] = "320x200x15";
348 $options[0x30E] = "320x200x16";
349 $options[0x30F] = "320x200x24";
350 $options[0x320] = "320x200x32";
351 $options[0x332] = "320x240x8"; // 392?
352 $options[0x393] = "320x240x15";
353 $options[0x335] = "320x240x16";// 394?
354 $options[0x395] = "320x240x24";
355 $options[0x396] = "320x240x32";
356 $options[0x333] = "400x300x8";// 3A2?
357 $options[0x3A3] = "400x300x15";
358 $options[0x336] = "400x300x16";// 3A4?
359 $options[0x3A5] = "400x300x24";
360 $options[0x3A6] = "400x300x32";
361 $options[0x334] = "512x384x8";// 3B2?
362 $options[0x3B3] = "512x384x15";
363 $options[0x337] = "512x384x16";// 3B4?
364 $options[0x3B5] = "512x384x24";
365 $options[0x3B6] = "512x384x32";
366 $options[0x3C2] = "640x350x8";
367 $options[0x3C3] = "640x350x15";
368 $options[0x3C4] = "640x350x16";
369 $options[0x3C5] = "640x350x24";
370 $options[0x3C6] = "640x350x32";
371 $options[0x300] = "640x400x8";
372 $options[0x383] = "640x400x15";
373 $options[0x339] = "640x400x16";// 384?
374 $options[0x385] = "640x400x24";
375 $options[0x386] = "640x400x32";
376 $options[0x301] = "640x480x8";
377 $options[0x310] = "640x480x15";
378 $options[0x311] = "640x480x16";
379 $options[0x312] = "640x480x24";
380 $options[0x33A] = "640x480x32";// 321?
381 $options[879] = "800x500x8";
382 $options[880] = "800x500x15";
383 $options[881] = "800x500x16";
384 $options[882] = "800x500x24";
385 $options[883] = "800x500x32";
386 //$options[770] = "800x600x4";
387 $options[0x303] = "800x600x8";
388 $options[0x313] = "800x600x15";
389 $options[0x314] = "800x600x16";
390 $options[0x315] = "800x600x24";
391 $options[0x33B] = "800x600x32";//322?
392 $options[815] = "896x672x8";
393 $options[816] = "896x672x15";
394 $options[817] = "896x672x16";
395 $options[818] = "896x672x24";
396 $options[819] = "896x672x32";
397 $options[874] = "1024x640x8";
398 $options[875] = "1024x640x15";
399 $options[876] = "1024x640x16";
400 $options[877] = "1024x640x24";
401 $options[878] = "1024x640x32";
402 //$options[772] = "1024x768x4";
403 $options[0x305] = "1024x768x8";
404 $options[0x316] = "1024x768x15";
405 $options[0x317] = "1024x768x16";
406 $options[0x318] = "1024x768x24";
407 $options[0x33C] = "1024x768x32";//323?
408 $options[869] = "1152x720x8";
409 $options[870] = "1152x720x15";
410 $options[871] = "1152x720x16";
411 $options[872] = "1152x720x24";
412 $options[873] = "1152x720x32";
413 $options[0x307] = "1280x1024x8";
414 $options[0x319] = "1280x1024x15";
415 $options[0x31A] = "1280x1024x16";
416 $options[0x31B] = "1280x1024x24";
417 $options[0x33D] = "1280x1024x32";
418 $options[835] = "1400x1050x8";
419 $options[837] = "1400x1050x16";
420 $options[838] = "1400x1040x24";
421 $options[864] = "1440x900x8";
422 $options[864] = "1440x900x15";
423 $options[866] = "1440x900x16";
424 $options[867] = "1440x900x24";
425 $options[868] = "1440x900x32";
426 $options[0x330] = "1600x1200x8";
427 $options[0x331] = "1600x1200x16";
428 $options[893] = "1920x1200x8";
429 foreach ($options as $key => $value) {
430 echo '<option value="'.$key.'"';
431 if ($key == $selected || $value == $selected)
432 echo ' selected="selected"';
433 echo '>'.$value."</option>\n";
434 }
435 ?>
436 </select>
437 </td>
438 </tr>
439 <tr>
440 <td>Floppy size:</td>
441 <td><select name="size">
442 <?php
443 foreach ($sizes as $key => $value) {
444 switch ($key) {
445 case "368640" :
446 echo " <optgroup label=\"5&frac14; SD\">\n";
447 break;
448 case "737280" :
449 echo " </optgroup>\n";
450 echo " <optgroup label=\"3&frac12; SD\">\n";
451 break;
452 case "1228800" :
453 echo " </optgroup>\n";
454 echo " <optgroup label=\"5&frac14; HD\">\n";
455 break;
456 case "1474560" :
457 echo " </optgroup>\n";
458 echo " <optgroup label=\"3&frac12; HD\">\n";
459 break;
460 case "2949120" :
461 echo " </optgroup>\n";
462 echo " <optgroup label=\"3&frac12; ED\">\n";
463 break;
464 case "0" :
465 echo " </optgroup>\n";
466 break;
467 }
468 echo " <option value=\"$key\"";
469 if ($key == "1474560") echo " selected='selected'";
470 echo ">$value</option>\n";
471 }
472 ?>
473 </select>&nbsp;
474 RAM used&nbsp;<select name="ram">
475 <?php
476 for ($i = 16; $i >= 4; $i--)
477 echo " <option value=\"$i\">$i MB</option>\n";
478 ?>
479 </select>&nbsp;
480 <input name="build" value="Build floppy set" type="submit" />
481 </td>
482 </tr>
483 </table></div>
484 <?php
485 echo <<<EOT
486 <p id="note1">Note 1: $msg of files (kernel and initramfs) in memory.</p>
488 <p>Note 2: the extra initramfs may be useful to add your own configuration files.</p>
490 <p>Note 3: the keyboard is read for ESC or ENTER on every form feed (ASCII 12) in the boot message.</p>
491 </form>
492 EOT;
493 }
494 else {
495 ?>
497 <h4>Download image<?php if ($count >= 2) echo "s"; ?></h4>
499 <ul>
500 <?php
501 for ($i = 1; $i <= $count; $i++) {
502 echo ' <li><a href="'.$_SERVER["PHP_SELF"].
503 "?id=".basename($tmp_dir)."&amp;n=$i&amp;s=".
504 $_POST["size"].'">'.sprintf("fd%03d.img",$i).
505 show_size($_POST["size"])."</a></li>\n";
506 }
507 echo "</ul>\n".floor($padding/1024)."KB padding.\n";
508 ?>
510 <p>You can write floppies with SliTaz <code>bootfloppybox</code>, <a
511 href="http://en.wikipedia.org/wiki/RaWrite">Windows rawrite</a> or simply
512 <code>dd</code>:</p>
514 <pre># dd if=fd001.img of=/dev/fd0</pre>
516 <p>Start your computer with <tt>fd001.img</tt>. It will show the kernel version
517 string and the kernel cmdline line. You can edit the cmdline. Most users can
518 just press Enter.</p>
520 <?php
521 if ($count >= 2) {
522 ?>
523 <p>The floppy is then loaded into memory (one dot each 64K) and you will be
524 prompted to insert the next floppy, <tt>fd002.img</tt>. And so on.</p>
526 <p>The floppy set detects disk swaps and can be used without a keyboard.</p>
527 <?php
528 }
529 ?>
530 <p>Good luck.</p>
532 <?php
533 }
534 ?>
537 <h3>How does it work?</h3>
539 <p>This tool updates the boot sector of your kernel with <a
540 href="http://hg.slitaz.org/wok/raw-file/13835bce7189/syslinux/stuff/iso2exe/bootloader.S">this
541 code</a>. You may add a default cmdline and an initramfs. The cmdline can be
542 edited at boot time but the <acronym title="Check for disk swap every 5 seconds"
543 >keyboard is not mandatory</acronym>. A <a href="bootloader">standalone
544 version</a> is available to break the web server upload limit.</p>
546 <p>Each part (boot, setup, boot message, cmdline, kernel, initramfs) is aligned
547 to 512 bytes. The result is split to fit the floppy size. The last floppy image
548 is padded with zeros.</p>
550 <p>You can extract the <u>kernel</u>, <u>cmdline</u> and <u>rootfs</u> files
551 with <a href="bootloader" title="./bootloader --extract floppy.*">this tool</a>
552 from the floppy images.</p>
555 <!-- End of content -->
556 </main>
558 <script>
559 function QRCodePNG(str, obj) {
560 try {
561 obj.height = obj.width += 300;
562 return QRCode.generatePNG(str, {ecclevel: 'H'});
563 }
564 catch (any) {
565 var element = document.createElement("script");
566 element.src = "/static/qrcode.min.js";
567 element.type = "text/javascript";
568 element.onload = function() {
569 obj.src = QRCode.generatePNG(str, {ecclevel: 'H'});
570 };
571 document.body.appendChild(element);
572 }
573 }
574 </script>
576 <footer>
577 <div>
578 Copyright &copy; <span class="year"></span>
579 <a href="http://www.slitaz.org/">SliTaz</a>
580 </div>
581 <div>
582 Network:
583 <a href="http://scn.slitaz.org/">Community</a> &middot;
584 <a href="http://doc.slitaz.org/">Doc</a> &middot;
585 <a href="http://forum.slitaz.org/">Forum</a> &middot;
586 <a href="http://pkgs.slitaz.org/">Packages</a> &middot;
587 <a href="http://bugs.slitaz.org">Bugs</a> &middot;
588 <a href="http://hg.slitaz.org/?sort=lastchange">Hg</a>
589 </div>
590 <div>
591 SliTaz @
592 <a href="http://twitter.com/slitaz">Twitter</a> &middot;
593 <a href="http://www.facebook.com/slitaz">Facebook</a> &middot;
594 <a href="http://distrowatch.com/slitaz">Distrowatch</a> &middot;
595 <a href="http://en.wikipedia.org/wiki/SliTaz">Wikipedia</a> &middot;
596 <a href="http://flattr.com/profile/slitaz">Flattr</a>
597 </div>
598 <img src="/static/qr.png" alt="#" onmouseover="this.title = location.href"
599 onclick="this.src = QRCodePNG(location.href, this)"/>
600 </footer>
602 </body>
603 </html>