Netra™ CP2500 Board Programming Guide For the Solaris™ Operating System Sun Microsystems, Inc. www.sun.com Part No. 819-1749-11 March 2007, Revision A Submit comments about this document at: http://www.sun.
Copyright 2007 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has intellectual property rights relating to technology that is described in this document. In particular, and without limitation, these intellectual property rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents or pending patent applications in the U.S. and in other countries.
Contents Preface 1. xi Watchdog Timer Overview 1 1 PICL Plug-In Module 2 Watchdog Node Management Code OpenBoot PROM Interface 2.
Warning Temperature Response at OpenBoot PROM Critical Temperature Response at OpenBoot PROM 33 33 Using the show-sensors Command at the OpenBoot PROM Environmental Monitoring Application Programming 34 Reading Temperature Sensor States Using the PICL API Using a Configuration File for Sensor Information Solaris Driver Interface 36 37 Reading the CPU Temperature and Environmental Limits User Flash 43 User Flash Usage and Implementation User Flash Driver 43 44 OpenBoot PROM Device Tree and Proper
Figures FIGURE 2-1 Typical Environmental Monitoring Application Block Diagram 25 FIGURE 2-2 Location of Environmental Monitoring Hardware on the Netra CP2500 Board – Top Side FIGURE 2-3 Netra CP2500 Board Environmental Monitoring Functional Block Diagram 29 30 v
vi Netra CP2500 Board Programming Guide • March 2007
Tables TABLE 1-1 Watchdog Plug-In Interfaces for Netra CP2500 Board Software 3 TABLE 1-2 Properties Under watchdog-controller Node TABLE 1-3 Properties Under watchdog-timer Node TABLE 2-1 Compatible Environmental Monitoring Components TABLE 2-2 Typical Netra CP2500 Board Hardware Environmental Monitoring Functions TABLE 2-3 I2C Components TABLE 2-4 PICL Temperature Sensor Class Node Properties TABLE 2-5 Description of Values Displayed by Solaris Commands TABLE 3-1 User Flash Node Properti
viii Netra CP2500 Board Programming Guide • March 2007
Code Samples CODE EXAMPLE 1-1 System Watchdog Node Management Code Example CODE EXAMPLE 2-1 Sample envmond Application Program CODE EXAMPLE 3-1 PROM Information Structure CODE EXAMPLE 3-2 User Flash Interface Structure CODE EXAMPLE 3-3 Read Action on User Flash Device 48 CODE EXAMPLE 3-4 Write Action on User Flash Device 49 CODE EXAMPLE 3-5 Block Erase Action on User Flash Device CODE EXAMPLE 3-6 Sample User Flash Application Program 5 37 46 47 51 53 ix
x Netra CP2500 Board Programming Guide • March 2007
Preface The Netra CP2500 Board Programming Guide is written for program developers and users who want to program the Netra™ CP2500 board in order to design original equipment manufacturer (OEM) systems, supply additional capability to an existing compatible system, or work in a laboratory environment for experimental purposes. You are required to have a basic knowledge of computers and digital logic programming to fully use the information in this document.
Using UNIX Commands This document may not contain information on basic UNIX® commands and procedures such as shutting down the system, booting the system, and configuring devices. See one or more of the following for this information: ■ Solaris Handbook for Sun Peripherals ■ Solaris™ Operating System (Solaris OS) documentation, which is at: http://docs.sun.
Shell Prompts Shell Prompt C shell machine-name% C shell superuser machine-name# Bourne shell and Korn shell $ Bourne shell and Korn shell superuser # Related Documentation Online documents are available at: http://www.sun.
Documentation, Support, and Training Sun Function URL Documentation http://www.sun.com/documentation/ Support http://www.sun.com/support/ Training http://www.sun.com/training/ Third-Party Web Sites Sun is not responsible for the availability of third-party web sites mentioned in this document. Sun does not endorse and is not responsible or liable for any content, advertising, products, or other materials that are available on or through such sites or resources.
CHAPTER 1 Watchdog Timer The system management controller (SMC) on the Netra CP2500 implements a watchdog service that captures catastrophic faults in the Solaris OS running on the CPU board. The watchdog service reports such faults to the baseboard management controller (BMC) by means of either an IPMI message or by a de-assertion of the CPU’s HEALTHY# signal.
PICL Plug-In Module The watchdog subsystem is managed by a platform information and control library (PICL) plug-in module. This PICL plug-in module provides a set of PICL properties to the system, which enables a Solaris PICL client to specify the attributes of the watchdog system. To use the PICL API to set the watchdog properties, your application must follow the following sequence: Note – The following instructions are not server-specific.
PICL interfaces for the watchdog plug-in module include the nodes watchdogcontroller and watchdog-timer. See TABLE 1-1, TABLE 1-2, and TABLE 1-3 for descriptions of the properties of these nodes. TABLE 1-1 Watchdog Plug-In Interfaces for Netra CP2500 Board Software PICL Class Property Meaning watchdogcontroller WdOp Represents a watchdog subsystem. watchdog-timer State Represents a watchdog timer hardware that belongs to its controller.
TABLE 1-3 Properties Under watchdog-timer Node Property Values Description State armed Indicates timer is armed or running. Cleared by disarm. expired Indicates timer has expired. Cleared by disarm. disarmed Default value set at startup time. Indicates timer is disarmed or stopped. WdTimeout* Varies by system and timer level Indicates the timer initial countdown value. Should be set prior to arming the timer. WdAction\ none Default value. No action is taken.
:_class watchdog-timer :name watchdog-level2 Watchdog Node Management Code CODE EXAMPLE 1-1 contains an example of the code used for managing the watchdog timer nodes. This code can be used to change watchdog timer action and timeout values and also to arm and disarm the watchdog controller. CODE EXAMPLE 1-1 System Watchdog Node Management Code Example /* * Copyright 2003 Sun Microsystems, Inc. * Use is subject to license terms. */ #pragma ident "@(#)wdadm.c 1.6 All rights reserved.
CODE EXAMPLE 1-1 System Watchdog Node Management Code Example (Continued) #define EM_INIT #define EM_GETROOT #define EM_GETPVALBYNAME 1 2 3 #define USAGE_STR "Usage:\n"\ "wdadm -l [...
CODE EXAMPLE 1-1 System Watchdog Node Management Code Example (Continued) #define WATCHDOG_DISARMED "disarmed" /* * data structure that will be passed as argument to * picl_walk_tree_by_class callback function */ typedef struct { int start_index; int max_index; char **list; char *name; char *action; char *op; int32_t timeout; int error_code; } wdadm_args_t; static char *prog; static picl_nodehdl_t rooth; static int count = 0; /* * Error mesage texts */ static char *err_msg[] = { /* program usage */ USAG
CODE EXAMPLE 1-1 System Watchdog Node Management Code Example (Continued) } return (-1); } static void print_errmsg(char *message, ...) { va_list ap; va_start(ap, message); (void) fprintf(stderr, "%s: ", prog); (void) vfprintf(stderr, message, ap); va_end(ap); } /* * Print wdadm usage */ static void usage(void) { print_errmsg(gettext(err_msg[EM_USAGE])); exit(1); } /* * This function is used to read picl property. The value is copied * into vbuf.
CODE EXAMPLE 1-1 System Watchdog Node Management Code Example (Continued) /* read the property value */ if ((err = picl_get_propval(proph, *vbuf, pinfo.
CODE EXAMPLE 1-1 System Watchdog Node Management Code Example (Continued) */ static picl_errno_t print_watchdog_node_props(picl_nodehdl_t nodeh) { int32_t *timeout = NULL; char *action = NULL, *status = NULL; if (wdadm_get_picl_prop(nodeh, WATCHDOG_TIMEOUT, (void **)&timeout) != PICL_SUCCESS) { free(timeout); return (PICL_FAILURE); } if (wdadm_get_picl_prop(nodeh, WATCHDOG_STATUS, (void **)&status) != PICL_SUCCESS) { free(status); free(timeout); return (PICL_FAILURE); } if (wdadm_get_picl_prop(nodeh, WATC
CODE EXAMPLE 1-1 System Watchdog Node Management Code Example (Continued) wdadm_args_t *wd_arg = NULL; picl_nodehdl_t childh, peerh; char cntrl_name[PICL_PROPNAMELEN_MAX]; char wd_name[PICL_PROPNAMELEN_MAX]; char name[2 * PICL_PROPNAMELEN_MAX]; wd_arg = (wdadm_args_t *)args; /* get the controller name */ err = picl_get_propval_by_name(nodeh, PICL_PROP_NAME, (void *)cntrl_name, PICL_PROPNAMELEN_MAX); if (err != PICL_SUCCESS) { print_errmsg(gettext(err_msg[EM_GETPVALBYNAME]), picl_strerror(err)); return (er
CODE EXAMPLE 1-1 System Watchdog Node Management Code Example (Continued) if (wd_arg == NULL || print) { if (count == 0) { (void) printf("%s", HEADER); count++; } (void) printf("%-30s", name); (void) print_watchdog_node_props(peerh); (void) printf("\n"); print = 0; } /* move to next timer node */ err = picl_get_propval_by_name(peerh, PICL_PROP_PEER, &peerh, sizeof (picl_nodehdl_t)); } while (err == PICL_SUCCESS); return (PICL_WALK_CONTINUE); /* move to next controller */ } /* * This routine is used */ sta
CODE EXAMPLE 1-1 System Watchdog Node Management Code Example (Continued) } return (err); } /* * This function is the callback function that gets called * due to picl_walk_tree_by_class call from set_wd_params function. * This function checks if the given controller node has the watchdog-timer * of interest and then changes the timeout and action of that timer.
CODE EXAMPLE 1-1 System Watchdog Node Management Code Example (Continued) if (strncmp(cntrl_name, wd_arg->name, (ptr - wd_arg->name)) != 0) { return (PICL_WALK_CONTINUE); } err = picl_get_propval_by_name(nodeh, PICL_PROP_CHILD, &childh, sizeof (picl_nodehdl_t)); if (err != PICL_SUCCESS) return (PICL_WALK_TERMINATE); ptr++; /* this points to watchdog node name */ if (ptr == NULL) { (void) fprintf(stderr, "%s:Node not found:%d\n", prog, picl2errno(PICL_NODENOTFOUND)); return (PICL_WALK_TERMINATE); } /* trav
CODE EXAMPLE 1-1 System Watchdog Node Management Code Example (Continued) if (wd_arg->action) if ((err = wdadm_set_picl_prop(peerh, WATCHDOG_ACTION, wd_arg->action, strlen(wd_arg->action) + 1)) != PICL_SUCCESS) { (void) fprintf(stderr, "%s:Error in " "setting action:%d\n", prog, picl2errno(err)); return (err); } /* set watchdog timeout */ if (wd_arg->timeout != ILLEGAL_TIMEOUT) if ((err = wdadm_set_picl_prop(peerh, WATCHDOG_TIMEOUT, (void *)&wd_arg->timeout, sizeof (wd_arg->timeout))) != PICL_SUCCESS) { (v
CODE EXAMPLE 1-1 System Watchdog Node Management Code Example (Continued) ptr = strchr(wd_name, ’:’); if (ptr == NULL) { /* invalid format */ (void) fprintf(stderr, "%s:Node not found:%d\n", prog, picl2errno(PICL_NODENOTFOUND)); return (PICL_NODENOTFOUND); } wd_arg.name = wd_name; wd_arg.action = action; wd_arg.error_code = 0; if (timeout) { errno = 0; wd_arg.
CODE EXAMPLE 1-1 System Watchdog Node Management Code Example (Continued) print_errmsg(gettext(err_msg[EM_GETPVALBYNAME]), picl_strerror(err)); return (err); } /* * check to see if the controller is of interest, otherwise * move to the next controller.
CODE EXAMPLE 1-1 System Watchdog Node Management Code Example (Continued) return (err); } int main(int argc, char **argv) { int err; int c, rc = 0; char cntrl_name[PICL_CLASSNAMELEN_MAX]; char op[PICL_CLASSNAMELEN_MAX]; char wd_name[PICL_CLASSNAMELEN_MAX]; char timeout[PICL_CLASSNAMELEN_MAX]; char action[PICL_CLASSNAMELEN_MAX]; int cflg = 0, oflg = 0, lflg = 0; int mflg = 0, tflg = 0, aflg = 0; (void) setlocale(LC_ALL, ""); if ((prog = strrchr(argv[0], ’/’)) == NULL) prog = argv[0]; else prog++; bzero(tim
CODE EXAMPLE 1-1 System Watchdog Node Management Code Example (Continued) tflg = 1; (void) strlcpy(timeout, optarg, PICL_CLASSNAMELEN_MAX); break; case ’a’: aflg = 1; (void) strlcpy(action, optarg, PICL_CLASSNAMELEN_MAX); break; case ’h’: (void) printf("%s\n", USAGE_STR); (void) printf("%s", DETAILED_HELP); exit(0); case ’?’: /*FALLTHROUGH*/ default: usage(); /*NOTREACHED*/ } } /* check if more than one action is specified */ if ((lflg + cflg + mflg) > 1) { (void) printf("wdadm: more than one action " "sp
CODE EXAMPLE 1-1 System Watchdog Node Management Code Example (Continued) rc = print_wd_info(argc, argv, optind); (void) picl_shutdown(); return (picl2errno(rc)); } if (argc != optind) { (void) picl_shutdown(); usage(); } if (mflg) { if ((aflg + tflg) < 1) { /* * m flag must be associated with atleast * action or timeout */ (void) printf("wdadm: timeout and action values " "are missing\n"); (void) picl_shutdown(); usage(); } rc = set_wd_params(wd_name, (aflg ? action : NULL), (tflg ? timeout : NULL)); } i
OpenBoot PROM Interface There is no user interface to the watchdog timer at the OpenBoot™ PROM level. When the Netra CP2500 board is in the host slot of a Netra CT 810 or 410 server, the OpenBoot PROM configures the watchdog timer automatically. The watchdog timer is armed only when a boot has been started. Once the Solaris OS has booted, the watchdog timer configuration is changed, based on the Solaris OS configuration.
22 Netra CP2500 Board Programming Guide • March 2007
CHAPTER 2 Environmental Monitoring The Netra CP2500 board uses an intelligent fault detection environmental monitoring system that increases uptime and manageability of the board. The system management controller (SMC) module on the Netra CP2500 supports the temperature and voltage environmental monitoring functions. This chapter describes the specific environmental monitoring functions of the Netra CP2500.
Environmental Monitoring Component Compatibility TABLE 2-1 lists the compatible environmental monitoring hardware, OpenBoot PROM, and Solaris OS for the Netra CP2500. TABLE 2-1 Compatible Environmental Monitoring Components Component Environmental Monitoring Compatibility Hardware Board supports environmental monitoring OpenBoot PROM Environmental monitoring is supported by OpenBoot PROM.
Transition card (OEM supplied) Rack midplane I2C node I2C external bus Power bus (+5.0 and 3.3 volts) PWR MUX I2C internal bus ADM 1026 System Monitor PWR SMC I2C SMC firmware Temp. voltages Temp.
The Netra CP2500 monitors its CPU diode temperature and issues warnings at both the OpenBoot PROM and Solaris OS levels when these environmental readings are out of limits. At the Solaris OS level, the application program monitors and issues warnings for the board. At the OpenBoot PROM level, the CPU diode temperature is monitored. Typical Cycle From Power Up to Shutdown This section describes a typical environmental monitoring cycle from power up to shutdown.
Protection at the operating system level takes place when the PICL environmental monitoring program (envmond) is running. The environmental monitoring program is part of a UNIX daemon that runs automatically when the Solaris OS boots up. In a typical environmental monitoring application program, the software reads the CPU, inlet, and exhaust temperature sensors once every polling cycle.
Hardware Environmental Monitoring Functions This section summarizes the hardware environmental monitoring features on the Netra CP2500 board. TABLE 2-2 lists the environmental monitoring functions on a Netra CP2500 board. TABLE 2-2 Typical Netra CP2500 Board Hardware Environmental Monitoring Functions Function Capability Board Exhaust Air Temperature Senses the air temperature at the trailing edge of the board. Assumes air direction from the PMC slots toward the processor/heatsink.
FIGURE 2-2 Location of Environmental Monitoring Hardware on the Netra CP2500 Board – Top Side FIGURE 2-3 is a block diagram of the environmental monitoring functions.
CPU die temperature sensor PICL application program Solaris SMC driver CPU Southbridge OpenBoot PROM SMC micro controller PLD I2C controller I2C MUX Power control and monitor cPCI J5 external I2C Exhaust temperature sensor ADM 1026 system monitor Inlet temperature sensor FIGURE 2-3 30 Netra CP2500 Board Environmental Monitoring Functional Block Diagram Netra CP2500 Board Programming Guide • March 2007
Switching Power On and Off The on-board voltage controller allows power to the CPU of the Netra CP2500 only when the following conditions are met: ■ The VDD core-1.1-volt supply voltage is greater than 1.0 volts (within 10% of nominal). ■ The 12-volt supply voltage is greater than 10.8 volts (within 10% of nominal). ■ The 5-volt supply voltage is greater than 4.5 volts (within 10% of nominal) ■ The 3.3-volt supply voltage is greater than 3.0 volts (within 10% of nominal).
The CPU diode temperature can be used to prevent damage to the board by shutting the board down if this sensor exceeds predetermined limits. Adjusting the Environmental Monitoring Warning, Critical, and Shutdown Parameter Settings on the Board The Netra CP2500 uses the environmental monitoring detection system to monitor the temperature of the board. The environmental monitoring system will display messages if the board temperature exceeds the warning and critical settings.
Note – If you have developed an application that uses the environmental monitoring software to monitor the temperature sensors, you may want to adjust your application’s settings accordingly. OpenBoot PROM Environmental Monitoring This section describes the OpenBoot PROM environmental monitoring of the CPU.
Using the show-sensors Command at the OpenBoot PROM The show-sensors command at OpenBoot PROM displays the readings of all the temperature sensors on the board. A sample output for typical sensor readings for a Netra CP2500 is as follows: ok show-sensors Sensor# Sensor Name Sensor Reading ======= ==================================== =================== 1 EP 5v Sensor (d1) 4.968 volts 2 EP 3.3v Sensor (8b) 3.336 volts 3 BP +12v Sensor (ce) 11.760 volts 4 BP -12v Sensor (63) -12.
The environmental monitoring parameter values in the application program apply when the system is running at the Solaris level and do not necessarily have to be the same as the default settings programmed by the SMC and used by the OpenBoot PROM. The OpenBoot PROM environmental monitoring only applies when the system is running at the OpenBoot PROM level. Reading Temperature Sensor States Using the PICL API Temperature sensor states may be read using the libpicl API.
:HighShutdownThreshold 118 :HighWarningThreshold 110 :LowPowerOffThreshold -20 :LowShutdownThreshold -10 :LowWarningThreshold -5 :Temperature 74 :Label Ambient :GeoAddr 0xe :_class temperature-sensor :name CPU-sensor Using a Configuration File for Sensor Information On the Netra CP2500, you can enable or disable sensors, and configure sensor threshold actions, such as shutdown and reboot, by editing the /etc/picl/config/envmond.conf file. Sample entries in the envmond.
Sample Application Program This section presents a sample environmental monitoring (envmond) application that monitors the CPU diode temperature. CODE EXAMPLE 2-1 Sample envmond Application Program /* * sensor_readwrite.c * * compile: cc sensor_readwrite.c -lthread -lpicl -o sensor_readwrite */ #include #include
CODE EXAMPLE 2-1 Sample envmond Application Program (Continued) *resulth = childh; return (PICL_SUCCESS); } if (get_child_by_name(childh, name, resulth) == PICL_SUCCESS) { return (PICL_SUCCESS); } /* get next child node */ rc = picl_get_propval_by_name(childh, PICL_PROP_PEER, &nexth, sizeof (picl_nodehdl_t)); if (rc != PICL_SUCCESS) { return (rc); } childh = nexth; } return (rc); } void get_sensor_thresholds(picl_nodehdl_t nodeh) { int8_t threshold; if (picl_get_propval_by_name(nodeh, HI_POWEROFF_THRESHOL
CODE EXAMPLE 2-1 Sample envmond Application Program (Continued) if (picl_get_propval_by_name(nodeh, LO_SHUTDOWN_THRESHOLD, &threshold, sizeof (threshold)) != PICL_SUCCESS) { fprintf(stderr, "Failed to read low shutdown threshold."); } else fprintf(stdout, "Low shutdown threshold = %d\n", threshold); if (picl_get_propval_by_name(nodeh, LO_WARNING_THRESHOLD, &threshold, sizeof (threshold)) != PICL_SUCCESS) { fprintf(stderr, "Failed to read low warning threshold.
CODE EXAMPLE 2-1 Sample envmond Application Program (Continued) return (1); } if (get_child_by_name(platformh, sensor, &childh) != PICL_SUCCESS) { fprintf(stderr, "Failed to get %s sensor.
Reading the CPU Temperature and Environmental Limits You can access the CPU temperature sensor current readings and environmental monitoring settings from the Solaris prompt by typing the following commands. Sample output is listed after each command.
TABLE 2-5 shows which Solaris commands correspond to the environmental monitoring warning that runs when the CPU temperature exceeds the set limit. TABLE 2-5 42 Description of Values Displayed by Solaris Commands Environmental Monitoring Warning prtpicl prtdiag The first-level temperature warning is displayed. HighWarning Threshold High Warning Threshold The second-level temperature warning is displayed. HighShutdown Threshold High Shutdown Threshold The CPU is shut off.
CHAPTER 3 User Flash This chapter describes the user flash driver for the onboard flash PROM and how to use it. The Netra CP2500 is equipped with user flash memory.
User Flash Driver The uflash is the device driver for the flash PROM device on the Netra CP2500. Access to the driver is carried out through open, read, write, pread, pwrite and ioctl system interfaces. On the Netra CP2500, one device is supported. There is one logical device file for the physical device that can be accessed from applications. Users can use this device for storing applications and data. An instance of the driver is loaded for the device.
TABLE 3-1 User Flash Node Properties (Continued) (Continued) Property Description/Value bank-size 00080000 model SUNW,370-xxxx version version number name flashprom compatible isa-flashprom reg 00000002 00000000 00100000 User Flash Device Files The user flash device file is /dev/uflash0. Interface (Header) File The user flash header file is located in the following path: /usr/platform/SUNW,Netra-CP2500/include/sys/uflash_if.
The ioctl supported commands are listed below: #define #define #define #define #define UIOCIBLK UIOCQBLK UIOCLBLK UIOCCLCK UIOCEBLK (uflashIOC|0) (uflashIOC|1) (uflashIOC|2) (uflashIOC|4) (uflashIOC|5) /* /* /* /* /* identify */ query a block */ lock a block */ clear all locks */ erase a block */ Note that these ioctl commands are not supported: #define UIOCMLCK (uflashIOC|3) #define UIOCEALL (uflashIOC|6) #define UIOCEFUL (uflashIOC|7) /* master lock */ /* erase all unlocked blocks */ /* erase full c
User Flash User Interface Structure The user flash user interface structure holds user parameters to commands such as erase. CODE EXAMPLE 3-2 User Flash Interface Structure /* * uflash user interface structure. */ typedef struct { int blk_num; int num_of_blks; uflash_info_t info; driver */ } uflash_if_t; /* to be filled by the Errors EINVAL Application passed one or more incorrect arguments to the system call. EACCESS Write or Erase operation was attempted on a locked block.
■ ■ Write Block Erase Read Example Program CODE EXAMPLE 3-3 contains the Read Action on the user flash device. CODE EXAMPLE 3-3 Read Action on User Flash Device /* * uflash_read.c * An example that shows how to read user flash */ #include #include #include #include #include #include #include #include
CODE EXAMPLE 3-3 Read Action on User Flash Device (Continued) printf("number of blocks = 0x%p", ufif0.info.blk_num); printf("block size = 0x%p" ufif0.info.blk_size); } static int uflash_uninit() { if (ufd0) close(ufd0); cleanup: if (buf0) free(buf0); } static int uflash_read() { /* read block 0 of user flash */ if (pread(ufd0, buf0, ufif0.info.blk_size, 0) != ufif0.info.
CODE EXAMPLE 3-4 Write Action on User Flash Device (Continued) int ufd0; uflash_if_t ufif0; char *buf0; char *module; static int uflash_init() { char *buf0 = malloc(ufif0.info.
CODE EXAMPLE 3-4 Write Action on User Flash Device (Continued) } main() { int ret; module = argv[0]; ret = uflash_init(); if (!ret) uflash_write(); uflash_uninit(); } Block Erase Example Program CODE EXAMPLE 3-5 contains the Block Erase Action on the user flash device. CODE EXAMPLE 3-5 Block Erase Action on User Flash Device /* * uflash_blockerase.c * An example that shows how to erase block(s) of user flash */ #include #include #include #include
CODE EXAMPLE 3-5 Block Erase Action on User Flash Device (Continued) printf("manfacturer id = 0x%p\n", ufif0.info.mfr_id); printf("device id = 0x%p\n", ufif0.info.dev_id); printf("number of blocks = 0x%p", ufif0.info.blk_num); printf("block size = 0x%p" ufif0.info.blk_size); } } static int uflash_uninit() { if (ufd0) close(ufd0); } static int uflash_blockerase() { /* erase 2 blocks starting from block 1 of user flash */ uf0.blk_num = 1; uf0.
Sample User Flash Application Program You can use the following program to test the user flash device and driver. This program also demonstrates how this device can be used. CODE EXAMPLE 3-6 /* * * * * * * * * * * * * * * * * * * * * * * * * */ This application program demonstrates the user program interface to the User Flash PROM driver. One can read or write a number of bytes up to the size of the user PROM by means of pread() and pwrite() calls.
CODE EXAMPLE 3-6 Sample User Flash Application Program (Continued) #if 1 #define PROM_SIZE 0x700000 /* 7 MBytes */ #endif static char *help[14] = { "0 -- read user flash PROM", "1 -- write user flash PROM", "2 -- identify user flash PROM", "3 -- query blocks", "4 -- lock blocks", "5 -- clear all locks", "6 -- erase blocks", "q -- quit", "?/h -- display this menu", "" }; /*char get_cmd(); */ static char get_cmd() { char buf[10]; gets(buf); return (buf[0]); } /* * Main */ main(int argc, char { int int int
CODE EXAMPLE 3-6 Sample User Flash Application Program (Continued) if ((fd0 = open(devname0, O_RDWR)) < 0) { fprintf(stderr, "couldn’t open device: %s\n", devname0); exit(1); } /* set the default PROM */ prom_id = 0; fd = fd0; /* let them know about the help menu */ fprintf(stderr, "Enter or > for help on commands\n"); while (1) { fprintf(stderr, "[%d]command> ", prom_id); switch(get_cmd()) { case ’q’: goto getout; case ’h’: case ’?’: h = 0; while (*help[h]){ fprintf(stderr, " h++; } break; %s\n",
CODE EXAMPLE 3-6 Sample User Flash Application Program (Continued) case ’4’: /* lock flash PROM block */ /* on certain PROMs */ fprintf(stderr, "Enter PROM block number[0, 56]> "); scanf ("%d", &uflash_if.blk_num); fprintf(stderr, "Enter number of block> "); scanf ("%d", &uflash_if.num_of_blks); if (ioctl(fd, UIOCLBLK, &uflash_if) == -1) goto getout; break; case ’3’: /* query flash PROM */ /* on certain PROMs */ fprintf(stderr, "Enter PROM block number[0, 56]> "); scanf ("%d", &uflash_if.
CODE EXAMPLE 3-6 Sample User Flash Application Program (Continued) case ’1’: /* write to user flash PROM */ fprintf(stderr, "Enter PROM offset[0, 0xXX,XXXX]> "); scanf ("%x", &offset); fprintf(stderr, "Enter number of bytes[hex]> "); scanf ("%x", &size); fprintf(stderr, "Enter data pattern[0, 0xFF]> "); scanf ("%x", &pat); /* * init write buffer.
CODE EXAMPLE 3-6 Sample User Flash Application Program (Continued) } printf ("\nuser data buffer:\n"); for (i = 0; i < size; i++) { printf("%2x ", r_buf[i] & 0xff); } printf("\n"); default: continue; } } /* exit */ getout: close(fd0); return; } /* end of main() */ 58 Netra CP2500 Board Programming Guide • March 2007
Index B O boot, Solaris OS, 21 OpenBoot PROM and environmental monitoring, 26 and user flash, 43, 44 and watchdog timer, 21 backup copy, 43 C commands prtdiag, 41, 42 prtpicl, 4, 35, 41, 42 show-sensors, 34 critical-temperature parameter, 33 D device node, 44 dip switch, 43 documentation, related, xiii E environmental monitoring, 23 to 42 application block diagram, 24 application program, 34 functional block diagram, 30 temperature monitoring, 32 to 33 envmond application program, 27, 34, 37 to 40 en
device, 45 device files, 45 driver, 43 header file, 45 interface structure, 47 node properties, 44 V voltage, 27, 31 voltage controller, 27, 31 W warning-temperature parameter, 33 watchdog plug-ins, 3 watchdog timer, 1 to 21 watchdog-controller, 3, 4 watchdog-timer, 3, 4 60 Netra CP2500 Board Programming Guide • March 2007