]> git.ipfire.org Git - people/ms/u-boot.git/blame - tools/bddb/defs.php
Initial revision
[people/ms/u-boot.git] / tools / bddb / defs.php
CommitLineData
fe8c2806
WD
1<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?>
2<?php
3 // (C) Copyright 2001
4 // Murray Jensen <Murray.Jensen@cmst.csiro.au>
5 // CSIRO Manufacturing Science and Technology, Preston Lab
6
7 // contains mysql user id and password - keep secret
8 require("config.php");
9
10 if (isset($logout)) {
11 Header("status: 401 Unauthorized");
12 Header("HTTP/1.0 401 Unauthorized");
13 Header("WWW-authenticate: basic realm=\"$bddb_label\"");
14
15 echo "<html><head><title>" .
16 "Access to '$bddb_label' Denied" .
17 "</title></head>\n";
18 echo "<body bgcolor=#ffffff><br></br><br></br><center><h1>" .
19 "You must be an Authorised User " .
20 "to access the '$bddb_label'" .
21 "</h1>\n</center></body></html>\n";
22 exit;
23 }
24
25 // contents of the various enumerated types - if first item is
26 // empty ('') then the enum is allowed to be null (ie "not null"
27 // is not set on the column)
28
29 // all column names in the database table
30 $columns = array(
31 'serno','ethaddr','date','batch',
32 'type','rev','location','comments',
33 'sdram0','sdram1','sdram2','sdram3',
34 'flash0','flash1','flash2','flash3',
35 'zbt0','zbt1','zbt2','zbt3','zbt4','zbt5','zbt6','zbt7',
36 'zbt8','zbt9','zbta','zbtb','zbtc','zbtd','zbte','zbtf',
37 'xlxtyp0','xlxtyp1','xlxtyp2','xlxtyp3',
38 'xlxspd0','xlxspd1','xlxspd2','xlxspd3',
39 'xlxtmp0','xlxtmp1','xlxtmp2','xlxtmp3',
40 'xlxgrd0','xlxgrd1','xlxgrd2','xlxgrd3',
41 'cputyp','cpuspd','cpmspd','busspd',
42 'hstype','hschin','hschout'
43 );
44
45 // board type
46 $type_vals = array('IO','CLP','DSP','INPUT','ALT-INPUT','DISPLAY');
47
48 // sdram sizes (nbits array is for write into eeprom config file)
49 $sdram_vals = array('','32M','64M','128M','256M');
50 $sdram_nbits = array(0,25,26,27,28);
51
52 // flash sizes (nbits array is for write into eeprom config file)
53 $flash_vals = array('','4M','8M','16M','32M','64M');
54 $flash_nbits = array(0,22,23,24,25,26);
55
56 // zbt ram sizes (nbits array is for write into eeprom config file)
57 $zbt_vals = array('','512K','1M','2M','4M');
58 $zbt_nbits = array(0,19,20,21,22);
59
60 // Xilinx attributes
61 $xlxtyp_vals = array('','XCV300E','XCV400E','XCV600E');
62 $xlxspd_vals = array('','6','7','8');
63 $xlxtmp_vals = array('','COM','IND');
64 $xlxgrd_vals = array('','NORMAL','ENGSAMP');
65
66 // processor attributes
67 $cputyp_vals = array('','MPC8260');
68 $clk_vals = array('','33MHZ','66MHZ','100MHZ','133MHZ','166MHZ','200MHZ');
69
70 // high-speed serial attributes
71 $hstype_vals = array('','AMCC-S2064A');
72 $hschin_vals = array('0','1','2','3','4');
73 $hschout_vals = array('0','1','2','3','4');
74
75 // value filters - used when outputting html
76 function rev_filter($num) {
77 if ($num == 0)
78 return "001";
79 else
80 return sprintf("%03d", $num);
81 }
82
83 function text_filter($str) {
84 return urldecode($str);
85 }
86
87 mt_srand(time() | getmypid());
88
89 // set up MySQL connection
90 mysql_connect("", $mysql_user, $mysql_pw) || die("cannot connect");
91 mysql_select_db($mysql_db) || die("cannot select db");
92
93 // page header
94 function pg_head($title)
95 {
96 echo "<html>\n<head>\n";
97 echo "<link rel=stylesheet href=\"bddb.css\" type=\"text/css\" title=\"style sheet\"></link>\n";
98 echo "<title>$title</title>\n";
99 echo "</head>\n";
100 echo "<body>\n";
101 echo "<center><h1>$title</h1></center>\n";
102 echo "<hr></hr>\n";
103 }
104
105 // page footer
106 function pg_foot()
107 {
108 echo "<hr></hr>\n";
109 echo "<table width=\"100%\"><tr><td align=left>\n<address>" .
110 "If you have any problems, email " .
111 "<a href=\"mailto:Murray.Jensen@cmst.csiro.au\">" .
112 "Murray Jensen" .
113 "</a></address>\n" .
114 "</td><td align=right>\n" .
115 "<a href=\"index.php?logout=true\">logout</a>\n" .
116 "</td></tr></table>\n";
117 echo "<p><small><i>Made with " .
118 "<a href=\"http://kyber.dk/phpMyBuilder/\">" .
119 "Kyber phpMyBuilder</a></i></small></p>\n";
120 echo "</body>\n";
121 echo "</html>\n";
122 }
123
124 // some support functions
125
126 if (!function_exists('array_search')) {
127
128 function array_search($needle, $haystack, $strict = false) {
129
130 if (is_array($haystack) && count($haystack)) {
131
132 $ntype = gettype($needle);
133
134 foreach ($haystack as $key => $value) {
135
136 if ($value == $needle && (!$strict ||
137 gettype($value) == $ntype))
138 return $key;
139 }
140 }
141
142 return false;
143 }
144 }
145
146 if (!function_exists('in_array')) {
147
148 function in_array($needle, $haystack, $strict = false) {
149
150 if (is_array($haystack) && count($haystack)) {
151
152 $ntype = gettype($needle);
153
154 foreach ($haystack as $key => $value) {
155
156 if ($value == $needle && (!$strict ||
157 gettype($value) == $ntype))
158 return true;
159 }
160 }
161
162 return false;
163 }
164 }
165
166 function key_in_array($key, $array) {
167 return in_array($key, array_keys($array), true);
168 }
169
170 function enum_to_index($name, $vals) {
171 $index = array_search($GLOBALS[$name], $vals);
172 if ($vals[0] != '')
173 $index++;
174 return $index;
175 }
176
177 // fetch a value from an array - return empty string is not present
178 function get_key_value($key, $array) {
179 if (key_in_array($key, $array))
180 return $array[$key];
181 else
182 return '';
183 }
184
185 function fprintf() {
186 $n = func_num_args();
187 if ($n < 2)
188 return FALSE;
189 $a = func_get_args();
190 $fp = array_shift($a);
191 $x = "\$s = sprintf";
192 $sep = '(';
193 foreach ($a as $z) {
194 $x .= "$sep'$z'";
195 $sep = ',';
196 }
197 $x .= ');';
198 eval($x);
199 $l = strlen($s);
200 $r = fwrite($fp, $s, $l);
201 if ($r != $l)
202 return FALSE;
203 else
204 return TRUE;
205 }
206
207 // functions to display (print) a database table and its columns
208
209 function begin_table($ncols) {
210 global $table_ncols;
211 $table_ncols = $ncols;
212 echo "<table align=center width=\"100%\""
213 . " border=1 cellpadding=4 cols=$table_ncols>\n";
214 }
215
216 function begin_field($name, $span = 0) {
217 global $table_ncols;
218 echo "<tr valign=top>\n";
219 echo "\t<th align=center>$name</th>\n";
220 if ($span <= 0)
221 $span = $table_ncols - 1;
222 if ($span > 1)
223 echo "\t<td colspan=$span>\n";
224 else
225 echo "\t<td>\n";
226 }
227
228 function cont_field($span = 1) {
229 echo "\t</td>\n";
230 if ($span > 1)
231 echo "\t<td colspan=$span>\n";
232 else
233 echo "\t<td>\n";
234 }
235
236 function end_field() {
237 echo "\t</td>\n";
238 echo "</tr>\n";
239 }
240
241 function end_table() {
242 echo "</table>\n";
243 }
244
245 function print_field($name, $array, $size = 0, $filt='') {
246
247 begin_field($name);
248
249 if (key_in_array($name, $array))
250 $value = $array[$name];
251 else
252 $value = '';
253
254 if ($filt != '')
255 $value = $filt($value);
256
257 echo "\t\t<input name=$name value=\"$value\"";
258 if ($size > 0)
259 echo " size=$size maxlength=$size";
260 echo "></input>\n";
261
262 end_field();
263 }
264
265 function print_field_multiline($name, $array, $cols, $rows, $filt='') {
266
267 begin_field($name);
268
269 if (key_in_array($name, $array))
270 $value = $array[$name];
271 else
272 $value = '';
273
274 if ($filt != '')
275 $value = $filt($value);
276
277 echo "\t\t<textarea name=$name " .
278 "cols=$cols rows=$rows wrap=off>\n";
279 echo "$value";
280 echo "</textarea>\n";
281
282 end_field();
283 }
284
285 // print a mysql ENUM as an html RADIO INPUT
286 function print_enum($name, $array, $vals, $def = -1) {
287
288 begin_field($name);
289
290 if (key_in_array($name, $array))
291 $chk = array_search($array[$name], $vals, FALSE);
292 else
293 $chk = $def;
294
295 $nval = count($vals);
296
297 for ($i = 0; $i < $nval; $i++) {
298
299 $val = $vals[$i];
300 if ($val == '')
301 $pval = "none";
302 else
303 $pval = "$val";
304
305 printf("\t\t<input type=radio name=$name"
306 . " value=\"$val\"%s>$pval</input>\n",
307 $i == $chk ? " checked" : "");
308 }
309
310 end_field();
311 }
312
313 // print a group of mysql ENUMs (e.g. name0,name1,...) as an html SELECT
314 function print_enum_multi($base, $array, $vals, $cnt, $defs, $grp = 0) {
315
316 global $table_ncols;
317
318 if ($grp <= 0)
319 $grp = $cnt;
320 $ncell = $cnt / $grp;
321 $span = ($table_ncols - 1) / $ncell;
322
323 begin_field($base, $span);
324
325 $nval = count($vals);
326
327 for ($i = 0; $i < $cnt; $i++) {
328
329 if ($i > 0 && ($i % $grp) == 0)
330 cont_field($span);
331
332 $name = sprintf("%s%x", $base, $i);
333
334 echo "\t\t<select name=$name>\n";
335
336 if (key_in_array($name, $array))
337 $ai = array_search($array[$name], $vals, FALSE);
338 else {
339 if (key_in_array($i, $defs))
340 $ai = $defs[$i];
341 else
342 $ai = 0;
343 }
344
345 for ($j = 0; $j < $nval; $j++) {
346
347 $val = $vals[$j];
348 if ($val == '')
349 $pval = "&nbsp;";
350 else
351 $pval = "$val";
352
353 printf("\t\t\t<option " .
354 "value=\"%s\"%s>%s</option>\n",
355 $val,
356 $j == $ai ? " selected" : "",
357 $pval);
358 }
359
360 echo "\t\t</select>\n";
361 }
362
363 end_field();
364 }
365
366 // functions to handle the form input
367
368 // fetch all the parts of an "enum_multi" into a string suitable
369 // for a MySQL query
370 function gather_enum_multi_query($base, $cnt) {
371
372 $retval = '';
373
374 for ($i = 0; $i < $cnt; $i++) {
375
376 $name = sprintf("%s%x", $base, $i);
377
378 if (isset($GLOBALS[$name])) {
379 $retval .= sprintf(", %s='%s'",
380 $name, $GLOBALS[$name]);
381 }
382 }
383
384 return $retval;
385 }
386
387 // fetch all the parts of an "enum_multi" into a string suitable
388 // for a display e.g. in an html table cell
389 function gather_enum_multi_print($base, $cnt, $array) {
390
391 $retval = '';
392
393 for ($i = 0; $i < $cnt; $i++) {
394
395 $name = sprintf("%s%x", $base, $i);
396
397 if ($array[$name] != '') {
398 if ($retval != '')
399 $retval .= ',';
400 $retval .= $array[$name];
401 }
402 }
403
404 return $retval;
405 }
406
407 // fetch all the parts of an "enum_multi" into a string suitable
408 // for writing to the eeprom data file
409 function gather_enum_multi_write($base, $cnt, $vals, $xfrm = array()) {
410
411 $retval = '';
412
413 for ($i = 0; $i < $cnt; $i++) {
414
415 $name = sprintf("%s%x", $base, $i);
416
417 if ($GLOBALS[$name] != '') {
418 if ($retval != '')
419 $retval .= ',';
420 $index = enum_to_index($name, $vals);
421 if ($xfrm != array())
422 $retval .= $xfrm[$index];
423 else
424 $retval .= $index;
425 }
426 }
427
428 return $retval;
429 }
430
431 // count how many parts of an "enum_multi" are actually set
432 function count_enum_multi($base, $cnt) {
433
434 $retval = 0;
435
436 for ($i = 0; $i < $cnt; $i++) {
437
438 $name = sprintf("%s%x", $base, $i);
439
440 if (isset($GLOBALS[$name]))
441 $retval++;
442 }
443
444 return $retval;
445 }
446
447 // ethernet address functions
448
449 // generate a (possibly not unique) random vendor ethernet address
450 // (setting bit 6 in the ethernet address - motorola wise i.e. bit 0
451 // is the most significant bit - means it is not an assigned ethernet
452 // address). Also, make sure it is NOT a multicast ethernet address.
453 function gen_eth_addr($serno) {
454
455 $ethaddr_high = (mt_rand(0, 65535) & 0xfeff) | 0x0200;
456 $ethaddr_low = mt_rand(0, 4294967295);
457
458 return sprintf("%02lx:%02lx:%02lx:%02lx:%02lx:%02lx",
459 $ethaddr_high >> 8, $ethaddr_high & 0xff,
460 $ethaddr_low >> 24, ($ethaddr_low >> 16) & 0xff,
461 ($ethaddr_low >> 8) & 0xff, $ethaddr_low & 0xff);
462 }
463
464 // check that an ethernet address is valid
465 function eth_addr_is_valid($ethaddr) {
466
467 $ethbytes = split(':', $ethaddr);
468
469 if (count($ethbytes) != 6)
470 return FALSE;
471
472 for ($i = 0; $i < 6; $i++) {
473 $ethbyte = $ethbytes[$i];
474 if (!ereg('^[0-9a-f][0-9a-f]$', $ethbyte))
475 return FALSE;
476 }
477
478 return TRUE;
479 }
480
481 // write a simple eeprom configuration file
482 function write_eeprom_cfg_file() {
483
484 global $sernos, $nsernos, $bddb_cfgdir, $numerrs, $cfgerrs;
485 global $date, $batch, $type_vals, $rev;
486 global $sdram_vals, $sdram_nbits;
487 global $flash_vals, $flash_nbits;
488 global $zbt_vals, $zbt_nbits;
489 global $xlxtyp_vals, $xlxspd_vals, $xlxtmp_vals, $xlxgrd_vals;
490 global $cputyp, $cputyp_vals, $clk_vals;
491 global $hstype, $hstype_vals, $hschin, $hschout;
492
493 $numerrs = 0;
494 $cfgerrs = array();
495
496 for ($i = 0; $i < $nsernos; $i++) {
497
498 $serno = sprintf("%010d", $sernos[$i]);
499
500 $wfp = @fopen($bddb_cfgdir . "/$serno.cfg", "w");
501 if (!$wfp) {
502 $cfgerrs[$i] = 'file create fail';
503 $numerrs++;
504 continue;
505 }
506 set_file_buffer($wfp, 0);
507
508 if (!fprintf($wfp, "serno=%d\n", $sernos[$i])) {
509 $cfgerrs[$i] = 'cfg wr fail (serno)';
510 fclose($wfp);
511 $numerrs++;
512 continue;
513 }
514
515 if (!fprintf($wfp, "date=%s\n", $date)) {
516 $cfgerrs[$i] = 'cfg wr fail (date)';
517 fclose($wfp);
518 $numerrs++;
519 continue;
520 }
521
522 if ($batch != '') {
523 if (!fprintf($wfp, "batch=%s\n", $batch)) {
524 $cfgerrs[$i] = 'cfg wr fail (batch)';
525 fclose($wfp);
526 $numerrs++;
527 continue;
528 }
529 }
530
531 $typei = enum_to_index("type", $type_vals);
532 if (!fprintf($wfp, "type=%d\n", $typei)) {
533 $cfgerrs[$i] = 'cfg wr fail (type)';
534 fclose($wfp);
535 $numerrs++;
536 continue;
537 }
538
539 if (!fprintf($wfp, "rev=%d\n", $rev)) {
540 $cfgerrs[$i] = 'cfg wr fail (rev)';
541 fclose($wfp);
542 $numerrs++;
543 continue;
544 }
545
546 $s = gather_enum_multi_write("sdram", 4,
547 $sdram_vals, $sdram_nbits);
548 if ($s != '') {
549 $b = fprintf($wfp, "sdram=%s\n", $s);
550 if (!$b) {
551 $cfgerrs[$i] = 'cfg wr fail (sdram)';
552 fclose($wfp);
553 $numerrs++;
554 continue;
555 }
556 }
557
558 $s = gather_enum_multi_write("flash", 4,
559 $flash_vals, $flash_nbits);
560 if ($s != '') {
561 $b = fprintf($wfp, "flash=%s\n", $s);
562 if (!$b) {
563 $cfgerrs[$i] = 'cfg wr fail (flash)';
564 fclose($wfp);
565 $numerrs++;
566 continue;
567 }
568 }
569
570 $s = gather_enum_multi_write("zbt", 16,
571 $zbt_vals, $zbt_nbits);
572 if ($s != '') {
573 $b = fprintf($wfp, "zbt=%s\n", $s);
574 if (!$b) {
575 $cfgerrs[$i] = 'cfg wr fail (zbt)';
576 fclose($wfp);
577 $numerrs++;
578 continue;
579 }
580 }
581
582 $s = gather_enum_multi_write("xlxtyp", 4, $xlxtyp_vals);
583 if ($s != '') {
584 $b = fprintf($wfp, "xlxtyp=%s\n", $s);
585 if (!$b) {
586 $cfgerrs[$i] = 'cfg wr fail (xlxtyp)';
587 fclose($wfp);
588 $numerrs++;
589 continue;
590 }
591 }
592
593 $s = gather_enum_multi_write("xlxspd", 4, $xlxspd_vals);
594 if ($s != '') {
595 $b = fprintf($wfp, "xlxspd=%s\n", $s);
596 if (!$b) {
597 $cfgerrs[$i] = 'cfg wr fail (xlxspd)';
598 fclose($wfp);
599 $numerrs++;
600 continue;
601 }
602 }
603
604 $s = gather_enum_multi_write("xlxtmp", 4, $xlxtmp_vals);
605 if ($s != '') {
606 $b = fprintf($wfp, "xlxtmp=%s\n", $s);
607 if (!$b) {
608 $cfgerrs[$i] = 'cfg wr fail (xlxtmp)';
609 fclose($wfp);
610 $numerrs++;
611 continue;
612 }
613 }
614
615 $s = gather_enum_multi_write("xlxgrd", 4, $xlxgrd_vals);
616 if ($s != '') {
617 $b = fprintf($wfp, "xlxgrd=%s\n", $s);
618 if (!$b) {
619 $cfgerrs[$i] = 'cfg wr fail (xlxgrd)';
620 fclose($wfp);
621 $numerrs++;
622 continue;
623 }
624 }
625
626 if ($cputyp != '') {
627 $cputypi = enum_to_index("cputyp",$cputyp_vals);
628 $cpuspdi = enum_to_index("cpuspd", $clk_vals);
629 $busspdi = enum_to_index("busspd", $clk_vals);
630 $cpmspdi = enum_to_index("cpmspd", $clk_vals);
631 $b = fprintf($wfp, "cputyp=%d\ncpuspd=%d\n" .
632 "busspd=%d\ncpmspd=%d\n",
633 $cputypi, $cpuspdi, $busspdi, $cpmspdi);
634 if (!$b) {
635 $cfgerrs[$i] = 'cfg wr fail (cputyp)';
636 fclose($wfp);
637 $numerrs++;
638 continue;
639 }
640 }
641
642 if ($hstype != '') {
643 $hstypei = enum_to_index("hstype",$hstype_vals);
644 $b = fprintf($wfp, "hstype=%d\n" .
645 "hschin=%s\nhschout=%s\n",
646 $hstypei, $hschin, $hschout);
647 if (!$b) {
648 $cfgerrs[$i] = 'cfg wr fail (hstype)';
649 fclose($wfp);
650 $numerrs++;
651 continue;
652 }
653 }
654
655 if (!fclose($wfp)) {
656 $cfgerrs[$i] = 'file cls fail';
657 $numerrs++;
658 }
659 }
660
661 return $numerrs;
662 }
663?>