slitaz-forge view mirror/floppies/builder/index.php @ rev 716

mirror/floppies: multi-format support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jul 23 16:41:12 2021 +0000 (2021-07-23)
parents 418ff926c701
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 <?php
267 if (!isset($count)) {
268 $max = rtrim(ini_get('upload_max_filesize'),"M");
269 $max_post = rtrim(ini_get('post_max_size'),"M");
270 if ($max_post < $max) $max = $max_post;
271 $msg = "the web server can't upload more than $max MB";
272 ?>
273 <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
275 <div class="large"><table>
276 <tr>
277 <td>Linux kernel:</td>
278 <td><input type="file" name="kernel" size="37" /> <i>required</i></td>
279 </tr>
280 <tr>
281 <td>Initramfs / Initrd:</td>
282 <td><input type="file" name="initrd[]" size="37" multiple /> <i>optional</i></td>
283 </tr>
284 <tr>
285 <td>Extra initramfs:</td>
286 <td><input type="file" name="initrd2[]" size="37" multiple /> <i>optional</i></td>
287 </tr>
288 <tr>
289 <td>Boot message:</td>
290 <td><input type="file" name="info" size="37" /> <i>optional</i></td>
291 </tr>
292 <tr>
293 <td>Default cmdline:</td>
294 <td id="cmdline"><input type="text" name="cmdline" size="36" <?php
295 if (isset($_GET['cmdline'])) echo 'value="'.$_GET['cmdline'].'"';
296 ?>/> <input type="checkbox" name="edit" checked="checked" />edit
297 <i>optional</i></td>
298 </tr>
299 <tr>
300 <td>Root device:</td>
301 <td><input type="text" name="rdev" size="8" value="<?php
302 if (isset($_GET['rdev'])) echo $_GET['rdev'];
303 else echo "/dev/ram0";
304 ?>" />
305 &nbsp;&nbsp;Flags: <select name="flags">
306 <option value="1">R/O</option>
307 <option value="0" <?php
308 if (isset($_GET['rdev']) && $_GET['rdev'] == "0")
309 echo ' selected="selected"'
310 ?>>R/W</option>
311 </select>
312 &nbsp;&nbsp;VESA: <select name="video">
313 <?php
314 $selected=-1;
315 if (isset($_GET['video'])) $selected = $_GET['video'];
316 $options = array();
317 $options[-3] = "Ask";
318 $options[-2] = "Extended";
319 $options[-1] = "Standard";
320 for ($i = 0; $i < 16; $i++) $options[$i] = $i;
321 $options[0xF00] = "80x25";
322 $options[0xF01] = "80x50";
323 $options[0xF02] = "80x43";
324 $options[0xF03] = "80x28";
325 $options[0xF05] = "80x30";
326 $options[0xF06] = "80x34";
327 $options[0xF07] = "80x60";
328 $options[0x30A] = "132x43";
329 $options[0x309] = "132x25";
330 $options[0x338] = "320x200x8"; // 382?
331 $options[0x30D] = "320x200x15";
332 $options[0x30E] = "320x200x16";
333 $options[0x30F] = "320x200x24";
334 $options[0x320] = "320x200x32";
335 $options[0x332] = "320x240x8"; // 392?
336 $options[0x393] = "320x240x15";
337 $options[0x335] = "320x240x16";// 394?
338 $options[0x395] = "320x240x24";
339 $options[0x396] = "320x240x32";
340 $options[0x333] = "400x300x8";// 3A2?
341 $options[0x3A3] = "400x300x15";
342 $options[0x336] = "400x300x16";// 3A4?
343 $options[0x3A5] = "400x300x24";
344 $options[0x3A6] = "400x300x32";
345 $options[0x334] = "512x384x8";// 3B2?
346 $options[0x3B3] = "512x384x15";
347 $options[0x337] = "512x384x16";// 3B4?
348 $options[0x3B5] = "512x384x24";
349 $options[0x3B6] = "512x384x32";
350 $options[0x3C2] = "640x350x8";
351 $options[0x3C3] = "640x350x15";
352 $options[0x3C4] = "640x350x16";
353 $options[0x3C5] = "640x350x24";
354 $options[0x3C6] = "640x350x32";
355 $options[0x300] = "640x400x8";
356 $options[0x383] = "640x400x15";
357 $options[0x339] = "640x400x16";// 384?
358 $options[0x385] = "640x400x24";
359 $options[0x386] = "640x400x32";
360 $options[0x301] = "640x480x8";
361 $options[0x310] = "640x480x15";
362 $options[0x311] = "640x480x16";
363 $options[0x312] = "640x480x24";
364 $options[0x33A] = "640x480x32";// 321?
365 $options[879] = "800x500x8";
366 $options[880] = "800x500x15";
367 $options[881] = "800x500x16";
368 $options[882] = "800x500x24";
369 $options[883] = "800x500x32";
370 //$options[770] = "800x600x4";
371 $options[0x303] = "800x600x8";
372 $options[0x313] = "800x600x15";
373 $options[0x314] = "800x600x16";
374 $options[0x315] = "800x600x24";
375 $options[0x33B] = "800x600x32";//322?
376 $options[815] = "896x672x8";
377 $options[816] = "896x672x15";
378 $options[817] = "896x672x16";
379 $options[818] = "896x672x24";
380 $options[819] = "896x672x32";
381 $options[874] = "1024x640x8";
382 $options[875] = "1024x640x15";
383 $options[876] = "1024x640x16";
384 $options[877] = "1024x640x24";
385 $options[878] = "1024x640x32";
386 //$options[772] = "1024x768x4";
387 $options[0x305] = "1024x768x8";
388 $options[0x316] = "1024x768x15";
389 $options[0x317] = "1024x768x16";
390 $options[0x318] = "1024x768x24";
391 $options[0x33C] = "1024x768x32";//323?
392 $options[869] = "1152x720x8";
393 $options[870] = "1152x720x15";
394 $options[871] = "1152x720x16";
395 $options[872] = "1152x720x24";
396 $options[873] = "1152x720x32";
397 $options[0x307] = "1280x1024x8";
398 $options[0x319] = "1280x1024x15";
399 $options[0x31A] = "1280x1024x16";
400 $options[0x31B] = "1280x1024x24";
401 $options[0x33D] = "1280x1024x32";
402 $options[835] = "1400x1050x8";
403 $options[837] = "1400x1050x16";
404 $options[838] = "1400x1040x24";
405 $options[864] = "1440x900x8";
406 $options[864] = "1440x900x15";
407 $options[866] = "1440x900x16";
408 $options[867] = "1440x900x24";
409 $options[868] = "1440x900x32";
410 $options[0x330] = "1600x1200x8";
411 $options[0x331] = "1600x1200x16";
412 $options[893] = "1920x1200x8";
413 foreach ($options as $key => $value) {
414 echo '<option value="'.$key.'"';
415 if ($key == $selected || $value == $selected)
416 echo ' selected="selected"';
417 echo '>'.$value."</option>\n";
418 }
419 ?>
420 </select>
421 </td>
422 </tr>
423 <tr>
424 <td>Floppy size:</td>
425 <td><select name="size">
426 <?php
427 foreach ($sizes as $key => $value) {
428 switch ($key) {
429 case "368640" :
430 echo " <optgroup label=\"5&frac14; SD\">\n";
431 break;
432 case "737280" :
433 echo " </optgroup>\n";
434 echo " <optgroup label=\"3&frac12; SD\">\n";
435 break;
436 case "1228800" :
437 echo " </optgroup>\n";
438 echo " <optgroup label=\"5&frac14; HD\">\n";
439 break;
440 case "1474560" :
441 echo " </optgroup>\n";
442 echo " <optgroup label=\"3&frac12; HD\">\n";
443 break;
444 case "2949120" :
445 echo " </optgroup>\n";
446 echo " <optgroup label=\"3&frac12; ED\">\n";
447 break;
448 case "0" :
449 echo " </optgroup>\n";
450 break;
451 }
452 echo " <option value=\"$key\"";
453 if ($key == "1474560") echo " selected='selected'";
454 echo ">$value</option>\n";
455 }
456 ?>
457 </select>&nbsp;
458 RAM used&nbsp;<select name="ram">
459 <?php
460 for ($i = 16; $i >= 4; $i--)
461 echo " <option value=\"$i\">$i MB</option>\n";
462 ?>
463 </select>&nbsp;
464 <input name="build" value="Build floppy set" type="submit" />
465 </td>
466 </tr>
467 </table></div>
468 </form>
469 <?php
470 echo <<<EOT
471 <p>Note 1: $msg of files (kernel and initramfs) in memory.</p>
473 <p>Note 2: the extra initramfs may be useful to add your own configuration files.</p>
475 <p>Note 3: the keyboard is read for ESC or ENTER on every form feed (ASCII 12) in the boot message.</p>
476 EOT;
477 }
478 else {
479 ?>
481 <h4>Download image<?php if ($count >= 2) echo "s"; ?></h4>
483 <ul>
484 <?php
485 for ($i = 1; $i <= $count; $i++) {
486 echo ' <li><a href="'.$_SERVER["PHP_SELF"].
487 "?id=".basename($tmp_dir)."&amp;n=$i&amp;s=".
488 $_POST["size"].'">'.sprintf("fd%03d.img",$i).
489 show_size($_POST["size"])."</a></li>\n";
490 }
491 echo "</ul>\n".floor($padding/1024)."KB padding.\n";
492 ?>
494 <p>You can write floppies with SliTaz <code>bootfloppybox</code>, <a
495 href="http://en.wikipedia.org/wiki/RaWrite">Windows rawrite</a> or simply
496 <code>dd</code>:</p>
498 <pre># dd if=fd001.img of=/dev/fd0</pre>
500 <p>Start your computer with <tt>fd001.img</tt>. It will show the kernel version
501 string and the kernel cmdline line. You can edit the cmdline. Most users can
502 just press Enter.</p>
504 <?php
505 if ($count >= 2) {
506 ?>
507 <p>The floppy is then loaded into memory (one dot each 64K) and you will be
508 prompted to insert the next floppy, <tt>fd002.img</tt>. And so on.</p>
510 <p>The floppy set detects disk swaps and can be used without a keyboard.</p>
511 <?php
512 }
513 ?>
514 <p>Good luck.</p>
516 <?php
517 }
518 ?>
521 <h3>How does it work?</h3>
523 <p>This tool updates the boot sector of your kernel with <a
524 href="http://hg.slitaz.org/wok/raw-file/13835bce7189/syslinux/stuff/iso2exe/bootloader.S">this
525 code</a>. You may add a default cmdline and an initramfs. The cmdline can be
526 edited at boot time but the <acronym title="Check for disk swap every 5 seconds"
527 >keyboard is not mandatory</acronym>. A <a href="bootloader">standalone
528 version</a> is available to break the web server upload limit.</p>
530 <p>Each part (boot, setup, boot message, cmdline, kernel, initramfs) is aligned
531 to 512 bytes. The result is split to fit the floppy size. The last floppy image
532 is padded with zeros.</p>
534 <p>You can extract the <u>kernel</u>, <u>cmdline</u> and <u>rootfs</u> files
535 with <a href="bootloader" title="./bootloader --extract floppy.*">this tool</a>
536 from the floppy images.</p>
539 <!-- End of content -->
540 </main>
542 <script>
543 function QRCodePNG(str, obj) {
544 try {
545 obj.height = obj.width += 300;
546 return QRCode.generatePNG(str, {ecclevel: 'H'});
547 }
548 catch (any) {
549 var element = document.createElement("script");
550 element.src = "/static/qrcode.min.js";
551 element.type = "text/javascript";
552 element.onload = function() {
553 obj.src = QRCode.generatePNG(str, {ecclevel: 'H'});
554 };
555 document.body.appendChild(element);
556 }
557 }
558 </script>
560 <footer>
561 <div>
562 Copyright © <span class="year"></span>
563 <a href="http://www.slitaz.org/">SliTaz</a>
564 </div>
565 <div>
566 Network:
567 <a href="http://scn.slitaz.org/">Community</a> ·
568 <a href="http://doc.slitaz.org/">Doc</a> ·
569 <a href="http://forum.slitaz.org/">Forum</a> ·
570 <a href="http://pkgs.slitaz.org/">Packages</a> ·
571 <a href="http://bugs.slitaz.org">Bugs</a> ·
572 <a href="http://hg.slitaz.org/?sort=lastchange">Hg</a>
573 </div>
574 <div>
575 SliTaz @
576 <a href="http://twitter.com/slitaz">Twitter</a> ·
577 <a href="http://www.facebook.com/slitaz">Facebook</a> ·
578 <a href="http://distrowatch.com/slitaz">Distrowatch</a> ·
579 <a href="http://en.wikipedia.org/wiki/SliTaz">Wikipedia</a> ·
580 <a href="http://flattr.com/profile/slitaz">Flattr</a>
581 </div>
582 <img src="/static/qr.png" alt="#" onmouseover="this.title = location.href"
583 onclick="this.src = QRCodePNG(location.href, this)"/>
584 </footer>
586 </body>
587 </html>