diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/.gitignore | 1 | ||||
-rw-r--r-- | tools/Makefile | 1 | ||||
-rw-r--r-- | tools/bddb/README | 116 | ||||
-rw-r--r-- | tools/bddb/badsubmit.php | 23 | ||||
-rw-r--r-- | tools/bddb/bddb.css | 207 | ||||
-rw-r--r-- | tools/bddb/brlog.php | 109 | ||||
-rw-r--r-- | tools/bddb/browse.php | 147 | ||||
-rw-r--r-- | tools/bddb/config.php | 16 | ||||
-rw-r--r-- | tools/bddb/create_tables.sql | 90 | ||||
-rw-r--r-- | tools/bddb/defs.php | 710 | ||||
-rw-r--r-- | tools/bddb/dodelete.php | 65 | ||||
-rw-r--r-- | tools/bddb/dodellog.php | 57 | ||||
-rw-r--r-- | tools/bddb/doedit.php | 186 | ||||
-rw-r--r-- | tools/bddb/doedlog.php | 76 | ||||
-rw-r--r-- | tools/bddb/donew.php | 230 | ||||
-rw-r--r-- | tools/bddb/donewlog.php | 86 | ||||
-rw-r--r-- | tools/bddb/edit.php | 131 | ||||
-rw-r--r-- | tools/bddb/edlog.php | 86 | ||||
-rw-r--r-- | tools/bddb/execute.php | 33 | ||||
-rw-r--r-- | tools/bddb/index.php | 38 | ||||
-rw-r--r-- | tools/bddb/new.php | 120 | ||||
-rw-r--r-- | tools/bddb/newlog.php | 54 | ||||
-rw-r--r-- | tools/kwbimage.c | 1061 | ||||
-rw-r--r-- | tools/kwboot.c | 111 | ||||
-rw-r--r-- | tools/socfpgaimage.c | 16 |
25 files changed, 905 insertions, 2865 deletions
diff --git a/tools/.gitignore b/tools/.gitignore index cefe9235e2..e7f0f8ff72 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -1,3 +1,4 @@ +/atmel_pmecc_params /bmp_logo /envcrc /fit_check_sign diff --git a/tools/Makefile b/tools/Makefile index 2b05b202a0..3b95964fd1 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -140,6 +140,7 @@ ubsha1-objs := os_support.o ubsha1.o lib/sha1.o HOSTCFLAGS_ubsha1.o := -pedantic hostprogs-$(CONFIG_KIRKWOOD) += kwboot +hostprogs-$(CONFIG_ARMADA_XP) += kwboot hostprogs-y += proftool hostprogs-$(CONFIG_STATIC_RELA) += relocate-rela diff --git a/tools/bddb/README b/tools/bddb/README deleted file mode 100644 index 9bee59a0fe..0000000000 --- a/tools/bddb/README +++ /dev/null @@ -1,116 +0,0 @@ -Hymod Board Database - -(C) Copyright 2001 -Murray Jensen <Murray.Jensen@csiro.au> -CSIRO Manufacturing Science and Technology, Preston Lab - -25-Jun-01 - -This stuff is a set of PHP/MySQL scripts to implement a custom board -database. It will need *extensive* hacking to modify it to keep the -information about your custom boards that you want, however it is a good -starting point. - -How it is used: - - 1. a board has gone through all the hardware testing etc and is - ready to have the flash programmed for the first time - first you - go to a web page and fill in information about the board in a form - to register it in a database - - 2. the web stuff allocates a (unique) serial number and (optionally) - a (locally administered) ethernet address and stores the information - in a database using the serial number as the key (can do whole - batches of boards in one go and/or use a previously registered board - as defaults for the new board(s)) - - 3. it then creates a file in the tftp area of a server somewhere - containing the board information in a simple text format (one - per serial number) - - 4. all hymod boards have an i2c eeprom, and when U-Boot sees that - the eeprom is unitialised, it prompts for a serial number and - ethernet address (if not set), then transfers the file created - in step 3 from the server and initialises the eeprom from its - contents - -What this means is you can't boot the board until you have allocated a serial -number, but you don't have to type it all twice - you do it once on the web -and the board then finds the info it needs to initialise its eeprom. The -other side of the coin is the reading of the eeprom and how it gets passed -to Linux (or another O/S). - -To see how this is all done for the hymod boards look at the code in the -"board/hymod" directory and in the file "include/asm/hymod.h". Hymod boards -can have a mezzanine card which also have an eeprom that needs allocating, -the same process is used for these as well - just a different i2c address. - -Other forms provide the following functions: - - - browsing the board database - - editing board information (one at a time) - - maintaining/browsing a (simple) per board event log - -You will need: MySQL (I use version 3.23.7-alpha), PHP4 (with MySQL -support enabled) and a web server (I use Apache 1.3.x). - -I originally started by using phpMyBuilder (http://kyber.dk/phpMyBuilder) -but it soon got far more complicated than that could handle (but I left -the copyright messages in there anyway). Most of the code resides in the -common defs.php file, which shouldn't need much alteration - all the work -will be in shaping the front-end php files to your liking. - -Here's a quick summary of what needs doing to use it for your boards: - -1. get phpMyAdmin (http://phpwizard.net/projects/phpMyAdmin/) - it's an - invaluable tool for this sort of stuff (this step is optional of course) - -2. edit "bddb.css" to your taste, if you could be bothered - I have no - idea what is in there or what it does - I copied it from somewhere else - ("user.css" from the phpMyEdit (http://phpmyedit.sourcerforge.net) package, - I think) - I figure one day I'll see what sort of things I can change - in there. - -3. create a mysql database - call it whatever you like - -4. edit "create_tables.sql" and modify the "boards" table schema to - reflect the information you want to keep about your boards. It may or - may not be easier to do this and the next step in phpMyAdmin. Check out - the MySQL documentation at http://www.mysql.com/doc/ in particular the - column types at http://www.mysql.com/doc/C/o/Column_types.html - Note - there is only support for a few data types: - - int - presented as an html text input - char/text - presented as an html text input - date - presented as an html text input - enum - presented as an html radio input - - I also have what I call "enum_multi" which is a set of enums with the - same name, but suffixed with a number e.g. fred0, fred1, fred2. These - are presented as a number of html select's with a single label "fred" - this is useful for board characteristics that have multiple items of - the same type e.g. multiple banks of sdram. - -5. use the "create_tables.sql" file to create the "boards" table in the - database e.g. mysql dbname < create_tables.sql - -6. create a user and password for the web server to log into the MySQL - database with; give this user select, insert and update privileges - to the database created in 3 (and delete, if you want the "delete" - functions in the edit forms to work- I have this turned off). phpMyAdmin - helps in this step. - -7. edit "config.php" and set the variables: $mysql_user, $mysql_pw, $mysql_db, - $bddb_cfgdir and $bddb_label - keep the contents of this file secret - it - contains the web servers username and password (the three $mysql_* vars - are set from the previous step) - -8. edit "defs.php" and a. adjust the various enum value arrays and b. edit - the function "pg_foot()" to remove my email address :-) - -9. do major hacking on the following files: browse.php, doedit.php, donew.php, - edit.php and new.php to reflect your database schema - fortunately the - hacking is fairly straight-forward, but it is boring and time-consuming. - -These notes were written rather hastily - if you find any obvious problems -please let me know. diff --git a/tools/bddb/badsubmit.php b/tools/bddb/badsubmit.php deleted file mode 100644 index 5092a31969..0000000000 --- a/tools/bddb/badsubmit.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - require("defs.php"); - pg_head("$bddb_label - Unknown Submit Type"); -?> -<center> - <font size="+4"> - <b> - The <?php echo "$bddb_label"; ?> form was submitted with an - unknown SUBMIT type <?php echo "(value was '$submit')" ?>. - <br></br> - Perhaps you typed the URL in directly? Click here to go to the - home page of the <a href="index.php"><?php echo "$bddb_label"; ?></a>. - </b> - </font> -</center> -<?php - pg_foot(); -?> diff --git a/tools/bddb/bddb.css b/tools/bddb/bddb.css deleted file mode 100644 index dee2b2ee49..0000000000 --- a/tools/bddb/bddb.css +++ /dev/null @@ -1,207 +0,0 @@ -BODY { - background: #e0ffff; - color: #000000; - font-family: Arial, Verdana, Helvetica; -} -H1 { - font-family: "Copperplate Gothic Bold"; - background: transparent; - color: #993300; - text-align: center; -} -H2, H3, H4, H5 { - background: transparent; - color: #993300; - margin-top: 4%; - text-align: center; -} -Body.Plain Div.Abstract, Body.Plain P.Abstract { - background: #cccc99; - color: #333300; - border: white; - padding: 3%; - font-family: Times, Verdana; -} -TH.Nav { - background: #0000cc; - color: #ff9900; -} -TH.Menu { - background: #3366cc; - color: #ff9900; -} -A:hover { - color: #ff6600; -} -A.Menu:hover { - color: #ff6600; -} -A.HoMe:hover { - color: #ff6600; -} -A.Menu { - background: transparent; - color: #ffcc33; - font-family: Verdana, Helvetica, Arial; - font-size: smaller; - text-decoration: none; -} -A.Menu:visited { - background: transparent; - color: #ffcc99; -} -A.HoMe { - background: transparent; - color: #ffcc33; - font-family: Verdana, Helvetica, Arial; - text-decoration:none; -} -A.HoMe:visited { - background: transparent; - color: #ffcc99; -} -TH.Xmp { - background: #eeeeee; - color: #330066; - font-family: courier; - font-weight: normal; -} -TH.LuT { - background: #cccccc; - color: #000000; -} -TD.LuT { - background: #ffffcc; - color: #000000; - font-size: 85%; -} -TH.Info, TD.Info { - background: #ffffcc; - color: #660000; - font-family: "Comic Sans MS", Cursive, Verdana; - font-size: smaller; -} -Div.Info, P.Info { - background: #ffff99; - color: #990033; - text-align: left; - padding: 2%; - font-family: "Comic Sans MS", Cursive, Verdana; - font-size: 85%; - } -Div.Info A { - background: transparent; - color: #ff6600; -} -.HL { - background: #ffff99; - color: #000000; -} -TD.HL { - background: #ccffff; - color: #000000; -} -Div.Margins { - width: 512px; - text-align: center; -} -TD.Plain { - background: #ffffcc; - color: #000033; -} -.Type { - background: #cccccc; - color: #660000; -} -.Name { - background: #eeeeee; - color: #660000; - vertical-align: top; - text-align: right; -} -.Value { - background: #ffffee; - color: #000066; -} -.Drop { - background: #333366; - color: #ffcc33; - font-family: "Copperplate Gothic Light", Helvetica, Verdana, Arial; -} -A.Button:hover { - color: #ff6600; -} -A.Button { - text-decoration:none; - color: #003366; - background: #ffcc66; -} -.Button { - font-size: 9pt; - text-align: center; - text-decoration:none; - color: #003366; - background: #ffcc66; - margin-bottom: 2pt; - border-top: 2px solid #ffff99; - border-left: 2px solid #ffff99; - border-right: 2px solid #cc9933; - border-bottom: 2px solid #cc9933; - font-family: Verdana, Arial, "Comic Sans MS"; -} -.Banner { - width: 468; - font-size: 12pt; - text-align: center; - text-decoration:none; - color: #003366; - background: #ffcc66; - border-top: 4px solid #ffff99; - border-left: 4px solid #ffff99; - border-right: 4px solid #cc9933; - border-bottom: 4px solid #cc9933; - font-family: Verdana, Arial, "Comic Sans MS"; -} -TD.Nova, Body.Nova { - background: #000000; - font-family: "Times New Roman"; - font-weight: light; - color: #ffcc00; -} -Body.Nova A.Button { - background: gold; - color: #003366; -} -Body.Nova A.Banner { - background: transparent; - color: #003366; -} -Body.Nova A { - background: transparent; - text-decoration:none; - color: #ffd766; -} -Body.Nova H1, Body.Nova H2, Body.Nova H3, Body.Nova H4 { - background: transparent; - color: white; - margin-top: 4%; - text-align: center; - filter: Blur(Add=1, Direction=0, Strength=8); -} -Body.Nova Div.Abstract { - background: #000000; - color: #ffffff; - font-family: Times, Verdana; -} -Body.Nova A.Abstract { - background: transparent; - color: #ffeedd; -} -Body.Nova TH.LuT { - background: black; - color: #ffff99; -} -Body.Nova TD.LuT { - background: navy; - color: #ffff99; -} diff --git a/tools/bddb/brlog.php b/tools/bddb/brlog.php deleted file mode 100644 index fccfbd011c..0000000000 --- a/tools/bddb/brlog.php +++ /dev/null @@ -1,109 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - // list page (hymod_bddb / boards) - - require("defs.php"); - - pg_head("$bddb_label - Browse Board Log"); - - $serno=intval($serno); - if ($serno == 0) - die("serial number not specified or invalid!"); - - function print_cell($str) { - if ($str == '') - $str = ' '; - echo "\t<td>$str</td>\n"; - } -?> -<table align=center border=1 cellpadding=10> -<tr> -<th>serno / edit</th> -<th>ethaddr</th> -<th>date</th> -<th>batch</th> -<th>type</th> -<th>rev</th> -<th>location</th> -</tr> -<?php - $r=mysql_query("select * from boards where serno=$serno"); - - while($row=mysql_fetch_array($r)){ - foreach ($columns as $key) { - if (!key_in_array($key, $row)) - $row[$key] = ''; - } - - echo "<tr>\n"; - print_cell("<a href=\"edit.php?serno=$row[serno]\">$row[serno]</a>"); - print_cell($row['ethaddr']); - print_cell($row['date']); - print_cell($row['batch']); - print_cell($row['type']); - print_cell($row['rev']); - print_cell($row['location']); - echo "</tr>\n"; - } - - mysql_free_result($r); -?> -</table> -<hr></hr> -<p></p> -<?php - $limit=abs(isset($_REQUEST['limit'])?$_REQUEST['limit']:20); - $offset=abs(isset($_REQUEST['offset'])?$_REQUEST['offset']:0); - $lr=mysql_query("select count(*) as n from log where serno=$serno"); - $lrow=mysql_fetch_array($lr); - if($lrow['n']>$limit){ - $preoffset=max(0,$offset-$limit); - $postoffset=$offset+$limit; - echo "<table width=\"100%\">\n<tr align=center>\n"; - printf("<td><%sa href=\"%s?submit=Log&serno=$serno&offset=%d\"><img border=0 alt=\"<\" src=\"/icons/left.gif\"></a></td>\n", $offset>0?"":"no", $PHP_SELF, $preoffset); - printf("<td><%sa href=\"%s?submit=Log&serno=$serno&offset=%d\"><img border=0 alt=\">\" src=\"/icons/right.gif\"></a></td>\n", $postoffset<$lrow['n']?"":"no", $PHP_SELF, $postoffset); - echo "</tr>\n</table>\n"; - } - mysql_free_result($lr); -?> -<table width="100%" border=1 cellpadding=10> -<tr valign=top> -<th>logno / edit</th> -<th>date</th> -<th>who</th> -<th width="70%">details</th> -</tr> -<?php - $r=mysql_query("select * from log where serno=$serno order by logno limit $offset,$limit"); - - while($row=mysql_fetch_array($r)){ - echo "<tr>\n"; - print_cell("<a href=\"edlog.php?serno=$row[serno]&logno=$row[logno]\">$row[logno]</a>"); - print_cell($row['date']); - print_cell($row['who']); - print_cell("<pre>" . urldecode($row['details']) . "</pre>"); - echo "</tr>\n"; - } - - mysql_free_result($r); -?> -</table> -<hr></hr> -<p></p> -<table width="100%"> -<tr> - <td align=center> - <a href="newlog.php?serno=<?php echo "$serno"; ?>">Add to Log</a> - </td> - <td align=center> - <a href="index.php">Back to Start</a> - </td> -</tr> -</table> -<?php - pg_foot(); -?> diff --git a/tools/bddb/browse.php b/tools/bddb/browse.php deleted file mode 100644 index 675dfab749..0000000000 --- a/tools/bddb/browse.php +++ /dev/null @@ -1,147 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - // list page (hymod_bddb / boards) - - require("defs.php"); - - $serno=isset($_REQUEST['serno'])?$_REQUEST['serno']:''; - - $verbose=isset($_REQUEST['verbose'])?intval($_REQUEST['verbose']):0; - - pg_head("$bddb_label - Browse database" . ($verbose?" (verbose)":"")); -?> -<p></p> -<?php - $limit=isset($_REQUEST['limit'])?abs(intval($_REQUEST['limit'])):20; - $offset=isset($_REQUEST['offset'])?abs(intval($_REQUEST['offset'])):0; - - if ($serno == '') { - - $lr=mysql_query("select count(*) as n from boards"); - $lrow=mysql_fetch_array($lr); - - if($lrow['n']>$limit){ - $preoffset=max(0,$offset-$limit); - $postoffset=$offset+$limit; - echo "<table width=\"100%\">\n<tr>\n"; - printf("<td align=left><%sa href=\"%s?submit=Browse&offset=%d&verbose=%d\"><img border=0 alt=\"<\" src=\"/icons/left.gif\"></a></td>\n", $offset>0?"":"no", $PHP_SELF, $preoffset, $verbose); - printf("<td align=right><%sa href=\"%s?submit=Browse&offset=%d&verbose=%d\"><img border=0 alt=\">\" src=\"/icons/right.gif\"></a></td>\n", $postoffset<$lrow['n']?"":"no", $PHP_SELF, $postoffset, $offset); - echo "</tr>\n</table>\n"; - } - - mysql_free_result($lr); - } -?> -<table align=center border=1 cellpadding=10> -<tr> -<th></th> -<th>serno / edit</th> -<th>ethaddr</th> -<th>date</th> -<th>batch</th> -<th>type</th> -<th>rev</th> -<th>location</th> -<?php - if ($verbose) { - echo "<th>comments</th>\n"; - echo "<th>sdram</th>\n"; - echo "<th>flash</th>\n"; - echo "<th>zbt</th>\n"; - echo "<th>xlxtyp</th>\n"; - echo "<th>xlxspd</th>\n"; - echo "<th>xlxtmp</th>\n"; - echo "<th>xlxgrd</th>\n"; - echo "<th>cputyp</th>\n"; - echo "<th>cpuspd</th>\n"; - echo "<th>cpmspd</th>\n"; - echo "<th>busspd</th>\n"; - echo "<th>hstype</th>\n"; - echo "<th>hschin</th>\n"; - echo "<th>hschout</th>\n"; - } -?> -</tr> -<?php - $query = "select * from boards"; - if ($serno != '') { - $pre = " where "; - foreach (preg_split("/[\s,]+/", $serno) as $s) { - if (preg_match('/^[0-9]+$/',$s)) - $query .= $pre . "serno=" . $s; - else if (preg_match('/^([0-9]+)-([0-9]+)$/',$s,$m)) { - $m1 = intval($m[1]); $m2 = intval($m[2]); - if ($m2 <= $m1) - die("bad serial number range ($s)"); - $query .= $pre . "(serno>=$m[1] and serno<=$m[2])"; - } - else - die("illegal serial number ($s)"); - $pre = " or "; - } - } - $query .= " order by serno"; - if ($serno == '') - $query .= " limit $offset,$limit"; - - $r = mysql_query($query); - - function print_cell($str) { - if ($str == '') - $str = ' '; - echo "\t<td>$str</td>\n"; - } - - while($row=mysql_fetch_array($r)){ - foreach ($columns as $key) { - if (!key_in_array($key, $row)) - $row[$key] = ''; - } - - echo "<tr>\n"; - print_cell("<a href=\"brlog.php?serno=$row[serno]\">Log</a>"); - print_cell("<a href=\"edit.php?serno=$row[serno]\">$row[serno]</a>"); - print_cell($row['ethaddr']); - print_cell($row['date']); - print_cell($row['batch']); - print_cell($row['type']); - print_cell($row['rev']); - print_cell($row['location']); - if ($verbose) { - print_cell("<pre>\n" . urldecode($row['comments']) . - "\n\t</pre>"); - print_cell(gather_enum_multi_print("sdram", 4, $row)); - print_cell(gather_enum_multi_print("flash", 4, $row)); - print_cell(gather_enum_multi_print("zbt", 16, $row)); - print_cell(gather_enum_multi_print("xlxtyp", 4, $row)); - print_cell(gather_enum_multi_print("xlxspd", 4, $row)); - print_cell(gather_enum_multi_print("xlxtmp", 4, $row)); - print_cell(gather_enum_multi_print("xlxgrd", 4, $row)); - print_cell($row['cputyp']); - print_cell($row['cpuspd']); - print_cell($row['cpmspd']); - print_cell($row['busspd']); - print_cell($row['hstype']); - print_cell($row['hschin']); - print_cell($row['hschout']); - } - echo "</tr>\n"; - } -?> -</table> -<p></p> -<table width="100%"> -<tr> - <td align=center><?php - printf("<a href=\"%s?submit=Browse&offset=%d&verbose=%d%s\">%s Listing</a>\n", $PHP_SELF, $offset, $verbose?0:1, $serno!=''?"&serno=$serno":'', $verbose?"Terse":"Verbose"); - ?></td> - <td align=center><a href="index.php">Back to Start</a></td> -</tr> -</table> -<?php - pg_foot(); -?> diff --git a/tools/bddb/config.php b/tools/bddb/config.php deleted file mode 100644 index 67257578f0..0000000000 --- a/tools/bddb/config.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - // mysql database access info - $mysql_user="fred"; - $mysql_pw="apassword"; - $mysql_db="mydbname"; - - // where to put the eeprom config files - $bddb_cfgdir = '/tftpboot/bddb'; - - // what this database is called - $bddb_label = 'Hymod Board Database'; -?> diff --git a/tools/bddb/create_tables.sql b/tools/bddb/create_tables.sql deleted file mode 100644 index a2a578867f..0000000000 --- a/tools/bddb/create_tables.sql +++ /dev/null @@ -1,90 +0,0 @@ -# phpMyAdmin MySQL-Dump -# http://phpwizard.net/phpMyAdmin/ -# -# Host: localhost Database : hymod_bddb - -# (C) Copyright 2001 -# Murray Jensen <Murray.Jensen@csiro.au> -# CSIRO Manufacturing and Infrastructure Technology, Preston Lab - -# -------------------------------------------------------- -# -# Table structure for table 'boards' -# - -DROP TABLE IF EXISTS boards; -CREATE TABLE boards ( - serno int(10) unsigned zerofill NOT NULL auto_increment, - ethaddr char(17), - date date NOT NULL, - batch char(32), - type enum('IO','CLP','DSP','INPUT','ALT-INPUT','DISPLAY') NOT NULL, - rev tinyint(3) unsigned zerofill NOT NULL, - location char(64), - comments text, - sdram0 enum('32M','64M','128M','256M','512M','1G','2G','4G'), - sdram1 enum('32M','64M','128M','256M','512M','1G','2G','4G'), - sdram2 enum('32M','64M','128M','256M','512M','1G','2G','4G'), - sdram3 enum('32M','64M','128M','256M','512M','1G','2G','4G'), - flash0 enum('4M','8M','16M','32M','64M','128M','256M','512M','1G'), - flash1 enum('4M','8M','16M','32M','64M','128M','256M','512M','1G'), - flash2 enum('4M','8M','16M','32M','64M','128M','256M','512M','1G'), - flash3 enum('4M','8M','16M','32M','64M','128M','256M','512M','1G'), - zbt0 enum('512K','1M','2M','4M','8M','16M'), - zbt1 enum('512K','1M','2M','4M','8M','16M'), - zbt2 enum('512K','1M','2M','4M','8M','16M'), - zbt3 enum('512K','1M','2M','4M','8M','16M'), - zbt4 enum('512K','1M','2M','4M','8M','16M'), - zbt5 enum('512K','1M','2M','4M','8M','16M'), - zbt6 enum('512K','1M','2M','4M','8M','16M'), - zbt7 enum('512K','1M','2M','4M','8M','16M'), - zbt8 enum('512K','1M','2M','4M','8M','16M'), - zbt9 enum('512K','1M','2M','4M','8M','16M'), - zbta enum('512K','1M','2M','4M','8M','16M'), - zbtb enum('512K','1M','2M','4M','8M','16M'), - zbtc enum('512K','1M','2M','4M','8M','16M'), - zbtd enum('512K','1M','2M','4M','8M','16M'), - zbte enum('512K','1M','2M','4M','8M','16M'), - zbtf enum('512K','1M','2M','4M','8M','16M'), - xlxtyp0 enum('XCV300E','XCV400E','XCV600E','XC2V2000','XC2V3000','XC2V4000','XC2V6000','XC2VP2','XC2VP4','XC2VP7','XC2VP20','XC2VP30','XC2VP50','XC4VFX20','XC4VFX40','XC4VFX60','XC4VFX100','XC4VFX140'), - xlxtyp1 enum('XCV300E','XCV400E','XCV600E','XC2V2000','XC2V3000','XC2V4000','XC2V6000','XC2VP2','XC2VP4','XC2VP7','XC2VP20','XC2VP30','XC2VP50','XC4VFX20','XC4VFX40','XC4VFX60','XC4VFX100','XC4VFX140'), - xlxtyp2 enum('XCV300E','XCV400E','XCV600E','XC2V2000','XC2V3000','XC2V4000','XC2V6000','XC2VP2','XC2VP4','XC2VP7','XC2VP20','XC2VP30','XC2VP50','XC4VFX20','XC4VFX40','XC4VFX60','XC4VFX100','XC4VFX140'), - xlxtyp3 enum('XCV300E','XCV400E','XCV600E','XC2V2000','XC2V3000','XC2V4000','XC2V6000','XC2VP2','XC2VP4','XC2VP7','XC2VP20','XC2VP30','XC2VP50','XC4VFX20','XC4VFX40','XC4VFX60','XC4VFX100','XC4VFX140'), - xlxspd0 enum('6','7','8','4','5','9','10','11','12'), - xlxspd1 enum('6','7','8','4','5','9','10','11','12'), - xlxspd2 enum('6','7','8','4','5','9','10','11','12'), - xlxspd3 enum('6','7','8','4','5','9','10','11','12'), - xlxtmp0 enum('COM','IND'), - xlxtmp1 enum('COM','IND'), - xlxtmp2 enum('COM','IND'), - xlxtmp3 enum('COM','IND'), - xlxgrd0 enum('NORMAL','ENGSAMP'), - xlxgrd1 enum('NORMAL','ENGSAMP'), - xlxgrd2 enum('NORMAL','ENGSAMP'), - xlxgrd3 enum('NORMAL','ENGSAMP'), - cputyp enum('MPC8260(HIP3)','MPC8260A(HIP4)','MPC8280(HIP7)','MPC8560'), - cpuspd enum('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'), - cpmspd enum('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'), - busspd enum('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'), - hstype enum('AMCC-S2064A','Xilinx-Rockets'), - hschin enum('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16'), - hschout enum('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16'), - PRIMARY KEY (serno), - KEY serno (serno), - UNIQUE serno_2 (serno) -); - -# -# Table structure for table 'log' -# - -DROP TABLE IF EXISTS log; -CREATE TABLE log ( - logno int(10) unsigned zerofill NOT NULL auto_increment, - serno int(10) unsigned zerofill NOT NULL, - date date NOT NULL, - details text NOT NULL, - PRIMARY KEY (logno), - KEY logno (logno, serno, date), - UNIQUE logno_2 (logno) -); diff --git a/tools/bddb/defs.php b/tools/bddb/defs.php deleted file mode 100644 index 0b50602823..0000000000 --- a/tools/bddb/defs.php +++ /dev/null @@ -1,710 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - // contains mysql user id and password - keep secret - require("config.php"); - - if (isset($_REQUEST['logout'])) { - Header("status: 401 Unauthorized"); - Header("HTTP/1.0 401 Unauthorized"); - Header("WWW-authenticate: basic realm=\"$bddb_label\""); - - echo "<html><head><title>" . - "Access to '$bddb_label' Denied" . - "</title></head>\n"; - echo "<body bgcolor=#ffffff><br></br><br></br><center><h1>" . - "You must be an Authorised User " . - "to access the '$bddb_label'" . - "</h1>\n</center></body></html>\n"; - exit; - } - - // contents of the various enumerated types - if first item is - // empty ('') then the enum is allowed to be null (ie "not null" - // is not set on the column) - - // all column names in the database table - $columns = array( - 'serno','ethaddr','date','batch', - 'type','rev','location','comments', - 'sdram0','sdram1','sdram2','sdram3', - 'flash0','flash1','flash2','flash3', - 'zbt0','zbt1','zbt2','zbt3','zbt4','zbt5','zbt6','zbt7', - 'zbt8','zbt9','zbta','zbtb','zbtc','zbtd','zbte','zbtf', - 'xlxtyp0','xlxtyp1','xlxtyp2','xlxtyp3', - 'xlxspd0','xlxspd1','xlxspd2','xlxspd3', - 'xlxtmp0','xlxtmp1','xlxtmp2','xlxtmp3', - 'xlxgrd0','xlxgrd1','xlxgrd2','xlxgrd3', - 'cputyp','cpuspd','cpmspd','busspd', - 'hstype','hschin','hschout' - ); - - // board type - $type_vals = array('IO','CLP','DSP','INPUT','ALT-INPUT','DISPLAY'); - - // Xilinx fpga types - $xlxtyp_vals = array('','XCV300E','XCV400E','XCV600E','XC2V2000','XC2V3000','XC2V4000','XC2V6000','XC2VP2','XC2VP4','XC2VP7','XC2VP20','XC2VP30','XC2VP50','XC4VFX20','XC4VFX40','XC4VFX60','XC4VFX100','XC4VFX140'); - - // Xilinx fpga speeds - $xlxspd_vals = array('','6','7','8','4','5','9','10','11','12'); - - // Xilinx fpga temperatures (commercial or industrial) - $xlxtmp_vals = array('','COM','IND'); - - // Xilinx fpga grades (normal or engineering sample) - $xlxgrd_vals = array('','NORMAL','ENGSAMP'); - - // CPU types - $cputyp_vals = array('','MPC8260(HIP3)','MPC8260A(HIP4)','MPC8280(HIP7)','MPC8560'); - - // CPU/BUS/CPM clock speeds - $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'); - - // sdram sizes (nbits array is for eeprom config file) - $sdram_vals = array('','32M','64M','128M','256M','512M','1G','2G','4G'); - $sdram_nbits = array(0,25,26,27,28,29,30,31,32); - - // flash sizes (nbits array is for eeprom config file) - $flash_vals = array('','4M','8M','16M','32M','64M','128M','256M','512M','1G'); - $flash_nbits = array(0,22,23,24,25,26,27,28,29,30); - - // zbt ram sizes (nbits array is for write into eeprom config file) - $zbt_vals = array('','512K','1M','2M','4M','8M','16M'); - $zbt_nbits = array(0,19,20,21,22,23,24); - - // high-speed serial attributes - $hstype_vals = array('','AMCC-S2064A','Xilinx-Rockets'); - $hschin_vals = array('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16'); - $hschout_vals = array('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16'); - - // value filters - used when outputting html - function rev_filter($num) { - if ($num == 0) - return "001"; - else - return sprintf("%03d", $num); - } - - function text_filter($str) { - return urldecode($str); - } - - mt_srand(time() | getmypid()); - - // set up MySQL connection - mysql_connect("", $mysql_user, $mysql_pw) || die("cannot connect"); - mysql_select_db($mysql_db) || die("cannot select db"); - - // page header - function pg_head($title) - { - echo "<html>\n<head>\n"; - echo "<link rel=stylesheet href=\"bddb.css\" type=\"text/css\" title=\"style sheet\"></link>\n"; - echo "<title>$title</title>\n"; - echo "</head>\n"; - echo "<body>\n"; - echo "<center><h1>$title</h1></center>\n"; - echo "<hr></hr>\n"; - } - - // page footer - function pg_foot() - { - echo "<hr></hr>\n"; - echo "<table width=\"100%\"><tr><td align=left>\n<address>" . - "If you have any problems, email " . - "<a href=\"mailto:Murray.Jensen@csiro.au\">" . - "Murray Jensen" . - "</a></address>\n" . - "</td><td align=right>\n" . - "<a href=\"index.php?logout=true\">logout</a>\n" . - "</td></tr></table>\n"; - echo "<p><small><i>Made with " . - "<a href=\"http://kyber.dk/phpMyBuilder/\">" . - "Kyber phpMyBuilder</a></i></small></p>\n"; - echo "</body>\n"; - echo "</html>\n"; - } - - // some support functions - - if (!function_exists('array_search')) { - - function array_search($needle, $haystack, $strict = false) { - - if (is_array($haystack) && count($haystack)) { - - $ntype = gettype($needle); - - foreach ($haystack as $key => $value) { - - if ($value == $needle && (!$strict || - gettype($value) == $ntype)) - return $key; - } - } - - return false; - } - } - - if (!function_exists('in_array')) { - - function in_array($needle, $haystack, $strict = false) { - - if (is_array($haystack) && count($haystack)) { - - $ntype = gettype($needle); - - foreach ($haystack as $key => $value) { - - if ($value == $needle && (!$strict || - gettype($value) == $ntype)) - return true; - } - } - - return false; - } - } - - function key_in_array($key, $array) { - return in_array($key, array_keys($array), true); - } - - function enum_to_index($name, $vals) { - $index = array_search($GLOBALS[$name], $vals); - if ($vals[0] != '') - $index++; - return $index; - } - - // fetch a value from an array - return empty string is not present - function get_key_value($key, $array) { - if (key_in_array($key, $array)) - return $array[$key]; - else - return ''; - } - - function fprintf() { - $n = func_num_args(); - if ($n < 2) - return FALSE; - $a = func_get_args(); - $fp = array_shift($a); - $x = "\$s = sprintf"; - $sep = '('; - foreach ($a as $z) { - $x .= "$sep'$z'"; - $sep = ','; - } - $x .= ');'; - eval($x); - $l = strlen($s); - $r = fwrite($fp, $s, $l); - if ($r != $l) - return FALSE; - else - return TRUE; - } - - // functions to display (print) a database table and its columns - - function begin_table($ncols) { - global $table_ncols; - $table_ncols = $ncols; - echo "<table align=center width=\"100%\"" - . " border=1 cellpadding=4 cols=$table_ncols>\n"; - } - - function begin_field($name, $span = 0) { - global $table_ncols; - echo "<tr valign=top>\n"; - echo "\t<th align=center>$name</th>\n"; - if ($span <= 0) - $span = $table_ncols - 1; - if ($span > 1) - echo "\t<td colspan=$span>\n"; - else - echo "\t<td>\n"; - } - - function cont_field($span = 1) { - echo "\t</td>\n"; - if ($span > 1) - echo "\t<td colspan=$span>\n"; - else - echo "\t<td>\n"; - } - - function end_field() { - echo "\t</td>\n"; - echo "</tr>\n"; - } - - function end_table() { - echo "</table>\n"; - } - - function print_field($name, $array, $size = 0, $filt='') { - - begin_field($name); - - if (key_in_array($name, $array)) - $value = $array[$name]; - else - $value = ''; - - if ($filt != '') - $value = $filt($value); - - echo "\t\t<input name=$name value=\"$value\""; - if ($size > 0) - echo " size=$size maxlength=$size"; - echo "></input>\n"; - - end_field(); - } - - function print_field_multiline($name, $array, $cols, $rows, $filt='') { - - begin_field($name); - - if (key_in_array($name, $array)) - $value = $array[$name]; - else - $value = ''; - - if ($filt != '') - $value = $filt($value); - - echo "\t\t<textarea name=$name " . - "cols=$cols rows=$rows wrap=off>\n"; - echo "$value"; - echo "</textarea>\n"; - - end_field(); - } - - // print a mysql ENUM as an html RADIO INPUT - function print_enum($name, $array, $vals, $def = -1) { - - begin_field($name); - - if (key_in_array($name, $array)) - $chk = array_search($array[$name], $vals, FALSE); - else - $chk = $def; - - $nval = count($vals); - - for ($i = 0; $i < $nval; $i++) { - - $val = $vals[$i]; - if ($val == '') - $pval = "none"; - else - $pval = "$val"; - - printf("\t\t<input type=radio name=$name" - . " value=\"$val\"%s>$pval</input>\n", - $i == $chk ? " checked" : ""); - } - - end_field(); - } - - // print a mysql ENUM as an html SELECT INPUT - function print_enum_select($name, $array, $vals, $def = -1) { - - begin_field($name); - - echo "\t\t<select name=$name>\n"; - - if (key_in_array($name, $array)) - $chk = array_search($array[$name], $vals, FALSE); - else - $chk = $def; - - $nval = count($vals); - - for ($i = 0; $i < $nval; $i++) { - - $val = $vals[$i]; - if ($val == '') - $pval = "none"; - else - $pval = "$val"; - - printf("\t\t\t<option " . - "value=\"%s\"%s>%s</option>\n", - $val, $i == $chk ? " selected" : "", $pval); - } - - echo "\t\t</select>\n"; - - end_field(); - } - - // print a group of mysql ENUMs (e.g. name0,name1,...) as an html SELECT - function print_enum_multi($base, $array, $vals, $cnt, $defs, $grp = 0) { - - global $table_ncols; - - if ($grp <= 0) - $grp = $cnt; - $ncell = $cnt / $grp; - $span = ($table_ncols - 1) / $ncell; - - begin_field($base, $span); - - $nval = count($vals); - - for ($i = 0; $i < $cnt; $i++) { - - if ($i > 0 && ($i % $grp) == 0) - cont_field($span); - - $name = sprintf("%s%x", $base, $i); - - echo "\t\t<select name=$name>\n"; - - if (key_in_array($name, $array)) - $ai = array_search($array[$name], $vals, FALSE); - else { - if (key_in_array($i, $defs)) - $ai = $defs[$i]; - else - $ai = 0; - } - - for ($j = 0; $j < $nval; $j++) { - - $val = $vals[$j]; - if ($val == '') - $pval = " "; - else - $pval = "$val"; - - printf("\t\t\t<option " . - "value=\"%s\"%s>%s</option>\n", - $val, - $j == $ai ? " selected" : "", - $pval); - } - - echo "\t\t</select>\n"; - } - - end_field(); - } - - // functions to handle the form input - - // fetch all the parts of an "enum_multi" into a string suitable - // for a MySQL query - function gather_enum_multi_query($base, $cnt) { - - $retval = ''; - - for ($i = 0; $i < $cnt; $i++) { - - $name = sprintf("%s%x", $base, $i); - - if (isset($_REQUEST[$name])) { - $retval .= sprintf(", %s='%s'", - $name, $_REQUEST[$name]); - } - } - - return $retval; - } - - // fetch all the parts of an "enum_multi" into a string suitable - // for a display e.g. in an html table cell - function gather_enum_multi_print($base, $cnt, $array) { - - $retval = ''; - - for ($i = 0; $i < $cnt; $i++) { - - $name = sprintf("%s%x", $base, $i); - - if ($array[$name] != '') { - if ($retval != '') - $retval .= ','; - $retval .= $array[$name]; - } - } - - return $retval; - } - - // fetch all the parts of an "enum_multi" into a string suitable - // for writing to the eeprom data file - function gather_enum_multi_write($base, $cnt, $vals, $xfrm = array()) { - - $retval = ''; - - for ($i = 0; $i < $cnt; $i++) { - - $name = sprintf("%s%x", $base, $i); - - if ($GLOBALS[$name] != '') { - if ($retval != '') - $retval .= ','; - $index = enum_to_index($name, $vals); - if ($xfrm != array()) - $retval .= $xfrm[$index]; - else - $retval .= $index; - } - } - - return $retval; - } - - // count how many parts of an "enum_multi" are actually set - function count_enum_multi($base, $cnt) { - - $retval = 0; - - for ($i = 0; $i < $cnt; $i++) { - - $name = sprintf("%s%x", $base, $i); - - if (isset($_REQUEST[$name])) - $retval++; - } - - return $retval; - } - - // ethernet address functions - - // generate a (possibly not unique) random vendor ethernet address - // (setting bit 6 in the ethernet address - motorola wise i.e. bit 0 - // is the most significant bit - means it is not an assigned ethernet - // address - it is a "locally administered" address). Also, make sure - // it is NOT a multicast ethernet address (by setting bit 7 to 0). - // e.g. the first byte of all ethernet addresses generated here will - // have 2 in the bottom two bits (incidentally, these are the first - // two bits transmitted on the wire, since the octets in ethernet - // addresses are transmitted LSB first). - - function gen_eth_addr($serno) { - - $ethaddr_hgh = (mt_rand(0, 65535) & 0xfeff) | 0x0200; - $ethaddr_mid = mt_rand(0, 65535); - $ethaddr_low = mt_rand(0, 65535); - - return sprintf("%02lx:%02lx:%02lx:%02lx:%02lx:%02lx", - $ethaddr_hgh >> 8, $ethaddr_hgh & 0xff, - $ethaddr_mid >> 8, $ethaddr_mid & 0xff, - $ethaddr_low >> 8, $ethaddr_low & 0xff); - } - - // check that an ethernet address is valid - function eth_addr_is_valid($ethaddr) { - - $ethbytes = split(':', $ethaddr); - - if (count($ethbytes) != 6) - return FALSE; - - for ($i = 0; $i < 6; $i++) { - $ethbyte = $ethbytes[$i]; - if (!ereg('^[0-9a-f][0-9a-f]$', $ethbyte)) - return FALSE; - } - - return TRUE; - } - - // write a simple eeprom configuration file - function write_eeprom_cfg_file() { - - global $sernos, $nsernos, $bddb_cfgdir, $numerrs, $cfgerrs; - global $date, $batch, $type_vals, $rev; - global $sdram_vals, $sdram_nbits; - global $flash_vals, $flash_nbits; - global $zbt_vals, $zbt_nbits; - global $xlxtyp_vals, $xlxspd_vals, $xlxtmp_vals, $xlxgrd_vals; - global $cputyp, $cputyp_vals, $clk_vals; - global $hstype, $hstype_vals, $hschin, $hschout; - - $numerrs = 0; - $cfgerrs = array(); - - for ($i = 0; $i < $nsernos; $i++) { - - $serno = sprintf("%010d", $sernos[$i]); - - $wfp = @fopen($bddb_cfgdir . "/$serno.cfg", "w"); - if (!$wfp) { - $cfgerrs[$i] = 'file create fail'; - $numerrs++; - continue; - } - set_file_buffer($wfp, 0); - - if (!fprintf($wfp, "serno=%d\n", $sernos[$i])) { - $cfgerrs[$i] = 'cfg wr fail (serno)'; - fclose($wfp); - $numerrs++; - continue; - } - - if (!fprintf($wfp, "date=%s\n", $date)) { - $cfgerrs[$i] = 'cfg wr fail (date)'; - fclose($wfp); - $numerrs++; - continue; - } - - if ($batch != '') { - if (!fprintf($wfp, "batch=%s\n", $batch)) { - $cfgerrs[$i] = 'cfg wr fail (batch)'; - fclose($wfp); - $numerrs++; - continue; - } - } - - $typei = enum_to_index("type", $type_vals); - if (!fprintf($wfp, "type=%d\n", $typei)) { - $cfgerrs[$i] = 'cfg wr fail (type)'; - fclose($wfp); - $numerrs++; - continue; - } - - if (!fprintf($wfp, "rev=%d\n", $rev)) { - $cfgerrs[$i] = 'cfg wr fail (rev)'; - fclose($wfp); - $numerrs++; - continue; - } - - $s = gather_enum_multi_write("sdram", 4, - $sdram_vals, $sdram_nbits); - if ($s != '') { - $b = fprintf($wfp, "sdram=%s\n", $s); - if (!$b) { - $cfgerrs[$i] = 'cfg wr fail (sdram)'; - fclose($wfp); - $numerrs++; - continue; - } - } - - $s = gather_enum_multi_write("flash", 4, - $flash_vals, $flash_nbits); - if ($s != '') { - $b = fprintf($wfp, "flash=%s\n", $s); - if (!$b) { - $cfgerrs[$i] = 'cfg wr fail (flash)'; - fclose($wfp); - $numerrs++; - continue; - } - } - - $s = gather_enum_multi_write("zbt", 16, - $zbt_vals, $zbt_nbits); - if ($s != '') { - $b = fprintf($wfp, "zbt=%s\n", $s); - if (!$b) { - $cfgerrs[$i] = 'cfg wr fail (zbt)'; - fclose($wfp); - $numerrs++; - continue; - } - } - - $s = gather_enum_multi_write("xlxtyp", 4, $xlxtyp_vals); - if ($s != '') { - $b = fprintf($wfp, "xlxtyp=%s\n", $s); - if (!$b) { - $cfgerrs[$i] = 'cfg wr fail (xlxtyp)'; - fclose($wfp); - $numerrs++; - continue; - } - } - - $s = gather_enum_multi_write("xlxspd", 4, $xlxspd_vals); - if ($s != '') { - $b = fprintf($wfp, "xlxspd=%s\n", $s); - if (!$b) { - $cfgerrs[$i] = 'cfg wr fail (xlxspd)'; - fclose($wfp); - $numerrs++; - continue; - } - } - - $s = gather_enum_multi_write("xlxtmp", 4, $xlxtmp_vals); - if ($s != '') { - $b = fprintf($wfp, "xlxtmp=%s\n", $s); - if (!$b) { - $cfgerrs[$i] = 'cfg wr fail (xlxtmp)'; - fclose($wfp); - $numerrs++; - continue; - } - } - - $s = gather_enum_multi_write("xlxgrd", 4, $xlxgrd_vals); - if ($s != '') { - $b = fprintf($wfp, "xlxgrd=%s\n", $s); - if (!$b) { - $cfgerrs[$i] = 'cfg wr fail (xlxgrd)'; - fclose($wfp); - $numerrs++; - continue; - } - } - - if ($cputyp != '') { - $cputypi = enum_to_index("cputyp",$cputyp_vals); - $cpuspdi = enum_to_index("cpuspd", $clk_vals); - $busspdi = enum_to_index("busspd", $clk_vals); - $cpmspdi = enum_to_index("cpmspd", $clk_vals); - $b = fprintf($wfp, "cputyp=%d\ncpuspd=%d\n" . - "busspd=%d\ncpmspd=%d\n", - $cputypi, $cpuspdi, $busspdi, $cpmspdi); - if (!$b) { - $cfgerrs[$i] = 'cfg wr fail (cputyp)'; - fclose($wfp); - $numerrs++; - continue; - } - } - - if ($hstype != '') { - $hstypei = enum_to_index("hstype",$hstype_vals); - $b = fprintf($wfp, "hstype=%d\n" . - "hschin=%s\nhschout=%s\n", - $hstypei, $hschin, $hschout); - if (!$b) { - $cfgerrs[$i] = 'cfg wr fail (hstype)'; - fclose($wfp); - $numerrs++; - continue; - } - } - - if (!fclose($wfp)) { - $cfgerrs[$i] = 'file cls fail'; - $numerrs++; - } - } - - return $numerrs; - } -?> diff --git a/tools/bddb/dodelete.php b/tools/bddb/dodelete.php deleted file mode 100644 index 4839e36e60..0000000000 --- a/tools/bddb/dodelete.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - // dodelete page (hymod_bddb / boards) - - require("defs.php"); - - pg_head("$bddb_label - Delete Board Results"); - - if (!isset($_REQUEST['serno'])) - die("the board serial number was not specified"); - $serno=intval($_REQUEST['serno']); - - mysql_query("delete from boards where serno=$serno"); - - if(mysql_errno()) { - $errstr = mysql_error(); - echo "\t<font size=+4>\n"; - echo "\t\t<p>\n"; - echo "\t\t\tThe following error was encountered:\n"; - echo "\t\t</p>\n"; - echo "\t\t<center>\n"; - printf("\t\t\t<b>%s</b>\n", $errstr); - echo "\t\t</center>\n"; - echo "\t</font>\n"; - } - else { - echo "\t<font size=+2>\n"; - echo "\t\t<p>\n"; - echo "\t\t\tThe board with serial number <b>$serno</b> was" - . " successfully deleted\n"; - mysql_query("delete from log where serno=$serno"); - if (mysql_errno()) { - $errstr = mysql_error(); - echo "\t\t\t<font size=+4>\n"; - echo "\t\t\t\t<p>\n"; - echo "\t\t\t\t\tBut the following error occurred " . - "when deleting the log entries:\n"; - echo "\t\t\t\t</p>\n"; - echo "\t\t\t\t<center>\n"; - printf("\t\t\t\t\t<b>%s</b>\n", $errstr); - echo "\t\t\t\t</center>\n"; - echo "\t\t\t</font>\n"; - } - echo "\t\t</p>\n"; - echo "\t</font>\n"; - } -?> -<p> -<table width="100%"> -<tr> - <td align=center> - <a href="browse.php">Back to Browse</a> - </td> - <td align=center> - <a href="index.php">Back to Start</a> - </td> -</tr> -</table> -<?php - pg_foot(); -?> diff --git a/tools/bddb/dodellog.php b/tools/bddb/dodellog.php deleted file mode 100644 index 9dd78c11b6..0000000000 --- a/tools/bddb/dodellog.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - // dodelete page (hymod_bddb / boards) - - require("defs.php"); - - pg_head("$bddb_label - Delete Log Entry Results"); - - if (!isset($_REQUEST['serno'])) - die("the board serial number was not specified"); - $serno=intval($_REQUEST['serno']); - - if (!isset($_REQUEST['logno']) || $_REQUEST['logno'] == 0) - die("the log entry number not specified!"); - $logno=$_REQUEST['logno']; - - mysql_query("delete from log where serno=$serno and logno=$logno"); - - if(mysql_errno()) { - $errstr = mysql_error(); - echo "\t<font size=+4>\n"; - echo "\t\t<p>\n"; - echo "\t\t\tThe following error was encountered:\n"; - echo "\t\t</p>\n"; - echo "\t\t<center>\n"; - printf("\t\t\t<b>%s</b>\n", $errstr); - echo "\t\t</center>\n"; - echo "\t</font>\n"; - } - else { - echo "\t<font size=+2>\n"; - echo "\t\t<p>\n"; - echo "\t\t\tThe log entry with log number <b>$logno</b>\n"; - echo "\t\t\tand serial number <b>$serno</b> "; - echo "was successfully deleted\n"; - echo "\t\t</p>\n"; - echo "\t</font>\n"; - } -?> -<p> -<table width="100%"> -<tr> - <td align=center> - <a href="brlog.php?serno=<?php echo "$serno"; ?>">Back to Log</a> - </td> - <td align=center> - <a href="index.php">Back to Start</a> - </td> -</tr> -</table> -<?php - pg_foot(); -?> diff --git a/tools/bddb/doedit.php b/tools/bddb/doedit.php deleted file mode 100644 index 13fbb69479..0000000000 --- a/tools/bddb/doedit.php +++ /dev/null @@ -1,186 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - // doedit page (hymod_bddb / boards) - - require("defs.php"); - - pg_head("$bddb_label - Edit Board Results"); - - if (!isset($_REQUEST['serno']) || $_REQUEST['serno'] == '') - die("the board serial number was not specified"); - $serno=intval($_REQUEST['serno']); - - $query="update boards set"; - - if (isset($_REQUEST['ethaddr'])) { - $ethaddr=$_REQUEST['ethaddr']; - if (!eth_addr_is_valid($ethaddr)) - die("ethaddr is invalid ('$ethaddr')"); - $query.=" ethaddr='$ethaddr',"; - } - - if (isset($_REQUEST['date'])) { - $date=$_REQUEST['date']; - list($y, $m, $d) = split("-", $date); - if (!checkdate($m, $d, $y) || $y < 1999) - die("date is invalid (input '$date', " . - "yyyy-mm-dd '$y-$m-$d')"); - $query.=" date='$date'"; - } - - if (isset($_REQUEST['batch'])) { - $batch=$_REQUEST['batch']; - if (strlen($batch) > 32) - die("batch field too long (>32)"); - $query.=", batch='$batch'"; - } - - if (isset($_REQUEST['type'])) { - $type=$_REQUEST['type']; - if (!in_array($type, $type_vals)) - die("Invalid type ($type) specified"); - $query.=", type='$type'"; - } - - if (isset($_REQUEST['rev'])) { - $rev=$_REQUEST['rev']; - if (($rev = intval($rev)) <= 0 || $rev > 255) - die("Revision number is invalid ($rev)"); - $query.=sprintf(", rev=%d", $rev); - } - - if (isset($_REQUEST['location'])) { - $location=$_REQUEST['location']; - if (strlen($location) > 64) - die("location field too long (>64)"); - $query.=", location='$location'"; - } - - if (isset($_REQUEST['comments'])) - $comments=$_REQUEST['comments']; - $query.=", comments='" . rawurlencode($comments) . "'"; - - $query.=gather_enum_multi_query("sdram", 4); - - $query.=gather_enum_multi_query("flash", 4); - - $query.=gather_enum_multi_query("zbt", 16); - - $query.=gather_enum_multi_query("xlxtyp", 4); - $nxlx = count_enum_multi("xlxtyp", 4); - - $query.=gather_enum_multi_query("xlxspd", 4); - if (count_enum_multi("xlxspd", 4) != $nxlx) - die("number of xilinx speeds not same as number of types"); - - $query.=gather_enum_multi_query("xlxtmp", 4); - if (count_enum_multi("xlxtmp", 4) != $nxlx) - die("number of xilinx temps. not same as number of types"); - - $query.=gather_enum_multi_query("xlxgrd", 4); - if (count_enum_multi("xlxgrd", 4) != $nxlx) - die("number of xilinx grades not same as number of types"); - - if (isset($_REQUEST['cputyp'])) { - $cputyp=$_REQUEST['cputyp']; - $query.=", cputyp='$cputyp'"; - if (!isset($_REQUEST['cpuspd']) || $_REQUEST['cpuspd'] == '') - die("must specify cpu speed if cpu type is defined"); - $cpuspd=$_REQUEST['cpuspd']; - $query.=", cpuspd='$cpuspd'"; - if (!isset($_REQUEST['cpmspd']) || $_REQUEST['cpmspd'] == '') - die("must specify cpm speed if cpu type is defined"); - $cpmspd=$_REQUEST['cpmspd']; - $query.=", cpmspd='$cpmspd'"; - if (!isset($_REQUEST['busspd']) || $_REQUEST['busspd'] == '') - die("must specify bus speed if cpu type is defined"); - $busspd=$_REQUEST['busspd']; - $query.=", busspd='$busspd'"; - } - else { - if (isset($_REQUEST['cpuspd'])) - die("can't specify cpu speed if there is no cpu"); - if (isset($_REQUEST['cpmspd'])) - die("can't specify cpm speed if there is no cpu"); - if (isset($_REQUEST['busspd'])) - die("can't specify bus speed if there is no cpu"); - } - - if (isset($_REQUEST['hschin'])) { - $hschin=$_REQUEST['hschin']; - if (($hschin = intval($hschin)) < 0 || $hschin > 4) - die("Invalid number of hs input chans ($hschin)"); - } - else - $hschin = 0; - if (isset($_REQUEST['hschout'])) { - $hschout=$_REQUEST['hschout']; - if (($hschout = intval($hschout)) < 0 || $hschout > 4) - die("Invalid number of hs output chans ($hschout)"); - } - else - $hschout = 0; - if (isset($_REQUEST['hstype'])) { - $hstype=$_REQUEST['hstype']; - $query.=", hstype='$hstype'"; - } - else { - if ($_REQUEST['hschin'] != 0) - die("number of high-speed input channels must be zero" - . " if high-speed chip is not present"); - if ($_REQUEST['hschout'] != 0) - die("number of high-speed output channels must be zero" - . " if high-speed chip is not present"); - } - $query.=", hschin='$hschin'"; - $query.=", hschout='$hschout'"; - - $query.=" where serno=$serno"; - - mysql_query($query); - if(mysql_errno()) { - $errstr = mysql_error(); - echo "\t<font size=+4>\n"; - echo "\t\t<p>\n"; - echo "\t\t\tThe following error was encountered:\n"; - echo "\t\t</p>\n"; - echo "\t\t<center>\n"; - printf("\t\t\t<b>%s</b>\n", $errstr); - echo "\t\t</center>\n"; - echo "\t</font>\n"; - } - else { - $sernos = array($serno); - $nsernos = 1; - - write_eeprom_cfg_file(); - - echo "\t<font size=+2>\n"; - echo "\t\t<p>\n"; - echo "\t\t\tThe board with serial number <b>$serno</b> was" - . " successfully updated"; - if ($numerrs > 0) { - $errstr = $cfgerrs[0]; - echo "<br>\n\t\t\t"; - echo "(but the cfg file update failed: $errstr)"; - } - echo "\n"; - echo "\t\t</p>\n"; - echo "\t</font>\n"; - } - -?> -<p> -<table align=center width="100%"> -<tr> - <td align=center><a href="browse.php">Back to Browse</a></td> - <td align=center><a href="index.php">Back to Start</a></td> -</tr> -</table> -<?php - pg_foot(); -?> diff --git a/tools/bddb/doedlog.php b/tools/bddb/doedlog.php deleted file mode 100644 index 7009aa7dad..0000000000 --- a/tools/bddb/doedlog.php +++ /dev/null @@ -1,76 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - // doedit page (hymod_bddb / boards) - - require("defs.php"); - - pg_head("$bddb_label - Edit Log Entry Results"); - - if (!isset($_REQUEST['serno']) || $_REQUEST['serno'] == '') - die("the board serial number was not specified"); - $serno=intval($_REQUEST['serno']); - - if (!isset($_REQUEST['logno']) || $_REQUEST['logno'] == '') - die("log number not specified!"); - $logno=intval($_REQUEST['logno']); - - $query="update log set"; - - if (isset($_REQUEST['date'])) { - $date=$_REQUEST['date']; - list($y, $m, $d) = split("-", $date); - if (!checkdate($m, $d, $y) || $y < 1999) - die("date is invalid (input '$date', " . - "yyyy-mm-dd '$y-$m-$d')"); - $query.=" date='$date'"; - } - - if (isset($_REQUEST['who'])) { - $who=$_REQUEST['who']; - $query.=", who='" . $who . "'"; - } - - if (isset($_REQUEST['details'])) { - $details=$_REQUEST['details']; - $query.=", details='" . rawurlencode($details) . "'"; - } - - $query.=" where serno=$serno and logno=$logno"; - - mysql_query($query); - if(mysql_errno()) { - $errstr = mysql_error(); - echo "\t<font size=+4>\n"; - echo "\t\t<p>\n"; - echo "\t\t\tThe following error was encountered:\n"; - echo "\t\t</p>\n"; - echo "\t\t<center>\n"; - printf("\t\t\t<b>%s</b>\n", $errstr); - echo "\t\t</center>\n"; - echo "\t</font>\n"; - } - else { - echo "\t<font size=+2>\n"; - echo "\t\t<p>\n"; - echo "\t\t\tThe log entry with log number <b>$logno</b> and\n"; - echo "\t\t\tserial number <b>$serno</b> "; - echo "was successfully updated\n"; - echo "\t\t</p>\n"; - echo "\t</font>\n"; - } - -?> -<p> -<table align=center width="100%"> -<tr> - <td align=center><a href="brlog.php?serno=<?php echo "$serno"; ?>">Back to Log</a></td> - <td align=center><a href="index.php">Back to Start</a></td> -</tr> -</table> -<?php - pg_foot(); -?> diff --git a/tools/bddb/donew.php b/tools/bddb/donew.php deleted file mode 100644 index 39b2c78fca..0000000000 --- a/tools/bddb/donew.php +++ /dev/null @@ -1,230 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - // doedit page (hymod_bddb / boards) - - require("defs.php"); - - pg_head("$bddb_label - Board Registration Results"); - - if (isset($_REQUEST['serno'])) { - $serno=$_REQUEST['serno']; - die("serial number must not be set ($serno) when Creating!"); - } - - $query="update boards set"; - - list($y, $m, $d) = split("-", $date); - if (!checkdate($m, $d, $y) || $y < 1999) - die("date is invalid (input '$date', yyyy-mm-dd '$y-$m-$d')"); - $query.=" date='$date'"; - - if ($batch != '') { - if (strlen($batch) > 32) - die("batch field too long (>32)"); - $query.=", batch='$batch'"; - } - - if (!in_array($type, $type_vals)) - die("Invalid type ($type) specified"); - $query.=", type='$type'"; - - if (($rev = intval($rev)) <= 0 || $rev > 255) - die("Revision number is invalid ($rev)"); - $query.=sprintf(", rev=%d", $rev); - - $query.=gather_enum_multi_query("sdram", 4); - - $query.=gather_enum_multi_query("flash", 4); - - $query.=gather_enum_multi_query("zbt", 16); - - $query.=gather_enum_multi_query("xlxtyp", 4); - $nxlx = count_enum_multi("xlxtyp", 4); - - $query.=gather_enum_multi_query("xlxspd", 4); - if (count_enum_multi("xlxspd", 4) != $nxlx) - die("number of xilinx speeds not same as number of types"); - - $query.=gather_enum_multi_query("xlxtmp", 4); - if (count_enum_multi("xlxtmp", 4) != $nxlx) - die("number of xilinx temps. not same as number of types"); - - $query.=gather_enum_multi_query("xlxgrd", 4); - if (count_enum_multi("xlxgrd", 4) != $nxlx) - die("number of xilinx grades not same as number of types"); - - if ($cputyp == '') { - if ($cpuspd != '') - die("can't specify cpu speed if there is no cpu"); - if ($cpmspd != '') - die("can't specify cpm speed if there is no cpu"); - if ($busspd != '') - die("can't specify bus speed if there is no cpu"); - } - else { - $query.=", cputyp='$cputyp'"; - if ($cpuspd == '') - die("must specify cpu speed if cpu type is defined"); - $query.=", cpuspd='$cpuspd'"; - if ($cpmspd == '') - die("must specify cpm speed if cpu type is defined"); - $query.=", cpmspd='$cpmspd'"; - if ($busspd == '') - die("must specify bus speed if cpu type is defined"); - $query.=", busspd='$busspd'"; - } - - if (($hschin = intval($hschin)) < 0 || $hschin > 4) - die("Invalid number of hs input chans ($hschin)"); - if (($hschout = intval($hschout)) < 0 || $hschout > 4) - die("Invalid number of hs output chans ($hschout)"); - if ($hstype == '') { - if ($hschin != 0) - die("number of high-speed input channels must be zero" - . " if high-speed chip is not present"); - if ($hschout != 0) - die("number of high-speed output channels must be zero" - . " if high-speed chip is not present"); - } - else - $query.=", hstype='$hstype'"; - $query.=", hschin='$hschin'"; - $query.=", hschout='$hschout'"; - - // echo "final query = '$query'<br>\n"; - - $quant = intval($quant); - if ($quant <= 0) $quant = 1; - - $sernos = array(); - if ($geneths) - $ethaddrs = array(); - - $sqlerr = ''; - - while ($quant-- > 0) { - - mysql_query("insert into boards (serno) values (null)"); - if (mysql_errno()) { - $sqlerr = mysql_error(); - break; - } - - $serno = mysql_insert_id(); - if (!$serno) { - $sqlerr = "couldn't allocate new serial number"; - break; - } - - mysql_query($query . " where serno=$serno"); - if (mysql_errno()) { - $sqlerr = mysql_error(); - break; - } - - array_push($sernos, $serno); - - if ($geneths) { - - $ethaddr = gen_eth_addr($serno); - - mysql_query("update boards set ethaddr='$ethaddr'" . - " where serno=$serno"); - if (mysql_errno()) { - $sqlerr = mysql_error(); - - array_push($ethaddrs, - "<font color=#ff0000><b>" . - "db save fail" . - "</b></font>"); - break; - } - - array_push($ethaddrs, $ethaddr); - } - } - - $nsernos = count($sernos); - - if ($nsernos > 0) { - - write_eeprom_cfg_file(); - - echo "<font size=+2>\n"; - echo "\t<p>\n"; - echo "\t\tThe following board serial numbers were" - . " successfully allocated"; - if ($numerrs > 0) - echo " (but with $numerrs cfg file error" . - ($numerrs > 1 ? "s" : "") . ")"; - echo ":\n"; - echo "\t</p>\n"; - - echo "</font>\n"; - - echo "<table align=center width=\"100%\">\n"; - echo "<tr>\n"; - echo "\t<th>Serial Number</th>\n"; - if ($numerrs > 0) - echo "\t<th>Cfg File Errs</th>\n"; - if ($geneths) - echo "\t<th>Ethernet Address</th>\n"; - echo "</tr>\n"; - - for ($i = 0; $i < $nsernos; $i++) { - - $serno = sprintf("%010d", $sernos[$i]); - - echo "<tr>\n"; - - echo "\t<td align=center><font size=+2>" . - "<b>$serno</b></font></td>\n"; - - if ($numerrs > 0) { - if (($errstr = $cfgerrs[$i]) == '') - $errstr = ' '; - echo "\t<td align=center>" . - "<font size=+2 color=#ff0000><b>" . - $errstr . - "</b></font></td>\n"; - } - - if ($geneths) { - echo "\t<td align=center>" . - "<font size=+2 color=#00ff00><b>" . - $ethaddrs[$i] . - "</b></font></td>\n"; - } - - echo "</tr>\n"; - } - - echo "</table>\n"; - } - - if ($sqlerr != '') { - echo "\t<font size=+4>\n"; - echo "\t\t<p>\n"; - echo "\t\t\tThe following SQL error was encountered:\n"; - echo "\t\t</p>\n"; - echo "\t\t<center>\n"; - printf("\t\t\t<b>%s</b>\n", $sqlerr); - echo "\t\t</center>\n"; - echo "\t</font>\n"; - } - -?> -<p> -<table align=center width="100%"> -<tr> - <td align=center><a href="browse.php">Go to Browse</a></td> - <td align=center><a href="index.php">Back to Start</a></td> -</tr> -</table> -<?php - pg_foot(); -?> diff --git a/tools/bddb/donewlog.php b/tools/bddb/donewlog.php deleted file mode 100644 index 7635d2992d..0000000000 --- a/tools/bddb/donewlog.php +++ /dev/null @@ -1,86 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - // doedit page (hymod_bddb / boards) - - require("defs.php"); - - pg_head("$bddb_label - Add Log Entry Results"); - - if (!isset($_REQUEST['serno']) || $_REQUEST['serno'] == '') - die("serial number not specified!"); - $serno=intval($_REQUEST['serno']); - - if (isset($_REQUEST['logno'])) { - $logno=$_REQUEST['logno']; - die("log number must not be set ($logno) when Creating!"); - } - - $query="update log set serno=$serno"; - - list($y, $m, $d) = split("-", $date); - if (!checkdate($m, $d, $y) || $y < 1999) - die("date is invalid (input '$date', yyyy-mm-dd '$y-$m-$d')"); - $query.=", date='$date'"; - - if (isset($_REQUEST['who'])) { - $who=$_REQUEST['who']; - $query.=", who='" . $who . "'"; - } - - if (isset($_REQUEST['details'])) { - $details=$_REQUEST['details']; - $query.=", details='" . rawurlencode($details) . "'"; - } - - // echo "final query = '$query'<br>\n"; - - $sqlerr = ''; - - mysql_query("insert into log (logno) values (null)"); - if (mysql_errno()) - $sqlerr = mysql_error(); - else { - $logno = mysql_insert_id(); - if (!$logno) - $sqlerr = "couldn't allocate new serial number"; - else { - mysql_query($query . " where logno=$logno"); - if (mysql_errno()) - $sqlerr = mysql_error(); - } - } - - if ($sqlerr == '') { - echo "<font size=+2>\n"; - echo "\t<p>\n"; - echo "\t\tA log entry with log number '$logno' was " . - "added to the board with serial number '$serno'\n"; - echo "\t</p>\n"; - echo "</font>\n"; - } - else { - echo "\t<font size=+4>\n"; - echo "\t\t<p>\n"; - echo "\t\t\tThe following SQL error was encountered:\n"; - echo "\t\t</p>\n"; - echo "\t\t<center>\n"; - printf("\t\t\t<b>%s</b>\n", $sqlerr); - echo "\t\t</center>\n"; - echo "\t</font>\n"; - } - -?> -<p></p> -<table width="100%"> -<tr> - <td align=center><a href="brlog.php?serno=<?php echo "$serno"; ?>">Go to Browse</a></td> - <td align=center><a href="index.php">Back to Start</a></td> -</tr> -</table> -<?php - pg_foot(); -?> diff --git a/tools/bddb/edit.php b/tools/bddb/edit.php deleted file mode 100644 index dd8c26c5cd..0000000000 --- a/tools/bddb/edit.php +++ /dev/null @@ -1,131 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - // edit page (hymod_bddb / boards) - - require("defs.php"); - - pg_head("$bddb_label - Edit Board Registration"); - - if ($serno == 0) - die("serial number not specified or invalid!"); - - $pserno = sprintf("%010d", $serno); - - echo "<center><b><font size=+2>"; - echo "Board Serial Number: $pserno"; - echo "</font></b></center>\n"; - -?> -<p> -<form action=doedit.php method=POST> -<?php - echo "<input type=hidden name=serno value=$serno>\n"; - - $r=mysql_query("select * from boards where serno=$serno"); - $row=mysql_fetch_array($r); - if(!$row) die("no record of serial number '$serno' in database"); - - begin_table(5); - - // ethaddr char(17) - print_field("ethaddr", $row, 17); - - // date date - print_field("date", $row); - - // batch char(32) - print_field("batch", $row, 32); - - // type enum('IO','CLP','DSP','INPUT','ALT-INPUT','DISPLAY') - print_enum("type", $row, $type_vals); - - // rev tinyint(3) unsigned zerofill - print_field("rev", $row, 3, 'rev_filter'); - - // location char(64) - print_field("location", $row, 64); - - // comments text - print_field_multiline("comments", $row, 60, 10, 'text_filter'); - - // sdram[0-3] enum('32M','64M','128M','256M') - print_enum_multi("sdram", $row, $sdram_vals, 4, array()); - - // flash[0-3] enum('4M','8M','16M','32M','64M') - print_enum_multi("flash", $row, $flash_vals, 4, array()); - - // zbt[0-f] enum('512K','1M','2M','4M') - print_enum_multi("zbt", $row, $zbt_vals, 16, array()); - - // xlxtyp[0-3] enum('XCV300E','XCV400E','XCV600E') - print_enum_multi("xlxtyp", $row, $xlxtyp_vals, 4, array(), 1); - - // xlxspd[0-3] enum('6','7','8') - print_enum_multi("xlxspd", $row, $xlxspd_vals, 4, array(), 1); - - // xlxtmp[0-3] enum('COM','IND') - print_enum_multi("xlxtmp", $row, $xlxtmp_vals, 4, array(), 1); - - // xlxgrd[0-3] enum('NORMAL','ENGSAMP') - print_enum_multi("xlxgrd", $row, $xlxgrd_vals, 4, array(), 1); - - // cputyp enum('MPC8260(HIP3)','MPC8260A(HIP4)','MPC8280(HIP7)') - print_enum("cputyp", $row, $cputyp_vals); - - // cpuspd enum('33MHZ','66MHZ','100MHZ','133MHZ','166MHZ','200MHZ','233MHZ','266MHZ') - print_enum_select("cpuspd", $row, $clk_vals); - - // cpmspd enum('33MHZ','66MHZ','100MHZ','133MHZ','166MHZ','200MHZ','233MHZ','266MHZ') - print_enum_select("cpmspd", $row, $clk_vals); - - // busspd enum('33MHZ','66MHZ','100MHZ','133MHZ','166MHZ','200MHZ','233MHZ','266MHZ') - print_enum_select("busspd", $row, $clk_vals); - - // hstype enum('AMCC-S2064A') - print_enum("hstype", $row, $hstype_vals); - - // hschin enum('0','1','2','3','4') - print_enum("hschin", $row, $hschin_vals); - - // hschout enum('0','1','2','3','4') - print_enum("hschout", $row, $hschout_vals); - - end_table(); - - echo "<p>\n"; - echo "<center><b>"; - echo "<font color=#ff0000>WARNING: NO UNDO ON DELETE!</font>"; - echo "<br></br>\n"; - echo "<tt>[ <a href=\"dodelete.php?serno=$serno\">delete</a> ]</tt>"; - echo "</b></center>\n"; - echo "</p>\n"; -?> -<p> -<table align=center width="100%"> -<tr> - <td align=center> - <input type=submit value=Edit> - </td> - <td> - - </td> - <td align=center> - <input type=reset value=Reset> - </td> - <td> - - </td> - <td align=center> - <a href="index.php">Back to Start</a> - </td> -</tr> -</table> -</p> -</form> -<?php - pg_foot(); -?> diff --git a/tools/bddb/edlog.php b/tools/bddb/edlog.php deleted file mode 100644 index 8befd35b92..0000000000 --- a/tools/bddb/edlog.php +++ /dev/null @@ -1,86 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - // edit page (hymod_bddb / boards) - - require("defs.php"); - - pg_head("$bddb_label - Edit Board Log Entry"); - - if (!isset($_REQUEST['serno']) || $_REQUEST['serno'] == '') - die("serial number not specified!"); - $serno=intval($_REQUEST['serno']); - - if (!isset($_REQUEST['logno']) || $_REQUEST['logno'] == '') - die("log number not specified!"); - $logno=intval($_REQUEST['logno']); - - $pserno = sprintf("%010d", $serno); - $plogno = sprintf("%010d", $logno); - - echo "<center><b><font size=+2>"; - echo "Board Serial Number: $pserno, Log Number: $plogno"; - echo "</font></b></center>\n"; - -?> -<p> -<form action=doedlog.php method=POST> -<?php - echo "<input type=hidden name=serno value=$serno>\n"; - echo "<input type=hidden name=logno value=$logno>\n"; - - $r=mysql_query("select * from log where serno=$serno and logno=$logno"); - $row=mysql_fetch_array($r); - if(!$row) - die("no record of log entry with serial number '$serno' " . - "and log number '$logno' in database"); - - begin_table(3); - - // date date - print_field("date", $row); - - // who char(20) - print_field("who", $row); - - // details text - print_field_multiline("details", $row, 60, 10, 'text_filter'); - - end_table(); - - echo "<p>\n"; - echo "<center><b>"; - echo "<font color=#ff0000>WARNING: NO UNDO ON DELETE!</font>"; - echo "<br></br>\n"; - echo "<tt>[ <a href=\"dodellog.php?serno=$serno&logno=$logno\">delete</a> ]</tt>"; - echo "</b></center>\n"; - echo "</p>\n"; -?> -<p> -<table align=center width="100%"> -<tr> - <td align=center> - <input type=submit value=Edit> - </td> - <td> - - </td> - <td align=center> - <input type=reset value=Reset> - </td> - <td> - - </td> - <td align=center> - <a href="index.php">Back to Start</a> - </td> -</tr> -</table> -</p> -</form> -<?php - pg_foot(); -?> diff --git a/tools/bddb/execute.php b/tools/bddb/execute.php deleted file mode 100644 index 0b62882d75..0000000000 --- a/tools/bddb/execute.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - $serno=isset($_REQUEST['serno'])?$_REQUEST['serno']:''; - - $submit=isset($_REQUEST['submit'])?$_REQUEST['submit']:"[NOT SET]"; - - switch ($submit) { - - case "New": - require("new.php"); - break; - - case "Edit": - require("edit.php"); - break; - - case "Browse": - require("browse.php"); - break; - - case "Log": - require("brlog.php"); - break; - - default: - require("badsubmit.php"); - break; - } -?> diff --git a/tools/bddb/index.php b/tools/bddb/index.php deleted file mode 100644 index 842aed55fb..0000000000 --- a/tools/bddb/index.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - require("defs.php"); - pg_head("$bddb_label"); -?> -<font size="+4"> - <form action=execute.php method=POST> - <table width="100%" cellspacing=10 cellpadding=10> - <tr> - <td align=center> - <input type=submit name=submit value="New"></input> - </td> - <td align=center> - <input type=submit name=submit value="Edit"></input> - </td> - <td align=center> - <input type=submit name=submit value="Browse"></input> - </td> - <td align=center> - <input type=submit name=submit value="Log"></input> - </td> - </tr> - <tr> - <td align=center colspan=4> - <b>Serial Number:</b> - <input type=text name=serno size=10 maxsize=10 value=""></input> - </td> - </tr> - </table> - </form> -</font> -<?php - pg_foot(); -?> diff --git a/tools/bddb/new.php b/tools/bddb/new.php deleted file mode 100644 index 30323ff819..0000000000 --- a/tools/bddb/new.php +++ /dev/null @@ -1,120 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - // edit page (hymod_bddb / boards) - - require("defs.php"); - - pg_head("$bddb_label - New Board Registration"); -?> -<form action=donew.php method=POST> -<p></p> -<?php - $serno=intval($serno); - // if a serial number was supplied, fetch the record - // and use its contents as defaults - if ($serno != 0) { - $r=mysql_query("select * from boards where serno=$serno"); - $row=mysql_fetch_array($r); - if(!$row)die("no record of serial number '$serno' in database"); - } - else - $row = array(); - - begin_table(5); - - // date date - print_field("date", array('date' => date("Y-m-d"))); - - // batch char(32) - print_field("batch", $row, 32); - - // type enum('IO','CLP','DSP','INPUT','ALT-INPUT','DISPLAY') - print_enum("type", $row, $type_vals, 0); - - // rev tinyint(3) unsigned zerofill - print_field("rev", $row, 3, 'rev_filter'); - - // sdram[0-3] enum('32M','64M','128M','256M') - print_enum_multi("sdram", $row, $sdram_vals, 4, array(2)); - - // flash[0-3] enum('4M','8M','16M','32M','64M') - print_enum_multi("flash", $row, $flash_vals, 4, array(2)); - - // zbt[0-f] enum('512K','1M','2M','4M') - print_enum_multi("zbt", $row, $zbt_vals, 16, array(2, 2)); - - // xlxtyp[0-3] enum('XCV300E','XCV400E','XCV600E') - print_enum_multi("xlxtyp", $row, $xlxtyp_vals, 4, array(1), 1); - - // xlxspd[0-3] enum('6','7','8') - print_enum_multi("xlxspd", $row, $xlxspd_vals, 4, array(1), 1); - - // xlxtmp[0-3] enum('COM','IND') - print_enum_multi("xlxtmp", $row, $xlxtmp_vals, 4, array(1), 1); - - // xlxgrd[0-3] enum('NORMAL','ENGSAMP') - print_enum_multi("xlxgrd", $row, $xlxgrd_vals, 4, array(1), 1); - - // cputyp enum('MPC8260(HIP3)','MPC8260A(HIP4)','MPC8280(HIP7)') - print_enum("cputyp", $row, $cputyp_vals, 1); - - // cpuspd enum('33MHZ','66MHZ','100MHZ','133MHZ','166MHZ','200MHZ','233MHZ','266MHZ') - print_enum_select("cpuspd", $row, $clk_vals, 4); - - // cpmspd enum('33MHZ','66MHZ','100MHZ','133MHZ','166MHZ','200MHZ','233MHZ','266MHZ') - print_enum_select("cpmspd", $row, $clk_vals, 4); - - // busspd enum('33MHZ','66MHZ','100MHZ','133MHZ','166MHZ','200MHZ','233MHZ','266MHZ') - print_enum_select("busspd", $row, $clk_vals, 2); - - // hstype enum('AMCC-S2064A') - print_enum("hstype", $row, $hstype_vals, 1); - - // hschin enum('0','1','2','3','4') - print_enum("hschin", $row, $hschin_vals, 4); - - // hschout enum('0','1','2','3','4') - print_enum("hschout", $row, $hschout_vals, 4); - - end_table(); -?> -<p></p> -<table width="100%"> -<tr> - <td align=center colspan=3> - Allocate - <input type=text name=quant size=2 maxlength=2 value=" 1"> - board serial number(s) - </td> -</tr> -<tr> - <td align=center colspan=3> - <input type=checkbox name=geneths checked> - Generate Ethernet Address(es) - </td> -</tr> -<tr> - <td colspan=3> - - </td> -</tr> -<tr> - <td align=center> - <input type=submit value="Register Board"> - </td> - <td> - - </td> - <td align=center> - <input type=reset value="Reset Form Contents"> - </td> -</tr> -</table> -</form> -<?php - pg_foot(); -?> diff --git a/tools/bddb/newlog.php b/tools/bddb/newlog.php deleted file mode 100644 index 609bb855c5..0000000000 --- a/tools/bddb/newlog.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?> -<?php - // (C) Copyright 2001 - // Murray Jensen <Murray.Jensen@csiro.au> - // CSIRO Manufacturing Science and Technology, Preston Lab - - // edit page (hymod_bddb / boards) - - require("defs.php"); - - pg_head("$bddb_label - New Log Entry"); - - if (!isset($_REQUEST['serno']) || $_REQUEST['serno'] == '') - die("serial number not specified or invalid!"); - $serno=intval($_REQUEST['serno']); - - if (isset($_REQUEST['logno'])) { - $logno=$_REQUEST['logno']; - die("log number must not be specified when adding! ($logno)"); - } -?> -<form action=donewlog.php method=POST> -<p></p> -<?php - echo "<input type=hidden name=serno value=$serno>\n"; - - begin_table(3); - - // date date - print_field("date", array('date' => date("Y-m-d"))); - - // who char(20) - print_field("who", array()); - - // details text - print_field_multiline("details", array(), 60, 10, 'text_filter'); - - end_table(); -?> -<p></p> -<table width="100%"> -<tr> - <td align=center> - <input type=submit value="Add Log Entry"> - </td> - <td align=center> - <input type=reset value="Reset Form Contents"> - </td> -</tr> -</table> -</form> -<?php - pg_foot(); -?> diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 109d61686e..c50f2e2b24 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1,364 +1,824 @@ /* - * (C) Copyright 2008 - * Marvell Semiconductor <www.marvell.com> - * Written-by: Prafulla Wadaskar <prafulla@marvell.com> + * Image manipulator for Marvell SoCs + * supports Kirkwood, Dove, Armada 370, and Armada XP + * + * (C) Copyright 2013 Thomas Petazzoni + * <thomas.petazzoni@free-electrons.com> * * SPDX-License-Identifier: GPL-2.0+ + * + * Not implemented: support for the register headers and secure + * headers in v1 images */ #include "imagetool.h" +#include <limits.h> #include <image.h> +#include <stdint.h> #include "kwbimage.h" -/* - * Supported commands for configuration file - */ -static table_entry_t kwbimage_cmds[] = { - {CMD_BOOT_FROM, "BOOT_FROM", "boot command", }, - {CMD_NAND_ECC_MODE, "NAND_ECC_MODE", "NAND mode", }, - {CMD_NAND_PAGE_SIZE, "NAND_PAGE_SIZE", "NAND size", }, - {CMD_SATA_PIO_MODE, "SATA_PIO_MODE", "SATA mode", }, - {CMD_DDR_INIT_DELAY, "DDR_INIT_DELAY", "DDR init dly", }, - {CMD_DATA, "DATA", "Reg Write Data", }, - {CMD_INVALID, "", "", }, +#define ALIGN_SUP(x, a) (((x) + (a - 1)) & ~(a - 1)) + +/* Structure of the main header, version 0 (Kirkwood, Dove) */ +struct main_hdr_v0 { + uint8_t blockid; /*0 */ + uint8_t nandeccmode; /*1 */ + uint16_t nandpagesize; /*2-3 */ + uint32_t blocksize; /*4-7 */ + uint32_t rsvd1; /*8-11 */ + uint32_t srcaddr; /*12-15 */ + uint32_t destaddr; /*16-19 */ + uint32_t execaddr; /*20-23 */ + uint8_t satapiomode; /*24 */ + uint8_t rsvd3; /*25 */ + uint16_t ddrinitdelay; /*26-27 */ + uint16_t rsvd2; /*28-29 */ + uint8_t ext; /*30 */ + uint8_t checksum; /*31 */ +}; + +struct ext_hdr_v0_reg { + uint32_t raddr; + uint32_t rdata; +}; + +#define EXT_HDR_V0_REG_COUNT ((0x1dc - 0x20) / sizeof(struct ext_hdr_v0_reg)) + +struct ext_hdr_v0 { + uint32_t offset; + uint8_t reserved[0x20 - sizeof(uint32_t)]; + struct ext_hdr_v0_reg rcfg[EXT_HDR_V0_REG_COUNT]; + uint8_t reserved2[7]; + uint8_t checksum; +}; + +/* Structure of the main header, version 1 (Armada 370, Armada XP) */ +struct main_hdr_v1 { + uint8_t blockid; /* 0 */ + uint8_t reserved1; /* 1 */ + uint16_t reserved2; /* 2-3 */ + uint32_t blocksize; /* 4-7 */ + uint8_t version; /* 8 */ + uint8_t headersz_msb; /* 9 */ + uint16_t headersz_lsb; /* A-B */ + uint32_t srcaddr; /* C-F */ + uint32_t destaddr; /* 10-13 */ + uint32_t execaddr; /* 14-17 */ + uint8_t reserved3; /* 18 */ + uint8_t nandblocksize; /* 19 */ + uint8_t nandbadblklocation; /* 1A */ + uint8_t reserved4; /* 1B */ + uint16_t reserved5; /* 1C-1D */ + uint8_t ext; /* 1E */ + uint8_t checksum; /* 1F */ }; /* - * Supported Boot options for configuration file + * Header for the optional headers, version 1 (Armada 370, Armada XP) */ -static table_entry_t kwbimage_bootops[] = { - {IBR_HDR_SPI_ID, "spi", "SPI Flash", }, - {IBR_HDR_NAND_ID, "nand", "NAND Flash", }, - {IBR_HDR_SATA_ID, "sata", "Sata port", }, - {IBR_HDR_PEX_ID, "pex", "PCIe port", }, - {IBR_HDR_UART_ID, "uart", "Serial port", }, - {-1, "", "Invalid", }, +struct opt_hdr_v1 { + uint8_t headertype; + uint8_t headersz_msb; + uint16_t headersz_lsb; + char data[0]; }; /* - * Supported NAND ecc options configuration file + * Various values for the opt_hdr_v1->headertype field, describing the + * different types of optional headers. The "secure" header contains + * informations related to secure boot (encryption keys, etc.). The + * "binary" header contains ARM binary code to be executed prior to + * executing the main payload (usually the bootloader). This is + * typically used to execute DDR3 training code. The "register" header + * allows to describe a set of (address, value) tuples that are + * generally used to configure the DRAM controller. */ -static table_entry_t kwbimage_eccmodes[] = { - {IBR_HDR_ECC_DEFAULT, "default", "Default mode", }, - {IBR_HDR_ECC_FORCED_HAMMING, "hamming", "Hamming mode", }, - {IBR_HDR_ECC_FORCED_RS, "rs", "RS mode", }, - {IBR_HDR_ECC_DISABLED, "disabled", "ECC Disabled", }, - {-1, "", "", }, +#define OPT_HDR_V1_SECURE_TYPE 0x1 +#define OPT_HDR_V1_BINARY_TYPE 0x2 +#define OPT_HDR_V1_REGISTER_TYPE 0x3 + +#define KWBHEADER_V1_SIZE(hdr) \ + (((hdr)->headersz_msb << 16) | (hdr)->headersz_lsb) + +static struct image_cfg_element *image_cfg; +static int cfgn; + +struct boot_mode { + unsigned int id; + const char *name; +}; + +struct boot_mode boot_modes[] = { + { 0x4D, "i2c" }, + { 0x5A, "spi" }, + { 0x8B, "nand" }, + { 0x78, "sata" }, + { 0x9C, "pex" }, + { 0x69, "uart" }, + {}, +}; + +struct nand_ecc_mode { + unsigned int id; + const char *name; +}; + +struct nand_ecc_mode nand_ecc_modes[] = { + { 0x00, "default" }, + { 0x01, "hamming" }, + { 0x02, "rs" }, + { 0x03, "disabled" }, + {}, +}; + +/* Used to identify an undefined execution or destination address */ +#define ADDR_INVALID ((uint32_t)-1) + +#define BINARY_MAX_ARGS 8 + +/* In-memory representation of a line of the configuration file */ +struct image_cfg_element { + enum { + IMAGE_CFG_VERSION = 0x1, + IMAGE_CFG_BOOT_FROM, + IMAGE_CFG_DEST_ADDR, + IMAGE_CFG_EXEC_ADDR, + IMAGE_CFG_NAND_BLKSZ, + IMAGE_CFG_NAND_BADBLK_LOCATION, + IMAGE_CFG_NAND_ECC_MODE, + IMAGE_CFG_NAND_PAGESZ, + IMAGE_CFG_BINARY, + IMAGE_CFG_PAYLOAD, + IMAGE_CFG_DATA, + } type; + union { + unsigned int version; + unsigned int bootfrom; + struct { + const char *file; + unsigned int args[BINARY_MAX_ARGS]; + unsigned int nargs; + } binary; + const char *payload; + unsigned int dstaddr; + unsigned int execaddr; + unsigned int nandblksz; + unsigned int nandbadblklocation; + unsigned int nandeccmode; + unsigned int nandpagesz; + struct ext_hdr_v0_reg regdata; + }; }; -static struct kwb_header kwbimage_header; -static int datacmd_cnt = 0; -static char * fname = "Unknown"; -static int lineno = -1; +#define IMAGE_CFG_ELEMENT_MAX 256 /* - * Report Error if xflag is set in addition to default + * Byte 8 of the image header contains the version number. In the v0 + * header, byte 8 was reserved, and always set to 0. In the v1 header, + * byte 8 has been changed to a proper field, set to 1. */ -static int kwbimage_check_params(struct image_tool_params *params) +static unsigned int image_version(void *header) { - if (!strlen (params->imagename)) { - printf ("Error:%s - Configuration file not specified, " - "it is needed for kwbimage generation\n", - params->cmdname); - return CFG_INVALID; - } - return ((params->dflag && (params->fflag || params->lflag)) || - (params->fflag && (params->dflag || params->lflag)) || - (params->lflag && (params->dflag || params->fflag)) || - (params->xflag) || !(strlen (params->imagename))); + unsigned char *ptr = header; + return ptr[8]; +} + +/* + * Utility functions to manipulate boot mode and ecc modes (convert + * them back and forth between description strings and the + * corresponding numerical identifiers). + */ + +static const char *image_boot_mode_name(unsigned int id) +{ + int i; + for (i = 0; boot_modes[i].name; i++) + if (boot_modes[i].id == id) + return boot_modes[i].name; + return NULL; } -static uint32_t check_get_hexval (char *token) +int image_boot_mode_id(const char *boot_mode_name) { - uint32_t hexval; + int i; + for (i = 0; boot_modes[i].name; i++) + if (!strcmp(boot_modes[i].name, boot_mode_name)) + return boot_modes[i].id; + + return -1; +} + +int image_nand_ecc_mode_id(const char *nand_ecc_mode_name) +{ + int i; + for (i = 0; nand_ecc_modes[i].name; i++) + if (!strcmp(nand_ecc_modes[i].name, nand_ecc_mode_name)) + return nand_ecc_modes[i].id; + return -1; +} + +static struct image_cfg_element * +image_find_option(unsigned int optiontype) +{ + int i; - if (!sscanf (token, "%x", &hexval)) { - printf ("Error:%s[%d] - Invalid hex data(%s)\n", fname, - lineno, token); - exit (EXIT_FAILURE); + for (i = 0; i < cfgn; i++) { + if (image_cfg[i].type == optiontype) + return &image_cfg[i]; } - return hexval; + + return NULL; +} + +static unsigned int +image_count_options(unsigned int optiontype) +{ + int i; + unsigned int count = 0; + + for (i = 0; i < cfgn; i++) + if (image_cfg[i].type == optiontype) + count++; + + return count; } /* - * Generates 8 bit checksum + * Compute a 8-bit checksum of a memory area. This algorithm follows + * the requirements of the Marvell SoC BootROM specifications. */ -static uint8_t kwbimage_checksum8 (void *start, uint32_t len, uint8_t csum) +static uint8_t image_checksum8(void *start, uint32_t len) { - register uint8_t sum = csum; - volatile uint8_t *p = (volatile uint8_t *)start; + uint8_t csum = 0; + uint8_t *p = start; /* check len and return zero checksum if invalid */ if (!len) return 0; do { - sum += *p; + csum += *p; p++; } while (--len); - return (sum); + + return csum; } -/* - * Generates 32 bit checksum - */ -static uint32_t kwbimage_checksum32 (uint32_t *start, uint32_t len, uint32_t csum) +static uint32_t image_checksum32(void *start, uint32_t len) { - register uint32_t sum = csum; - volatile uint32_t *p = start; + uint32_t csum = 0; + uint32_t *p = start; /* check len and return zero checksum if invalid */ if (!len) return 0; if (len % sizeof(uint32_t)) { - printf ("Error:%s[%d] - length is not in multiple of %zu\n", - __FUNCTION__, len, sizeof(uint32_t)); + fprintf(stderr, "Length %d is not in multiple of %zu\n", + len, sizeof(uint32_t)); return 0; } do { - sum += *p; + csum += *p; p++; len -= sizeof(uint32_t); } while (len > 0); - return (sum); + + return csum; } -static void kwbimage_check_cfgdata (char *token, enum kwbimage_cmd cmdsw, - struct kwb_header *kwbhdr) +static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, + int payloadsz) { - bhr_t *mhdr = &kwbhdr->kwb_hdr; - extbhr_t *exthdr = &kwbhdr->kwb_exthdr; - int i; + struct image_cfg_element *e; + size_t headersz; + struct main_hdr_v0 *main_hdr; + struct ext_hdr_v0 *ext_hdr; + void *image; + int has_ext = 0; + + /* + * Calculate the size of the header and the size of the + * payload + */ + headersz = sizeof(struct main_hdr_v0); + + if (image_count_options(IMAGE_CFG_DATA) > 0) { + has_ext = 1; + headersz += sizeof(struct ext_hdr_v0); + } - switch (cmdsw) { - case CMD_BOOT_FROM: - i = get_table_entry_id (kwbimage_bootops, - "Kwbimage boot option", token); + if (image_count_options(IMAGE_CFG_PAYLOAD) > 1) { + fprintf(stderr, "More than one payload, not possible\n"); + return NULL; + } - if (i < 0) - goto INVL_DATA; + image = malloc(headersz); + if (!image) { + fprintf(stderr, "Cannot allocate memory for image\n"); + return NULL; + } - mhdr->blockid = i; - printf ("Preparing kirkwood boot image to boot " - "from %s\n", token); - break; - case CMD_NAND_ECC_MODE: - i = get_table_entry_id (kwbimage_eccmodes, - "NAND ecc mode", token); + memset(image, 0, headersz); + + main_hdr = image; + + /* Fill in the main header */ + main_hdr->blocksize = payloadsz + sizeof(uint32_t) - headersz; + main_hdr->srcaddr = headersz; + main_hdr->ext = has_ext; + main_hdr->destaddr = params->addr; + main_hdr->execaddr = params->ep; + + e = image_find_option(IMAGE_CFG_BOOT_FROM); + if (e) + main_hdr->blockid = e->bootfrom; + e = image_find_option(IMAGE_CFG_NAND_ECC_MODE); + if (e) + main_hdr->nandeccmode = e->nandeccmode; + e = image_find_option(IMAGE_CFG_NAND_PAGESZ); + if (e) + main_hdr->nandpagesize = e->nandpagesz; + main_hdr->checksum = image_checksum8(image, + sizeof(struct main_hdr_v0)); + + /* Generate the ext header */ + if (has_ext) { + int cfgi, datai; + + ext_hdr = image + sizeof(struct main_hdr_v0); + ext_hdr->offset = 0x40; + + for (cfgi = 0, datai = 0; cfgi < cfgn; cfgi++) { + e = &image_cfg[cfgi]; + if (e->type != IMAGE_CFG_DATA) + continue; + + ext_hdr->rcfg[datai].raddr = e->regdata.raddr; + ext_hdr->rcfg[datai].rdata = e->regdata.rdata; + datai++; + } - if (i < 0) - goto INVL_DATA; + ext_hdr->checksum = image_checksum8(ext_hdr, + sizeof(struct ext_hdr_v0)); + } - mhdr->nandeccmode = i; - printf ("Nand ECC mode = %s\n", token); - break; - case CMD_NAND_PAGE_SIZE: - mhdr->nandpagesize = - (uint16_t) check_get_hexval (token); - printf ("Nand page size = 0x%x\n", mhdr->nandpagesize); - break; - case CMD_SATA_PIO_MODE: - mhdr->satapiomode = - (uint8_t) check_get_hexval (token); - printf ("Sata PIO mode = 0x%x\n", - mhdr->satapiomode); - break; - case CMD_DDR_INIT_DELAY: - mhdr->ddrinitdelay = - (uint16_t) check_get_hexval (token); - printf ("DDR init delay = %d msec\n", mhdr->ddrinitdelay); - break; - case CMD_DATA: - exthdr->rcfg[datacmd_cnt].raddr = - check_get_hexval (token); + *imagesz = headersz; + return image; +} - break; - case CMD_INVALID: - goto INVL_DATA; - default: - goto INVL_DATA; +static size_t image_headersz_v1(struct image_tool_params *params, + int *hasext) +{ + struct image_cfg_element *binarye; + size_t headersz; + int ret; + + /* + * Calculate the size of the header and the size of the + * payload + */ + headersz = sizeof(struct main_hdr_v1); + + if (image_count_options(IMAGE_CFG_BINARY) > 1) { + fprintf(stderr, "More than one binary blob, not supported\n"); + return 0; } - return; -INVL_DATA: - printf ("Error:%s[%d] - Invalid data\n", fname, lineno); - exit (EXIT_FAILURE); + if (image_count_options(IMAGE_CFG_PAYLOAD) > 1) { + fprintf(stderr, "More than one payload, not possible\n"); + return 0; + } + + binarye = image_find_option(IMAGE_CFG_BINARY); + if (binarye) { + struct stat s; + + ret = stat(binarye->binary.file, &s); + if (ret < 0) { + char cwd[PATH_MAX]; + char *dir = cwd; + + memset(cwd, 0, sizeof(cwd)); + if (!getcwd(cwd, sizeof(cwd))) { + dir = "current working directory"; + perror("getcwd() failed"); + } + + fprintf(stderr, + "Didn't find the file '%s' in '%s' which is mandatory to generate the image\n" + "This file generally contains the DDR3 training code, and should be extracted from an existing bootable\n" + "image for your board. See 'kwbimage -x' to extract it from an existing image.\n", + binarye->binary.file, dir); + return 0; + } + + headersz += s.st_size + + binarye->binary.nargs * sizeof(unsigned int); + if (hasext) + *hasext = 1; + } + + /* + * The payload should be aligned on some reasonable + * boundary + */ + return ALIGN_SUP(headersz, 4096); } -/* - * this function sets the kwbimage header by- - * 1. Abstracting input command line arguments data - * 2. parses the kwbimage configuration file and update extebded header data - * 3. calculates header, extended header and image checksums - */ -static void kwdimage_set_ext_header (struct kwb_header *kwbhdr, char* name) { - bhr_t *mhdr = &kwbhdr->kwb_hdr; - extbhr_t *exthdr = &kwbhdr->kwb_exthdr; - FILE *fd = NULL; - int j; - char *line = NULL; - char * token, *saveptr1, *saveptr2; - size_t len = 0; - enum kwbimage_cmd cmd; - - fname = name; - /* set dram register offset */ - exthdr->dramregsoffs = (intptr_t)&exthdr->rcfg - (intptr_t)mhdr; - - if ((fd = fopen (name, "r")) == 0) { - printf ("Error:%s - Can't open\n", fname); - exit (EXIT_FAILURE); +static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, + int payloadsz) +{ + struct image_cfg_element *e, *binarye; + struct main_hdr_v1 *main_hdr; + size_t headersz; + void *image, *cur; + int hasext = 0; + int ret; + + /* + * Calculate the size of the header and the size of the + * payload + */ + headersz = image_headersz_v1(params, &hasext); + if (headersz == 0) + return NULL; + + image = malloc(headersz); + if (!image) { + fprintf(stderr, "Cannot allocate memory for image\n"); + return NULL; } - /* Simple kwimage.cfg file parser */ - lineno=0; - while ((getline (&line, &len, fd)) > 0) { - lineno++; - token = strtok_r (line, "\r\n", &saveptr1); - /* drop all lines with zero tokens (= empty lines) */ - if (token == NULL) - continue; + memset(image, 0, headersz); + + cur = main_hdr = image; + cur += sizeof(struct main_hdr_v1); + + /* Fill the main header */ + main_hdr->blocksize = payloadsz - headersz + sizeof(uint32_t); + main_hdr->headersz_lsb = headersz & 0xFFFF; + main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16; + main_hdr->destaddr = params->addr; + main_hdr->execaddr = params->ep; + main_hdr->srcaddr = headersz; + main_hdr->ext = hasext; + main_hdr->version = 1; + e = image_find_option(IMAGE_CFG_BOOT_FROM); + if (e) + main_hdr->blockid = e->bootfrom; + e = image_find_option(IMAGE_CFG_NAND_BLKSZ); + if (e) + main_hdr->nandblocksize = e->nandblksz / (64 * 1024); + e = image_find_option(IMAGE_CFG_NAND_BADBLK_LOCATION); + if (e) + main_hdr->nandbadblklocation = e->nandbadblklocation; + + binarye = image_find_option(IMAGE_CFG_BINARY); + if (binarye) { + struct opt_hdr_v1 *hdr = cur; + unsigned int *args; + size_t binhdrsz; + struct stat s; + int argi; + FILE *bin; + + hdr->headertype = OPT_HDR_V1_BINARY_TYPE; + + bin = fopen(binarye->binary.file, "r"); + if (!bin) { + fprintf(stderr, "Cannot open binary file %s\n", + binarye->binary.file); + return NULL; + } - for (j = 0, cmd = CMD_INVALID, line = token; ; line = NULL) { - token = strtok_r (line, " \t", &saveptr2); - if (token == NULL) - break; - /* Drop all text starting with '#' as comments */ - if (token[0] == '#') - break; + fstat(fileno(bin), &s); - /* Process rest as valid config command line */ - switch (j) { - case CFG_COMMAND: - cmd = get_table_entry_id (kwbimage_cmds, - "Kwbimage command", token); + binhdrsz = sizeof(struct opt_hdr_v1) + + (binarye->binary.nargs + 1) * sizeof(unsigned int) + + s.st_size; + hdr->headersz_lsb = binhdrsz & 0xFFFF; + hdr->headersz_msb = (binhdrsz & 0xFFFF0000) >> 16; - if (cmd == CMD_INVALID) - goto INVL_CMD; - break; + cur += sizeof(struct opt_hdr_v1); - case CFG_DATA0: - kwbimage_check_cfgdata (token, cmd, kwbhdr); - break; + args = cur; + *args = binarye->binary.nargs; + args++; + for (argi = 0; argi < binarye->binary.nargs; argi++) + args[argi] = binarye->binary.args[argi]; - case CFG_DATA1: - if (cmd != CMD_DATA) - goto INVL_CMD; - - exthdr->rcfg[datacmd_cnt].rdata = - check_get_hexval (token); - - if (datacmd_cnt > KWBIMAGE_MAX_CONFIG ) { - printf ("Error:%s[%d] - Found more " - "than max(%zd) allowed " - "data configurations\n", - fname, lineno, - KWBIMAGE_MAX_CONFIG); - exit (EXIT_FAILURE); - } else - datacmd_cnt++; - break; + cur += (binarye->binary.nargs + 1) * sizeof(unsigned int); + + ret = fread(cur, s.st_size, 1, bin); + if (ret != 1) { + fprintf(stderr, + "Could not read binary image %s\n", + binarye->binary.file); + return NULL; + } + + fclose(bin); - default: - goto INVL_CMD; + cur += s.st_size; + + /* + * For now, we don't support more than one binary + * header, and no other header types are + * supported. So, the binary header is necessarily the + * last one + */ + *((unsigned char *)cur) = 0; + + cur += sizeof(uint32_t); + } + + /* Calculate and set the header checksum */ + main_hdr->checksum = image_checksum8(main_hdr, headersz); + + *imagesz = headersz; + return image; +} + +static int image_create_config_parse_oneline(char *line, + struct image_cfg_element *el) +{ + char *keyword, *saveptr; + char deliminiters[] = " \t"; + + keyword = strtok_r(line, deliminiters, &saveptr); + if (!strcmp(keyword, "VERSION")) { + char *value = strtok_r(NULL, deliminiters, &saveptr); + el->type = IMAGE_CFG_VERSION; + el->version = atoi(value); + } else if (!strcmp(keyword, "BOOT_FROM")) { + char *value = strtok_r(NULL, deliminiters, &saveptr); + el->type = IMAGE_CFG_BOOT_FROM; + el->bootfrom = image_boot_mode_id(value); + if (el->bootfrom < 0) { + fprintf(stderr, + "Invalid boot media '%s'\n", value); + return -1; + } + } else if (!strcmp(keyword, "NAND_BLKSZ")) { + char *value = strtok_r(NULL, deliminiters, &saveptr); + el->type = IMAGE_CFG_NAND_BLKSZ; + el->nandblksz = strtoul(value, NULL, 16); + } else if (!strcmp(keyword, "NAND_BADBLK_LOCATION")) { + char *value = strtok_r(NULL, deliminiters, &saveptr); + el->type = IMAGE_CFG_NAND_BADBLK_LOCATION; + el->nandbadblklocation = + strtoul(value, NULL, 16); + } else if (!strcmp(keyword, "NAND_ECC_MODE")) { + char *value = strtok_r(NULL, deliminiters, &saveptr); + el->type = IMAGE_CFG_NAND_ECC_MODE; + el->nandeccmode = image_nand_ecc_mode_id(value); + if (el->nandeccmode < 0) { + fprintf(stderr, + "Invalid NAND ECC mode '%s'\n", value); + return -1; + } + } else if (!strcmp(keyword, "NAND_PAGE_SIZE")) { + char *value = strtok_r(NULL, deliminiters, &saveptr); + el->type = IMAGE_CFG_NAND_PAGESZ; + el->nandpagesz = strtoul(value, NULL, 16); + } else if (!strcmp(keyword, "BINARY")) { + char *value = strtok_r(NULL, deliminiters, &saveptr); + int argi = 0; + + el->type = IMAGE_CFG_BINARY; + el->binary.file = strdup(value); + while (1) { + value = strtok_r(NULL, deliminiters, &saveptr); + if (!value) + break; + el->binary.args[argi] = strtoul(value, NULL, 16); + argi++; + if (argi >= BINARY_MAX_ARGS) { + fprintf(stderr, + "Too many argument for binary\n"); + return -1; } - j++; } + el->binary.nargs = argi; + } else if (!strcmp(keyword, "DATA")) { + char *value1 = strtok_r(NULL, deliminiters, &saveptr); + char *value2 = strtok_r(NULL, deliminiters, &saveptr); + + if (!value1 || !value2) { + fprintf(stderr, + "Invalid number of arguments for DATA\n"); + return -1; + } + + el->type = IMAGE_CFG_DATA; + el->regdata.raddr = strtoul(value1, NULL, 16); + el->regdata.rdata = strtoul(value2, NULL, 16); + } else { + fprintf(stderr, "Ignoring unknown line '%s'\n", line); } - if (line) - free (line); - fclose (fd); - return; + return 0; +} /* - * Invalid Command error reporring - * - * command CMD_DATA needs three strings on a line - * whereas other commands need only two. - * - * if more than two/three (as per command type) are observed, - * then error will be reported + * Parse the configuration file 'fcfg' into the array of configuration + * elements 'image_cfg', and return the number of configuration + * elements in 'cfgn'. */ -INVL_CMD: - printf ("Error:%s[%d] - Invalid command\n", fname, lineno); - exit (EXIT_FAILURE); +static int image_create_config_parse(FILE *fcfg) +{ + int ret; + int cfgi = 0; + + /* Parse the configuration file */ + while (!feof(fcfg)) { + char *line; + char buf[256]; + + /* Read the current line */ + memset(buf, 0, sizeof(buf)); + line = fgets(buf, sizeof(buf), fcfg); + if (!line) + break; + + /* Ignore useless lines */ + if (line[0] == '\n' || line[0] == '#') + continue; + + /* Strip final newline */ + if (line[strlen(line) - 1] == '\n') + line[strlen(line) - 1] = 0; + + /* Parse the current line */ + ret = image_create_config_parse_oneline(line, + &image_cfg[cfgi]); + if (ret) + return ret; + + cfgi++; + + if (cfgi >= IMAGE_CFG_ELEMENT_MAX) { + fprintf(stderr, + "Too many configuration elements in .cfg file\n"); + return -1; + } + } + + cfgn = cfgi; + return 0; +} + +static int image_get_version(void) +{ + struct image_cfg_element *e; + + e = image_find_option(IMAGE_CFG_VERSION); + if (!e) + return -1; + + return e->version; +} + +static int image_version_file(const char *input) +{ + FILE *fcfg; + int version; + int ret; + + fcfg = fopen(input, "r"); + if (!fcfg) { + fprintf(stderr, "Could not open input file %s\n", input); + return -1; + } + + image_cfg = malloc(IMAGE_CFG_ELEMENT_MAX * + sizeof(struct image_cfg_element)); + if (!image_cfg) { + fprintf(stderr, "Cannot allocate memory\n"); + fclose(fcfg); + return -1; + } + + memset(image_cfg, 0, + IMAGE_CFG_ELEMENT_MAX * sizeof(struct image_cfg_element)); + rewind(fcfg); + + ret = image_create_config_parse(fcfg); + fclose(fcfg); + if (ret) { + free(image_cfg); + return -1; + } + + version = image_get_version(); + /* Fallback to version 0 is no version is provided in the cfg file */ + if (version == -1) + version = 0; + + free(image_cfg); + + return version; } -static void kwbimage_set_header (void *ptr, struct stat *sbuf, int ifd, +static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, struct image_tool_params *params) { - struct kwb_header *hdr = (struct kwb_header *)ptr; - bhr_t *mhdr = &hdr->kwb_hdr; - extbhr_t *exthdr = &hdr->kwb_exthdr; + FILE *fcfg; + void *image = NULL; + int version; + size_t headersz; uint32_t checksum; + int ret; int size; - /* Build and add image checksum header */ - checksum = kwbimage_checksum32 ((uint32_t *)ptr, sbuf->st_size, 0); + fcfg = fopen(params->imagename, "r"); + if (!fcfg) { + fprintf(stderr, "Could not open input file %s\n", + params->imagename); + exit(EXIT_FAILURE); + } - size = write (ifd, &checksum, sizeof(uint32_t)); + image_cfg = malloc(IMAGE_CFG_ELEMENT_MAX * + sizeof(struct image_cfg_element)); + if (!image_cfg) { + fprintf(stderr, "Cannot allocate memory\n"); + fclose(fcfg); + exit(EXIT_FAILURE); + } + + memset(image_cfg, 0, + IMAGE_CFG_ELEMENT_MAX * sizeof(struct image_cfg_element)); + rewind(fcfg); + + ret = image_create_config_parse(fcfg); + fclose(fcfg); + if (ret) { + free(image_cfg); + exit(EXIT_FAILURE); + } + + version = image_get_version(); + switch (version) { + /* + * Fallback to version 0 if no version is provided in the + * cfg file + */ + case -1: + case 0: + image = image_create_v0(&headersz, params, sbuf->st_size); + break; + + case 1: + image = image_create_v1(&headersz, params, sbuf->st_size); + break; + + default: + fprintf(stderr, "Unsupported version %d\n", version); + free(image_cfg); + exit(EXIT_FAILURE); + } + + if (!image) { + fprintf(stderr, "Could not create image\n"); + free(image_cfg); + exit(EXIT_FAILURE); + } + + free(image_cfg); + + /* Build and add image checksum header */ + checksum = image_checksum32((uint32_t *)ptr, sbuf->st_size); + size = write(ifd, &checksum, sizeof(uint32_t)); if (size != sizeof(uint32_t)) { - printf ("Error:%s - Checksum write %d bytes %s\n", + fprintf(stderr, "Error:%s - Checksum write %d bytes %s\n", params->cmdname, size, params->imagefile); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } sbuf->st_size += sizeof(uint32_t); - mhdr->blocksize = sbuf->st_size - sizeof(struct kwb_header); - mhdr->srcaddr = sizeof(struct kwb_header); - mhdr->destaddr= params->addr; - mhdr->execaddr =params->ep; - mhdr->ext = 0x1; /* header extension appended */ - - kwdimage_set_ext_header (hdr, params->imagename); - /* calculate checksums */ - mhdr->checkSum = kwbimage_checksum8 ((void *)mhdr, sizeof(bhr_t), 0); - exthdr->checkSum = kwbimage_checksum8 ((void *)exthdr, - sizeof(extbhr_t), 0); -} - -static int kwbimage_verify_header (unsigned char *ptr, int image_size, - struct image_tool_params *params) -{ - struct kwb_header *hdr = (struct kwb_header *)ptr; - bhr_t *mhdr = &hdr->kwb_hdr; - extbhr_t *exthdr = &hdr->kwb_exthdr; - uint8_t calc_hdrcsum; - uint8_t calc_exthdrcsum; - - calc_hdrcsum = kwbimage_checksum8 ((void *)mhdr, - sizeof(bhr_t) - sizeof(uint8_t), 0); - if (calc_hdrcsum != mhdr->checkSum) - return -FDT_ERR_BADSTRUCTURE; /* mhdr csum not matched */ - - calc_exthdrcsum = kwbimage_checksum8 ((void *)exthdr, - sizeof(extbhr_t) - sizeof(uint8_t), 0); - if (calc_exthdrcsum != exthdr->checkSum) - return -FDT_ERR_BADSTRUCTURE; /* exthdr csum not matched */ + /* Finally copy the header into the image area */ + memcpy(ptr, image, headersz); - return 0; + free(image); } -static void kwbimage_print_header (const void *ptr) +static void kwbimage_print_header(const void *ptr) { - struct kwb_header *hdr = (struct kwb_header *) ptr; - bhr_t *mhdr = &hdr->kwb_hdr; - char *name = get_table_entry_name (kwbimage_bootops, - "Kwbimage boot option", - (int) mhdr->blockid); - - printf ("Image Type: Kirkwood Boot from %s Image\n", name); - printf ("Data Size: "); - genimg_print_size (mhdr->blocksize - sizeof(uint32_t)); - printf ("Load Address: %08x\n", mhdr->destaddr); - printf ("Entry Point: %08x\n", mhdr->execaddr); + struct main_hdr_v0 *mhdr = (struct main_hdr_v0 *)ptr; + + printf("Image Type: MVEBU Boot from %s Image\n", + image_boot_mode_name(mhdr->blockid)); + printf("Image version:%d\n", image_version((void *)ptr)); + printf("Data Size: "); + genimg_print_size(mhdr->blocksize - sizeof(uint32_t)); + printf("Load Address: %08x\n", mhdr->destaddr); + printf("Entry Point: %08x\n", mhdr->execaddr); } -static int kwbimage_check_image_types (uint8_t type) +static int kwbimage_check_image_types(uint8_t type) { if (type == IH_TYPE_KWBIMAGE) return EXIT_SUCCESS; @@ -366,18 +826,93 @@ static int kwbimage_check_image_types (uint8_t type) return EXIT_FAILURE; } +static int kwbimage_verify_header(unsigned char *ptr, int image_size, + struct image_tool_params *params) +{ + struct main_hdr_v0 *main_hdr; + struct ext_hdr_v0 *ext_hdr; + uint8_t checksum; + + main_hdr = (void *)ptr; + checksum = image_checksum8(ptr, + sizeof(struct main_hdr_v0) + - sizeof(uint8_t)); + if (checksum != main_hdr->checksum) + return -FDT_ERR_BADSTRUCTURE; + + /* Only version 0 extended header has checksum */ + if (image_version((void *)ptr) == 0) { + ext_hdr = (void *)ptr + sizeof(struct main_hdr_v0); + checksum = image_checksum8(ext_hdr, + sizeof(struct ext_hdr_v0) + - sizeof(uint8_t)); + if (checksum != ext_hdr->checksum) + return -FDT_ERR_BADSTRUCTURE; + } + + return 0; +} + +static int kwbimage_generate(struct image_tool_params *params, + struct image_type_params *tparams) +{ + int alloc_len; + void *hdr; + int version = 0; + + version = image_version_file(params->imagename); + if (version == 0) { + alloc_len = sizeof(struct main_hdr_v0) + + sizeof(struct ext_hdr_v0); + } else { + alloc_len = image_headersz_v1(params, NULL); + } + + hdr = malloc(alloc_len); + if (!hdr) { + fprintf(stderr, "%s: malloc return failure: %s\n", + params->cmdname, strerror(errno)); + exit(EXIT_FAILURE); + } + + memset(hdr, 0, alloc_len); + tparams->header_size = alloc_len; + tparams->hdr = hdr; + + return 0; +} + +/* + * Report Error if xflag is set in addition to default + */ +static int kwbimage_check_params(struct image_tool_params *params) +{ + if (!strlen(params->imagename)) { + fprintf(stderr, "Error:%s - Configuration file not specified, " + "it is needed for kwbimage generation\n", + params->cmdname); + return CFG_INVALID; + } + + return (params->dflag && (params->fflag || params->lflag)) || + (params->fflag && (params->dflag || params->lflag)) || + (params->lflag && (params->dflag || params->fflag)) || + (params->xflag) || !(strlen(params->imagename)); +} + /* * kwbimage type parameters definition */ static struct image_type_params kwbimage_params = { - .name = "Kirkwood Boot Image support", - .header_size = sizeof(struct kwb_header), - .hdr = (void*)&kwbimage_header, + .name = "Marvell MVEBU Boot Image support", + .header_size = 0, /* no fixed header size */ + .hdr = NULL, + .vrec_header = kwbimage_generate, .check_image_type = kwbimage_check_image_types, - .verify_header = kwbimage_verify_header, - .print_header = kwbimage_print_header, - .set_header = kwbimage_set_header, - .check_params = kwbimage_check_params, + .verify_header = kwbimage_verify_header, + .print_header = kwbimage_print_header, + .set_header = kwbimage_set_header, + .check_params = kwbimage_check_params, }; void init_kwb_image_type (void) diff --git a/tools/kwboot.c b/tools/kwboot.c index e773f01df3..1368b4c948 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -1,5 +1,6 @@ /* - * Boot a Marvell Kirkwood SoC, with Xmodem over UART0. + * Boot a Marvell SoC, with Xmodem over UART0. + * supports Kirkwood, Dove, Armada 370, Armada XP * * (c) 2012 Daniel Stodden <daniel.stodden@gmail.com> * @@ -37,9 +38,18 @@ static unsigned char kwboot_msg_boot[] = { 0xBB, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }; +static unsigned char kwboot_msg_debug[] = { + 0xDD, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 +}; + +/* Defines known to work on Kirkwood */ #define KWBOOT_MSG_REQ_DELAY 10 /* ms */ #define KWBOOT_MSG_RSP_TIMEO 50 /* ms */ +/* Defines known to work on Armada XP */ +#define KWBOOT_MSG_REQ_DELAY_AXP 1000 /* ms */ +#define KWBOOT_MSG_RSP_TIMEO_AXP 1000 /* ms */ + /* * Xmodem Transfers */ @@ -62,6 +72,9 @@ struct kwboot_block { static int kwboot_verbose; +static int msg_req_delay = KWBOOT_MSG_REQ_DELAY; +static int msg_rsp_timeo = KWBOOT_MSG_RSP_TIMEO; + static void kwboot_printv(const char *fmt, ...) { @@ -184,6 +197,9 @@ kwboot_tty_send(int fd, const void *buf, size_t len) int rc; ssize_t n; + if (!buf) + return 0; + rc = -1; do { @@ -268,7 +284,10 @@ kwboot_bootmsg(int tty, void *msg) int rc; char c; - kwboot_printv("Sending boot message. Please reboot the target..."); + if (msg == NULL) + kwboot_printv("Please reboot the target into UART boot mode..."); + else + kwboot_printv("Sending boot message. Please reboot the target..."); do { rc = tcflush(tty, TCIOFLUSH); @@ -277,11 +296,11 @@ kwboot_bootmsg(int tty, void *msg) rc = kwboot_tty_send(tty, msg, 8); if (rc) { - usleep(KWBOOT_MSG_REQ_DELAY * 1000); + usleep(msg_req_delay * 1000); continue; } - rc = kwboot_tty_recv(tty, &c, 1, KWBOOT_MSG_RSP_TIMEO); + rc = kwboot_tty_recv(tty, &c, 1, msg_rsp_timeo); kwboot_spinner(); @@ -293,6 +312,37 @@ kwboot_bootmsg(int tty, void *msg) } static int +kwboot_debugmsg(int tty, void *msg) +{ + int rc; + + kwboot_printv("Sending debug message. Please reboot the target..."); + + do { + char buf[16]; + + rc = tcflush(tty, TCIOFLUSH); + if (rc) + break; + + rc = kwboot_tty_send(tty, msg, 8); + if (rc) { + usleep(msg_req_delay * 1000); + continue; + } + + rc = kwboot_tty_recv(tty, buf, 16, msg_rsp_timeo); + + kwboot_spinner(); + + } while (rc); + + kwboot_printv("\n"); + + return rc; +} + +static int kwboot_xm_makeblock(struct kwboot_block *block, const void *data, size_t size, int pnum) { @@ -300,6 +350,7 @@ kwboot_xm_makeblock(struct kwboot_block *block, const void *data, size_t n; int i; + block->soh = SOH; block->pnum = pnum; block->_pnum = ~block->pnum; @@ -326,9 +377,15 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block) if (rc) break; - rc = kwboot_tty_recv(fd, &c, 1, KWBOOT_BLK_RSP_TIMEO); - if (rc) - break; + do { + rc = kwboot_tty_recv(fd, &c, 1, KWBOOT_BLK_RSP_TIMEO); + if (rc) + break; + + if (c != ACK && c != NAK && c != CAN) + printf("%c", c); + + } while (c != ACK && c != NAK && c != CAN); if (c != ACK) kwboot_progress(-1, '+'); @@ -511,7 +568,6 @@ kwboot_mmap_image(const char *path, size_t *size, int prot) void *img; rc = -1; - fd = -1; img = NULL; fd = open(path, O_RDONLY); @@ -601,11 +657,16 @@ static void kwboot_usage(FILE *stream, char *progname) { fprintf(stream, - "Usage: %s -b <image> [ -p ] [ -t ] " - "[-B <baud> ] <TTY>\n", progname); + "Usage: %s [-d | -a | -b <image> | -D <image> ] [ -t ] [-B <baud> ] <TTY>\n", + progname); fprintf(stream, "\n"); - fprintf(stream, " -b <image>: boot <image>\n"); + fprintf(stream, + " -b <image>: boot <image> with preamble (Kirkwood, Armada 370/XP)\n"); fprintf(stream, " -p: patch <image> to type 0x69 (uart boot)\n"); + fprintf(stream, + " -D <image>: boot <image> without preamble (Dove)\n"); + fprintf(stream, " -d: enter debug mode\n"); + fprintf(stream, " -a: use timings for Armada XP\n"); fprintf(stream, "\n"); fprintf(stream, " -t: mini terminal\n"); fprintf(stream, "\n"); @@ -619,6 +680,7 @@ main(int argc, char **argv) const char *ttypath, *imgpath; int rv, rc, tty, term, prot, patch; void *bootmsg; + void *debugmsg; void *img; size_t size; speed_t speed; @@ -626,6 +688,7 @@ main(int argc, char **argv) rv = 1; tty = -1; bootmsg = NULL; + debugmsg = NULL; imgpath = NULL; img = NULL; term = 0; @@ -636,7 +699,7 @@ main(int argc, char **argv) kwboot_verbose = isatty(STDOUT_FILENO); do { - int c = getopt(argc, argv, "hb:ptB:"); + int c = getopt(argc, argv, "hb:ptaB:dD:"); if (c < 0) break; @@ -646,6 +709,15 @@ main(int argc, char **argv) imgpath = optarg; break; + case 'D': + bootmsg = NULL; + imgpath = optarg; + break; + + case 'd': + debugmsg = kwboot_msg_debug; + break; + case 'p': patch = 1; break; @@ -654,6 +726,11 @@ main(int argc, char **argv) term = 1; break; + case 'a': + msg_req_delay = KWBOOT_MSG_REQ_DELAY_AXP; + msg_rsp_timeo = KWBOOT_MSG_RSP_TIMEO_AXP; + break; + case 'B': speed = kwboot_tty_speed(atoi(optarg)); if (speed == -1) @@ -667,7 +744,7 @@ main(int argc, char **argv) } } while (1); - if (!bootmsg && !term) + if (!bootmsg && !term && !debugmsg) goto usage; if (patch && !imgpath) @@ -702,7 +779,13 @@ main(int argc, char **argv) } } - if (bootmsg) { + if (debugmsg) { + rc = kwboot_debugmsg(tty, debugmsg); + if (rc) { + perror("debugmsg"); + goto out; + } + } else { rc = kwboot_bootmsg(tty, bootmsg); if (rc) { perror("bootmsg"); diff --git a/tools/socfpgaimage.c b/tools/socfpgaimage.c index 396d8a5472..917873e7b3 100644 --- a/tools/socfpgaimage.c +++ b/tools/socfpgaimage.c @@ -74,12 +74,12 @@ static uint16_t hdr_checksum(struct socfpga_header *header) static void build_header(uint8_t *buf, uint8_t version, uint8_t flags, uint16_t length_bytes) { - header.validation = htole32(VALIDATION_WORD); + header.validation = cpu_to_le32(VALIDATION_WORD); header.version = version; header.flags = flags; - header.length_u32 = htole16(length_bytes/4); + header.length_u32 = cpu_to_le16(length_bytes/4); header.zero = 0; - header.checksum = htole16(hdr_checksum(&header)); + header.checksum = cpu_to_le16(hdr_checksum(&header)); memcpy(buf, &header, sizeof(header)); } @@ -92,12 +92,12 @@ static int verify_header(const uint8_t *buf) { memcpy(&header, buf, sizeof(header)); - if (le32toh(header.validation) != VALIDATION_WORD) + if (le32_to_cpu(header.validation) != VALIDATION_WORD) return -1; - if (le16toh(header.checksum) != hdr_checksum(&header)) + if (le16_to_cpu(header.checksum) != hdr_checksum(&header)) return -1; - return le16toh(header.length_u32) * 4; + return le16_to_cpu(header.length_u32) * 4; } /* Sign the buffer and return the signed buffer size */ @@ -116,7 +116,7 @@ static int sign_buffer(uint8_t *buf, /* Calculate and apply the CRC */ calc_crc = ~pbl_crc32(0, (char *)buf, len); - *((uint32_t *)(buf + len)) = htole32(calc_crc); + *((uint32_t *)(buf + len)) = cpu_to_le32(calc_crc); if (!pad_64k) return len + 4; @@ -150,7 +150,7 @@ static int verify_buffer(const uint8_t *buf) calc_crc = ~pbl_crc32(0, (const char *)buf, len); - buf_crc = le32toh(*((uint32_t *)(buf + len))); + buf_crc = le32_to_cpu(*((uint32_t *)(buf + len))); if (buf_crc != calc_crc) { fprintf(stderr, "CRC32 does not match (%08x != %08x)\n", |