CODE EXAMPLE 3-6Sample 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 <h> 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, " %s\n", help[h]); h++;

}

break;

case ’6’: /* erase flash PROM block */ 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, UIOCEBLK, &uflash_if) == -1) goto getout;

break;

 

case ’5’:

/* clear all locks */

if (ioctl(fd, UIOCCLCK, &uflash_if) == -1) goto getout;

break;

Chapter 3 User Flash 55

Page 69
Image 69
Sun Microsystems CP2500 manual Code Example 3-6Sample User Flash Application Program