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
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');
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);
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);
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);
61 $xlxtyp_vals = array('','XCV300E','XCV400E','XCV600E','XC2V2000','XC2V3000','XC2V4000','XC2V6000');
62 $xlxspd_vals = array('','6','7','8','4','5');
63 $xlxtmp_vals = array('','COM','IND');
64 $xlxgrd_vals = array('','NORMAL','ENGSAMP');
66 // processor attributes
67 $cputyp_vals = array('','MPC8260');
68 $clk_vals = array('','33MHZ','66MHZ','100MHZ','133MHZ','166MHZ','200MHZ');
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');
75 // value filters - used when outputting html
76 function rev_filter($num) {
80 return sprintf("%03d", $num);
83 function text_filter($str) {
84 return urldecode($str);
87 mt_srand(time() | getmypid());
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");
94 function pg_head($title)
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";
101 echo "<center><h1>$title</h1></center>\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@csiro.au\">" .
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";
124 // some support functions
126 if (!function_exists('array_search')) {
128 function array_search($needle, $haystack, $strict = false) {
130 if (is_array($haystack) && count($haystack)) {
132 $ntype = gettype($needle);
134 foreach ($haystack as $key => $value) {
136 if ($value == $needle && (!$strict ||
137 gettype($value) == $ntype))
146 if (!function_exists('in_array')) {
148 function in_array($needle, $haystack, $strict = false) {
150 if (is_array($haystack) && count($haystack)) {
152 $ntype = gettype($needle);
154 foreach ($haystack as $key => $value) {
156 if ($value == $needle && (!$strict ||
157 gettype($value) == $ntype))
166 function key_in_array($key, $array) {
167 return in_array($key, array_keys($array), true);
170 function enum_to_index($name, $vals) {
171 $index = array_search($GLOBALS[$name], $vals);
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))
186 $n = func_num_args();
189 $a = func_get_args();
190 $fp = array_shift($a);
191 $x = "\$s = sprintf";
200 $r = fwrite($fp, $s, $l);
207 // functions to display (print) a database table and its columns
209 function begin_table($ncols) {
211 $table_ncols = $ncols;
212 echo "<table align=center width=\"100%\""
213 . " border=1 cellpadding=4 cols=$table_ncols>\n";
216 function begin_field($name, $span = 0) {
218 echo "<tr valign=top>\n";
219 echo "\t<th align=center>$name</th>\n";
221 $span = $table_ncols - 1;
223 echo "\t<td colspan=$span>\n";
228 function cont_field($span = 1) {
231 echo "\t<td colspan=$span>\n";
236 function end_field() {
241 function end_table() {
245 function print_field($name, $array, $size = 0, $filt='') {
249 if (key_in_array($name, $array))
250 $value = $array[$name];
255 $value = $filt($value);
257 echo "\t\t<input name=$name value=\"$value\"";
259 echo " size=$size maxlength=$size";
265 function print_field_multiline($name, $array, $cols, $rows, $filt='') {
269 if (key_in_array($name, $array))
270 $value = $array[$name];
275 $value = $filt($value);
277 echo "\t\t<textarea name=$name " .
278 "cols=$cols rows=$rows wrap=off>\n";
280 echo "</textarea>\n";
285 // print a mysql ENUM as an html RADIO INPUT
286 function print_enum($name, $array, $vals, $def = -1) {
290 if (key_in_array($name, $array))
291 $chk = array_search($array[$name], $vals, FALSE);
295 $nval = count($vals);
297 for ($i = 0; $i < $nval; $i++) {
305 printf("\t\t<input type=radio name=$name"
306 . " value=\"$val\"%s>$pval</input>\n",
307 $i == $chk ? " checked" : "");
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) {
320 $ncell = $cnt / $grp;
321 $span = ($table_ncols - 1) / $ncell;
323 begin_field($base, $span);
325 $nval = count($vals);
327 for ($i = 0; $i < $cnt; $i++) {
329 if ($i > 0 && ($i % $grp) == 0)
332 $name = sprintf("%s%x", $base, $i);
334 echo "\t\t<select name=$name>\n";
336 if (key_in_array($name, $array))
337 $ai = array_search($array[$name], $vals, FALSE);
339 if (key_in_array($i, $defs))
345 for ($j = 0; $j < $nval; $j++) {
353 printf("\t\t\t<option " .
354 "value=\"%s\"%s>%s</option>\n",
356 $j == $ai ? " selected" : "",
360 echo "\t\t</select>\n";
366 // functions to handle the form input
368 // fetch all the parts of an "enum_multi" into a string suitable
370 function gather_enum_multi_query($base, $cnt) {
374 for ($i = 0; $i < $cnt; $i++) {
376 $name = sprintf("%s%x", $base, $i);
378 if (isset($GLOBALS[$name])) {
379 $retval .= sprintf(", %s='%s'",
380 $name, $GLOBALS[$name]);
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) {
393 for ($i = 0; $i < $cnt; $i++) {
395 $name = sprintf("%s%x", $base, $i);
397 if ($array[$name] != '') {
400 $retval .= $array[$name];
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()) {
413 for ($i = 0; $i < $cnt; $i++) {
415 $name = sprintf("%s%x", $base, $i);
417 if ($GLOBALS[$name] != '') {
420 $index = enum_to_index($name, $vals);
421 if ($xfrm != array())
422 $retval .= $xfrm[$index];
431 // count how many parts of an "enum_multi" are actually set
432 function count_enum_multi($base, $cnt) {
436 for ($i = 0; $i < $cnt; $i++) {
438 $name = sprintf("%s%x", $base, $i);
440 if (isset($GLOBALS[$name]))
447 // ethernet address functions
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 - it is a "locally administered" address). Also, make sure
453 // it is NOT a multicast ethernet address (by setting bit 7 to 0).
454 // e.g. the first byte of all ethernet addresses generated here will
455 // have 2 in the bottom two bits (incidentally, these are the first
456 // two bits transmitted on the wire, since the octets in ethernet
457 // addresses are transmitted LSB first).
459 function gen_eth_addr($serno) {
461 $ethaddr_high = (mt_rand(0, 65535) & 0xfeff) | 0x0200;
462 $ethaddr_low = mt_rand(0, 4294967295);
464 return sprintf("%02lx:%02lx:%02lx:%02lx:%02lx:%02lx",
465 $ethaddr_high >> 8, $ethaddr_high & 0xff,
466 $ethaddr_low >> 24, ($ethaddr_low >> 16) & 0xff,
467 ($ethaddr_low >> 8) & 0xff, $ethaddr_low & 0xff);
470 // check that an ethernet address is valid
471 function eth_addr_is_valid($ethaddr) {
473 $ethbytes = split(':', $ethaddr);
475 if (count($ethbytes) != 6)
478 for ($i = 0; $i < 6; $i++) {
479 $ethbyte = $ethbytes[$i];
480 if (!ereg('^[0-9a-f][0-9a-f]$', $ethbyte))
487 // write a simple eeprom configuration file
488 function write_eeprom_cfg_file() {
490 global $sernos, $nsernos, $bddb_cfgdir, $numerrs, $cfgerrs;
491 global $date, $batch, $type_vals, $rev;
492 global $sdram_vals, $sdram_nbits;
493 global $flash_vals, $flash_nbits;
494 global $zbt_vals, $zbt_nbits;
495 global $xlxtyp_vals, $xlxspd_vals, $xlxtmp_vals, $xlxgrd_vals;
496 global $cputyp, $cputyp_vals, $clk_vals;
497 global $hstype, $hstype_vals, $hschin, $hschout;
502 for ($i = 0; $i < $nsernos; $i++) {
504 $serno = sprintf("%010d", $sernos[$i]);
506 $wfp = @fopen($bddb_cfgdir . "/$serno.cfg", "w");
508 $cfgerrs[$i] = 'file create fail';
512 set_file_buffer($wfp, 0);
514 if (!fprintf($wfp, "serno=%d\n", $sernos[$i])) {
515 $cfgerrs[$i] = 'cfg wr fail (serno)';
521 if (!fprintf($wfp, "date=%s\n", $date)) {
522 $cfgerrs[$i] = 'cfg wr fail (date)';
529 if (!fprintf($wfp, "batch=%s\n", $batch)) {
530 $cfgerrs[$i] = 'cfg wr fail (batch)';
537 $typei = enum_to_index("type", $type_vals);
538 if (!fprintf($wfp, "type=%d\n", $typei)) {
539 $cfgerrs[$i] = 'cfg wr fail (type)';
545 if (!fprintf($wfp, "rev=%d\n", $rev)) {
546 $cfgerrs[$i] = 'cfg wr fail (rev)';
552 $s = gather_enum_multi_write("sdram", 4,
553 $sdram_vals, $sdram_nbits);
555 $b = fprintf($wfp, "sdram=%s\n", $s);
557 $cfgerrs[$i] = 'cfg wr fail (sdram)';
564 $s = gather_enum_multi_write("flash", 4,
565 $flash_vals, $flash_nbits);
567 $b = fprintf($wfp, "flash=%s\n", $s);
569 $cfgerrs[$i] = 'cfg wr fail (flash)';
576 $s = gather_enum_multi_write("zbt", 16,
577 $zbt_vals, $zbt_nbits);
579 $b = fprintf($wfp, "zbt=%s\n", $s);
581 $cfgerrs[$i] = 'cfg wr fail (zbt)';
588 $s = gather_enum_multi_write("xlxtyp", 4, $xlxtyp_vals);
590 $b = fprintf($wfp, "xlxtyp=%s\n", $s);
592 $cfgerrs[$i] = 'cfg wr fail (xlxtyp)';
599 $s = gather_enum_multi_write("xlxspd", 4, $xlxspd_vals);
601 $b = fprintf($wfp, "xlxspd=%s\n", $s);
603 $cfgerrs[$i] = 'cfg wr fail (xlxspd)';
610 $s = gather_enum_multi_write("xlxtmp", 4, $xlxtmp_vals);
612 $b = fprintf($wfp, "xlxtmp=%s\n", $s);
614 $cfgerrs[$i] = 'cfg wr fail (xlxtmp)';
621 $s = gather_enum_multi_write("xlxgrd", 4, $xlxgrd_vals);
623 $b = fprintf($wfp, "xlxgrd=%s\n", $s);
625 $cfgerrs[$i] = 'cfg wr fail (xlxgrd)';
633 $cputypi = enum_to_index("cputyp",$cputyp_vals);
634 $cpuspdi = enum_to_index("cpuspd", $clk_vals);
635 $busspdi = enum_to_index("busspd", $clk_vals);
636 $cpmspdi = enum_to_index("cpmspd", $clk_vals);
637 $b = fprintf($wfp, "cputyp=%d\ncpuspd=%d\n" .
638 "busspd=%d\ncpmspd=%d\n",
639 $cputypi, $cpuspdi, $busspdi, $cpmspdi);
641 $cfgerrs[$i] = 'cfg wr fail (cputyp)';
649 $hstypei = enum_to_index("hstype",$hstype_vals);
650 $b = fprintf($wfp, "hstype=%d\n" .
651 "hschin=%s\nhschout=%s\n",
652 $hstypei, $hschin, $hschout);
654 $cfgerrs[$i] = 'cfg wr fail (hstype)';
662 $cfgerrs[$i] = 'file cls fail';