beautypg.com

Read example program, Code example 3-3 – Sun Microsystems Netra CP2500 User Manual

Page 62

background image

48

Netra CP2500 Board Programming Guide • March 2007

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

char *uflash0 = "/dev/uflash0";

int ufd0;

uflash_if_t ufif0;

char *buf0;

char *module;

static int

uflash_init() {

char *buf0 = malloc(ufif0.info.blk_size);

if (!buf0) {

printf("%s: cannot allocate memory\n", module);

return(-1);

}

/* open device */

if ((ufd0 = open(uflash0, O_RDWR)) == -1 ) {

perror("uflash0: ");

exit(1);

}

/* get uflash sizes */

if (ioctl(ufd0, UIOCIBLK, &ufif0) == -1 ) {

perror("ioctl(ufd0, UIOCIBLK): ");

exit(1);

}

if (ufd0) {

printf("%s: \n", uflash0);

printf("manfacturer id = 0x%p\n", ufif0.info.mfr_id);

printf("device id = 0x%p\n", ufif0.info.dev_id);