Annotation of embedtools/src/cfi.c, revision 1.1.2.1
1.1.2.1 ! misho 1: /*************************************************************************
! 2: * (C) 2011 AITNET - Sofia/Bulgaria - <office@aitbg.com>
! 3: * by Michael Pounov <misho@aitbg.com>
! 4: *
! 5: * $Author: misho $
! 6: * $Id: dwds.c,v 1.2.2.1 2011/06/13 20:23:35 misho Exp $
! 7: *
! 8: *************************************************************************
! 9: The ELWIX and AITNET software is distributed under the following
! 10: terms:
! 11:
! 12: All of the documentation and software included in the ELWIX and AITNET
! 13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
! 14:
! 15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
! 16: by Michael Pounov <misho@elwix.org>. All rights reserved.
! 17:
! 18: Redistribution and use in source and binary forms, with or without
! 19: modification, are permitted provided that the following conditions
! 20: are met:
! 21: 1. Redistributions of source code must retain the above copyright
! 22: notice, this list of conditions and the following disclaimer.
! 23: 2. Redistributions in binary form must reproduce the above copyright
! 24: notice, this list of conditions and the following disclaimer in the
! 25: documentation and/or other materials provided with the distribution.
! 26: 3. All advertising materials mentioning features or use of this software
! 27: must display the following acknowledgement:
! 28: This product includes software developed by Michael Pounov <misho@elwix.org>
! 29: ELWIX - Embedded LightWeight unIX and its contributors.
! 30: 4. Neither the name of AITNET nor the names of its contributors
! 31: may be used to endorse or promote products derived from this software
! 32: without specific prior written permission.
! 33:
! 34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
! 35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 37: ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 44: SUCH DAMAGE.
! 45: */
! 46: #include "global.h"
! 47:
! 48:
! 49: int Verbose;
! 50: extern char compiled[], compiledby[], compilehost[];
! 51:
! 52:
! 53: static void
! 54: Usage()
! 55: {
! 56: printf( "-= CFI =- Flash interface managment tool\n"
! 57: "=== %s === %s@%s ===\n\n"
! 58: " Syntax: cfi [options] <fact|oem|plr> [arg]\n"
! 59: "\n"
! 60: "\t-v\t\tVerbose ...\n"
! 61: "\t-w\t\tWrite operation for oem or plr ...\n"
! 62: "\t-f <dev>\t\tCFI device like [default=/dev/cfi0]...\n"
! 63: "\n", compiled, compiledby, compilehost);
! 64: }
! 65:
! 66: static uint64_t
! 67: getfactorypr(int fd)
! 68: {
! 69: uint64_t v;
! 70:
! 71: if (ioctl(fd, CFIOCGFACTORYPR, &v) < 0)
! 72: printf("Error:: ioctl(CFIOCGFACTORYPR) #%d - %s\n", errno, strerror(errno));
! 73:
! 74: return v;
! 75: }
! 76:
! 77: static uint64_t
! 78: getoempr(int fd)
! 79: {
! 80: uint64_t v;
! 81:
! 82: if (ioctl(fd, CFIOCGOEMPR, &v) < 0)
! 83: printf("Error:: ioctl(CFIOCGOEMPR) #%d - %s\n", errno, strerror(errno));
! 84:
! 85: return v;
! 86: }
! 87:
! 88: static void
! 89: setoempr(int fd, uint64_t v)
! 90: {
! 91: if (ioctl(fd, CFIOCSOEMPR, &v) < 0)
! 92: printf("Error:: ioctl(CFIOCSOEMPR) #%d - %s\n", errno, strerror(errno));
! 93: }
! 94:
! 95: static uint32_t
! 96: getplr(int fd)
! 97: {
! 98: uint32_t plr;
! 99:
! 100: if (ioctl(fd, CFIOCGPLR, &plr) < 0)
! 101: printf("Error:: ioctl(CFIOCGPLR) #%d - %s\n", errno, strerror(errno));
! 102:
! 103: return plr;
! 104: }
! 105:
! 106: static void
! 107: setplr(int fd)
! 108: {
! 109: if (ioctl(fd, CFIOCSPLR, 0) < 0)
! 110: printf("Error:: ioctl(CFIOCPLR) #%d - %s\n", errno, strerror(errno));
! 111: }
! 112:
! 113:
! 114: int
! 115: main(int argc, char **argv)
! 116: {
! 117: char ch, szDev[MAXPATHLEN] = "/dev/cfi0";
! 118: int d, mode = O_RDONLY;
! 119:
! 120: while ((ch = getopt(argc, argv, "vhwf:")) != -1)
! 121: switch (ch) {
! 122: case 'f':
! 123: strlcpy(szDev, optarg, sizeof szDev);
! 124: break;
! 125: case 'w':
! 126: mode = O_WRONLY;
! 127: break;
! 128: case 'v':
! 129: Verbose++;
! 130: break;
! 131: case 'h':
! 132: default:
! 133: Usage();
! 134: return 1;
! 135: }
! 136: argc -= optind;
! 137: argv += optind;
! 138: if (!argc || !*argv) {
! 139: Usage();
! 140: return 1;
! 141: }
! 142:
! 143: d = open(szDev, mode);
! 144: if (d < 0) {
! 145: printf("Error:: open device %s #%d - %s\n", szDev, errno, strerror(errno));
! 146: return 2;
! 147: }
! 148:
! 149: if (!strcasecmp(*argv, "fact")) {
! 150: printf("0x%llx\n", (unsigned long long) getfactorypr(d));
! 151: } else if (!strcasecmp(*argv, "oem")) {
! 152: if (mode == O_WRONLY && argv[1])
! 153: setoempr(d, (uint64_t) strtoull(argv[1], NULL, 0));
! 154: else
! 155: printf("0x%llx\n", (unsigned long long) getoempr(d));
! 156: } else if (!strcasecmp(*argv, "plr")) {
! 157: if (mode == O_WRONLY /*&& argv[1]*/)
! 158: setplr(d);
! 159: else
! 160: printf("0x%x\n", getplr(d));
! 161: } else
! 162: Usage();
! 163:
! 164: close(d);
! 165: return 0;
! 166: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>