1 <?php
// php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?>
4 // Murray Jensen <Murray.Jensen@csiro.au>
5 // CSIRO Manufacturing Science and Technology, Preston Lab
7 // contains mysql user id and password - keep secret
10 if (isset($_REQUEST['logout'])) {
11 Header("status: 401 Unauthorized");
12 Header("HTTP/1.0 401 Unauthorized");
13 Header("WWW-authenticate: basic realm=\"$bddb_label\"");
15 echo "<html><head><title>" .
16 "Access to '$bddb_label' Denied" .
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";
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)
29 // all column names in the database table
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'
46 $type_vals = array('IO','CLP','DSP','INPUT','ALT-INPUT','DISPLAY');
49 $xlxtyp_vals = array('','XCV300E','XCV400E','XCV600E','XC2V2000','XC2V3000','XC2V4000','XC2V6000','XC2VP2','XC2VP4','XC2VP7','XC2VP20','XC2VP30','XC2VP50','XC4VFX20','XC4VFX40','XC4VFX60','XC4VFX100','XC4VFX140');
52 $xlxspd_vals = array('','6','7','8','4','5','9','10','11','12');
54 // Xilinx fpga temperatures (commercial or industrial)
55 $xlxtmp_vals = array('','COM','IND');
57 // Xilinx fpga grades (normal or engineering sample)
58 $xlxgrd_vals = array('','NORMAL','ENGSAMP');
61 $cputyp_vals = array('','MPC8260(HIP3)','MPC8260A(HIP4)','MPC8280(HIP7)','MPC8560');
63 // CPU/BUS/CPM clock speeds
64 $clk_vals = array('','33MHZ','66MHZ','100MHZ','133MHZ','166MHZ','200MHZ','233MHZ','266MHZ','300MHZ','333MHZ','366MHZ','400MHZ','433MHZ','466MHZ','500MHZ','533MHZ','566MHZ','600MHZ','633MHZ','666MHZ','700MHZ','733MHZ','766MHZ','800MHZ','833MHZ','866MHZ','900MHZ','933MHZ','966MHZ','1000MHZ','1033MHZ','1066MHZ','1100MHZ','1133MHZ','1166MHZ','1200MHZ','1233MHZ','1266MHZ','1300MHZ','1333MHZ');
66 // sdram sizes (nbits array is for eeprom config file)
67 $sdram_vals = array('','32M','64M','128M','256M','512M','1G','2G','4G');
68 $sdram_nbits = array(0,25,26,27,28,29,30,31,32);
70 // flash sizes (nbits array is for eeprom config file)
71 $flash_vals = array('','4M','8M','16M','32M','64M','128M','256M','512M','1G');
72 $flash_nbits = array(0,22,23,24,25,26,27,28,29,30);
74 // zbt ram sizes (nbits array is for write into eeprom config file)
75 $zbt_vals = array('','512K','1M','2M','4M','8M','16M');
76 $zbt_nbits = array(0,19,20,21,22,23,24);
78 // high-speed serial attributes
79 $hstype_vals = array('','AMCC-S2064A','Xilinx-Rockets');
80 $hschin_vals = array('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16');
81 $hschout_vals = array('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16');
83 // value filters - used when outputting html
84 function rev_filter($num) {
88 return sprintf("%03d", $num);
91 function text_filter($str) {
92 return urldecode($str);
95 mt_srand(time() |
getmypid());
97 // set up MySQL connection
98 mysql_connect("", $mysql_user, $mysql_pw) ||
die("cannot connect");
99 mysql_select_db($mysql_db) ||
die("cannot select db");
102 function pg_head($title)
104 echo "<html>\n<head>\n";
105 echo "<link rel=stylesheet href=\"bddb.css\" type=\"text/css\" title=\"style sheet\"></link>\n";
106 echo "<title>$title</title>\n";
109 echo "<center><h1>$title</h1></center>\n";
117 echo "<table width=\"100%\"><tr><td align=left>\n<address>" .
118 "If you have any problems, email " .
119 "<a href=\"mailto:Murray.Jensen@csiro.au\">" .
122 "</td><td align=right>\n" .
123 "<a href=\"index.php?logout=true\">logout</a>\n" .
124 "</td></tr></table>\n";
125 echo "<p><small><i>Made with " .
126 "<a href=\"http://kyber.dk/phpMyBuilder/\">" .
127 "Kyber phpMyBuilder</a></i></small></p>\n";
132 // some support functions
134 if (!function_exists('array_search')) {
136 function array_search($needle, $haystack, $strict = false) {
138 if (is_array($haystack) && count($haystack)) {
140 $ntype = gettype($needle);
142 foreach ($haystack as $key => $value) {
144 if ($value == $needle && (!$strict ||
145 gettype($value) == $ntype))
154 if (!function_exists('in_array')) {
156 function in_array($needle, $haystack, $strict = false) {
158 if (is_array($haystack) && count($haystack)) {
160 $ntype = gettype($needle);
162 foreach ($haystack as $key => $value) {
164 if ($value == $needle && (!$strict ||
165 gettype($value) == $ntype))
174 function key_in_array($key, $array) {
175 return in_array($key, array_keys($array), true);
178 function enum_to_index($name, $vals) {
179 $index = array_search($GLOBALS[$name], $vals);
185 // fetch a value from an array - return empty string is not present
186 function get_key_value($key, $array) {
187 if (key_in_array($key, $array))
194 $n = func_num_args();
197 $a = func_get_args();
198 $fp = array_shift($a);
199 $x = "\$s = sprintf";
208 $r = fwrite($fp, $s, $l);
215 // functions to display (print) a database table and its columns
217 function begin_table($ncols) {
219 $table_ncols = $ncols;
220 echo "<table align=center width=\"100%\""
221 . " border=1 cellpadding=4 cols=$table_ncols>\n";
224 function begin_field($name, $span = 0) {
226 echo "<tr valign=top>\n";
227 echo "\t<th align=center>$name</th>\n";
229 $span = $table_ncols - 1;
231 echo "\t<td colspan=$span>\n";
236 function cont_field($span = 1) {
239 echo "\t<td colspan=$span>\n";
244 function end_field() {
249 function end_table() {
253 function print_field($name, $array, $size = 0, $filt='') {
257 if (key_in_array($name, $array))
258 $value = $array[$name];
263 $value = $filt($value);
265 echo "\t\t<input name=$name value=\"$value\"";
267 echo " size=$size maxlength=$size";
273 function print_field_multiline($name, $array, $cols, $rows, $filt='') {
277 if (key_in_array($name, $array))
278 $value = $array[$name];
283 $value = $filt($value);
285 echo "\t\t<textarea name=$name " .
286 "cols=$cols rows=$rows wrap=off>\n";
288 echo "</textarea>\n";
293 // print a mysql ENUM as an html RADIO INPUT
294 function print_enum($name, $array, $vals, $def = -1) {
298 if (key_in_array($name, $array))
299 $chk = array_search($array[$name], $vals, FALSE);
303 $nval = count($vals);
305 for ($i = 0; $i < $nval; $i++
) {
313 printf("\t\t<input type=radio name=$name"
314 . " value=\"$val\"%s>$pval</input>\n",
315 $i == $chk ?
" checked" : "");
321 // print a mysql ENUM as an html SELECT INPUT
322 function print_enum_select($name, $array, $vals, $def = -1) {
326 echo "\t\t<select name=$name>\n";
328 if (key_in_array($name, $array))
329 $chk = array_search($array[$name], $vals, FALSE);
333 $nval = count($vals);
335 for ($i = 0; $i < $nval; $i++
) {
343 printf("\t\t\t<option " .
344 "value=\"%s\"%s>%s</option>\n",
345 $val, $i == $chk ?
" selected" : "", $pval);
348 echo "\t\t</select>\n";
353 // print a group of mysql ENUMs (e.g. name0,name1,...) as an html SELECT
354 function print_enum_multi($base, $array, $vals, $cnt, $defs, $grp = 0) {
360 $ncell = $cnt / $grp;
361 $span = ($table_ncols - 1) / $ncell;
363 begin_field($base, $span);
365 $nval = count($vals);
367 for ($i = 0; $i < $cnt; $i++
) {
369 if ($i > 0 && ($i %
$grp) == 0)
372 $name = sprintf("%s%x", $base, $i);
374 echo "\t\t<select name=$name>\n";
376 if (key_in_array($name, $array))
377 $ai = array_search($array[$name], $vals, FALSE);
379 if (key_in_array($i, $defs))
385 for ($j = 0; $j < $nval; $j++
) {
393 printf("\t\t\t<option " .
394 "value=\"%s\"%s>%s</option>\n",
396 $j == $ai ?
" selected" : "",
400 echo "\t\t</select>\n";
406 // functions to handle the form input
408 // fetch all the parts of an "enum_multi" into a string suitable
410 function gather_enum_multi_query($base, $cnt) {
414 for ($i = 0; $i < $cnt; $i++
) {
416 $name = sprintf("%s%x", $base, $i);
418 if (isset($_REQUEST[$name])) {
419 $retval .= sprintf(", %s='%s'",
420 $name, $_REQUEST[$name]);
427 // fetch all the parts of an "enum_multi" into a string suitable
428 // for a display e.g. in an html table cell
429 function gather_enum_multi_print($base, $cnt, $array) {
433 for ($i = 0; $i < $cnt; $i++
) {
435 $name = sprintf("%s%x", $base, $i);
437 if ($array[$name] != '') {
440 $retval .= $array[$name];
447 // fetch all the parts of an "enum_multi" into a string suitable
448 // for writing to the eeprom data file
449 function gather_enum_multi_write($base, $cnt, $vals, $xfrm = array()) {
453 for ($i = 0; $i < $cnt; $i++
) {
455 $name = sprintf("%s%x", $base, $i);
457 if ($GLOBALS[$name] != '') {
460 $index = enum_to_index($name, $vals);
461 if ($xfrm != array())
462 $retval .= $xfrm[$index];
471 // count how many parts of an "enum_multi" are actually set
472 function count_enum_multi($base, $cnt) {
476 for ($i = 0; $i < $cnt; $i++
) {
478 $name = sprintf("%s%x", $base, $i);
480 if (isset($_REQUEST[$name]))
487 // ethernet address functions
489 // generate a (possibly not unique) random vendor ethernet address
490 // (setting bit 6 in the ethernet address - motorola wise i.e. bit 0
491 // is the most significant bit - means it is not an assigned ethernet
492 // address - it is a "locally administered" address). Also, make sure
493 // it is NOT a multicast ethernet address (by setting bit 7 to 0).
494 // e.g. the first byte of all ethernet addresses generated here will
495 // have 2 in the bottom two bits (incidentally, these are the first
496 // two bits transmitted on the wire, since the octets in ethernet
497 // addresses are transmitted LSB first).
499 function gen_eth_addr($serno) {
501 $ethaddr_hgh = (mt_rand(0, 65535) & 0xfeff) |
0x0200;
502 $ethaddr_mid = mt_rand(0, 65535);
503 $ethaddr_low = mt_rand(0, 65535);
505 return sprintf("%02lx:%02lx:%02lx:%02lx:%02lx:%02lx",
506 $ethaddr_hgh >> 8, $ethaddr_hgh & 0xff,
507 $ethaddr_mid >> 8, $ethaddr_mid & 0xff,
508 $ethaddr_low >> 8, $ethaddr_low & 0xff);
511 // check that an ethernet address is valid
512 function eth_addr_is_valid($ethaddr) {
514 $ethbytes = split(':', $ethaddr);
516 if (count($ethbytes) != 6)
519 for ($i = 0; $i < 6; $i++
) {
520 $ethbyte = $ethbytes[$i];
521 if (!ereg('^[0-9a-f][0-9a-f]$', $ethbyte))
528 // write a simple eeprom configuration file
529 function write_eeprom_cfg_file() {
531 global $sernos, $nsernos, $bddb_cfgdir, $numerrs, $cfgerrs;
532 global $date, $batch, $type_vals, $rev;
533 global $sdram_vals, $sdram_nbits;
534 global $flash_vals, $flash_nbits;
535 global $zbt_vals, $zbt_nbits;
536 global $xlxtyp_vals, $xlxspd_vals, $xlxtmp_vals, $xlxgrd_vals;
537 global $cputyp, $cputyp_vals, $clk_vals;
538 global $hstype, $hstype_vals, $hschin, $hschout;
543 for ($i = 0; $i < $nsernos; $i++
) {
545 $serno = sprintf("%010d", $sernos[$i]);
547 $wfp = @fopen
($bddb_cfgdir . "/$serno.cfg", "w");
549 $cfgerrs[$i] = 'file create fail';
553 set_file_buffer($wfp, 0);
555 if (!fprintf($wfp, "serno=%d\n", $sernos[$i])) {
556 $cfgerrs[$i] = 'cfg wr fail (serno)';
562 if (!fprintf($wfp, "date=%s\n", $date)) {
563 $cfgerrs[$i] = 'cfg wr fail (date)';
570 if (!fprintf($wfp, "batch=%s\n", $batch)) {
571 $cfgerrs[$i] = 'cfg wr fail (batch)';
578 $typei = enum_to_index("type", $type_vals);
579 if (!fprintf($wfp, "type=%d\n", $typei)) {
580 $cfgerrs[$i] = 'cfg wr fail (type)';
586 if (!fprintf($wfp, "rev=%d\n", $rev)) {
587 $cfgerrs[$i] = 'cfg wr fail (rev)';
593 $s = gather_enum_multi_write("sdram", 4,
594 $sdram_vals, $sdram_nbits);
596 $b = fprintf($wfp, "sdram=%s\n", $s);
598 $cfgerrs[$i] = 'cfg wr fail (sdram)';
605 $s = gather_enum_multi_write("flash", 4,
606 $flash_vals, $flash_nbits);
608 $b = fprintf($wfp, "flash=%s\n", $s);
610 $cfgerrs[$i] = 'cfg wr fail (flash)';
617 $s = gather_enum_multi_write("zbt", 16,
618 $zbt_vals, $zbt_nbits);
620 $b = fprintf($wfp, "zbt=%s\n", $s);
622 $cfgerrs[$i] = 'cfg wr fail (zbt)';
629 $s = gather_enum_multi_write("xlxtyp", 4, $xlxtyp_vals);
631 $b = fprintf($wfp, "xlxtyp=%s\n", $s);
633 $cfgerrs[$i] = 'cfg wr fail (xlxtyp)';
640 $s = gather_enum_multi_write("xlxspd", 4, $xlxspd_vals);
642 $b = fprintf($wfp, "xlxspd=%s\n", $s);
644 $cfgerrs[$i] = 'cfg wr fail (xlxspd)';
651 $s = gather_enum_multi_write("xlxtmp", 4, $xlxtmp_vals);
653 $b = fprintf($wfp, "xlxtmp=%s\n", $s);
655 $cfgerrs[$i] = 'cfg wr fail (xlxtmp)';
662 $s = gather_enum_multi_write("xlxgrd", 4, $xlxgrd_vals);
664 $b = fprintf($wfp, "xlxgrd=%s\n", $s);
666 $cfgerrs[$i] = 'cfg wr fail (xlxgrd)';
674 $cputypi = enum_to_index("cputyp",$cputyp_vals);
675 $cpuspdi = enum_to_index("cpuspd", $clk_vals);
676 $busspdi = enum_to_index("busspd", $clk_vals);
677 $cpmspdi = enum_to_index("cpmspd", $clk_vals);
678 $b = fprintf($wfp, "cputyp=%d\ncpuspd=%d\n" .
679 "busspd=%d\ncpmspd=%d\n",
680 $cputypi, $cpuspdi, $busspdi, $cpmspdi);
682 $cfgerrs[$i] = 'cfg wr fail (cputyp)';
690 $hstypei = enum_to_index("hstype",$hstype_vals);
691 $b = fprintf($wfp, "hstype=%d\n" .
692 "hschin=%s\nhschout=%s\n",
693 $hstypei, $hschin, $hschout);
695 $cfgerrs[$i] = 'cfg wr fail (hstype)';
703 $cfgerrs[$i] = 'file cls fail';