CODE EXAMPLE 3-3Read 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.blk_size) perror("uflash0:read");

return(0);

}

main() { int ret;

module = argv[0]; ret = uflash_init(); if (!ret)

uflash_read(); uflash_uninit();

}

Write Example Program

CODE EXAMPLE 3-4contains the Write Action on the user flash device.

CODE EXAMPLE 3-4Write Action on User Flash Device

/*

*uflash_write.c

*An example that shows how to write user flash

*/

#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <uflash_if.h>

char *uflash0 = "/dev/uflash0";

Chapter 3 User Flash 49

Page 63
Image 63
Sun Microsystems CP2500 manual Write Example Program, Code Example 3-4Write Action on User Flash Device