/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/promimpl.h>
#ifdef DPRINTF
#endif
/*
* Check if the prom is 64-bit ready.
*/
/*
* Table listing the minimum prom versions supported by this kernel.
* The model value is expected to match the model in the flashprom node.
*/
static struct obp_rev_table {
char *model;
char *version;
} obp_min_revs[] = {
{"SUNW,525-1414", "OBP 3.11.2 1997/12/05 10:25"}, /* pulsar */
{"SUNW,525-1672", "OBP 3.7.107 1998/02/19 17:54"}, /* tazmo */
{"SUNW,525-1431", "OBP 3.2.16 1998/06/08 16:58"}, /* sunfire */
};
#define MINUTE(m) (m)
static int
{
int c;
int val = 0;
val *= 10;
val += c - '0';
}
if (pos)
return (val);
}
/*
* obp_timestamp: based on the OBP flashprom version string of the
* on the year, month, day, hour and minute by turning that into
* a number of minutes.
*/
static int
obp_timestamp(char *v)
{
char *c;
if (v[0] != 'O' || v[1] != 'B' || v[2] != 'P')
return (-1);
c = v + 3;
/* Find first non-space character after OBP */
while (*c != '\0' && (*c == ' ' || *c == '\t'))
c++;
return (-1);
if (maj < 3)
return (-1);
#if 0 /* XXX - not used */
if (*c == '.') {
/* optional? dot-dot release */
if (*c == '.')
}
#endif
/* Find space at the end of version number */
while (*c != '\0' && *c != ' ')
c++;
return (-1);
/* Point to first character of date */
c++;
/* Validate date format */
if (c[4] != '/' || c[7] != '/')
return (-1);
return (-1);
/*
* Find space at the end of date number
*/
c += 10;
while (*c != '\0' && *c != ' ')
c++;
return (-1);
/* Point to first character of time */
c++;
if (c[2] != ':')
return (-1);
}
/*
* Check the prom against the obp_min_revs table and complain if
*/
static int flashprom_checked;
static int flashprom_return_code;
int
{
int min_tstamp;
if (min_tstamp == -1) {
#ifdef DEBUG
prom_printf("prom_version_check: "
"invalid OBP version string in table "
#endif
continue;
}
if (tstamp < min_tstamp) {
#ifdef DPRINTF
dprintf("prom_version_check: "
"Down-rev OBP detected. "
"Please update to at least:\n\t%s\n\n",
#endif
return (1);
}
}
} /* for each obp_rev_table entry */
return (0);
}
static pnode_t
{
/*
* if name isn't 'flashprom', continue.
*/
return ((pnode_t)0);
return ((pnode_t)0);
return ((pnode_t)0);
/* Make sure it's an OBP flashprom */
return ((pnode_t)0);
return ((pnode_t)0);
if (tstamp == -1) {
prom_printf("prom_version_check: node contains "
"improperly formatted version property,\n"
"\tnot checking prom version");
return ((pnode_t)0);
}
if (i == 0)
return ((pnode_t)0);
/*
* We know that "node"'s flashprom image contains downrev firmware,
* however, a multi-board server might be running correct firmware.
* Check for that case by looking at the "/openprom" node,
* which always contains the running version. (We needed the
* "model" value to be able to do this, so we can use it as
* an index value into the table.)
*
* If it turns out we're running 'current' firmware,
* but detect down-rev firmware, use a different return code.
*/
if (openprom_node == OBP_BADNODE)
return (node);
return (node);
prom_printf("prom_version_check: "
"unknown <version> string in </openprom>\n");
return (node);
}
if (tstamp == -1) {
prom_printf("prom_version_check: "
"</openprom> node <version> property: bad tstamp\n");
return (node);
}
/*
* If that returned zero, then the running version is
* adequate ... so we can 'suggest' instead of 'require'.
*/
if (i == 0)
return (node);
}
/*
* visit each node in the device tree, until we get a non-null answer
*/
static pnode_t
{
return (node);
return (id);
return ((pnode_t)0);
}
/*
* Check if the prom is 64-bit ready.
*
* If it's ready (or the test doesn't apply), return PROM_VER64_OK.
* If downrev firmware is running, return PROM_VER64_UPGRADE.
* If downrev firmware is detected (but not running), return PROM_VER64_SUGGEST.
*
* For PROM_VER64_UPGRADE and PROM_VER64_SUGGEST return code values:
* Return the nodeid of the flashprom node in *nodeid.
* and a printable message in *buf, buflen.
*/
int
{
char *p;
size_t i;
/*
* If we already checked, we already know the answer.
*/
if (flashprom_checked == 0) {
flashprom_checked = 1;
}
if (nodeid)
*buf = '\0';
return (PROM_VER64_OK);
}
/* bzero the callers buffer */
*p = '\0';
/*
* Do a bounded copy of the output string into the callers buffer
*/
if (buflen <= 1)
return (flashprom_return_code);
return (flashprom_return_code);
}