2 * Copyright (c) 2009 Sam Leffler, Errno Consulting
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
32 * (default device is /dev/cfi0).
34 #include <sys/types.h>
36 #include <sys/ioctl.h>
37 #include <sys/cfictl.h>
52 fprintf(stderr, "usage: %s [-f device] op...\n", progname);
53 fprintf(stderr, "where op's are:\n");
54 fprintf(stderr, "fact\t\tread factory PR segment\n");
55 fprintf(stderr, "oem\t\tread OEM segment\n");
56 fprintf(stderr, "woem value\twrite OEM segment\n");
57 fprintf(stderr, "plr\t\tread PLR\n");
58 fprintf(stderr, "wplr\t\twrite PLR\n");
65 int fd = open(dvname, mode, 0);
75 int fd = getfd(O_RDONLY);
76 if (ioctl(fd, CFIOCGFACTORYPR, &v) < 0)
77 err(-1, "ioctl(CFIOCGFACTORYPR)");
86 int fd = getfd(O_RDONLY);
87 if (ioctl(fd, CFIOCGOEMPR, &v) < 0)
88 err(-1, "ioctl(CFIOCGOEMPR)");
96 int fd = getfd(O_WRONLY);
97 if (ioctl(fd, CFIOCSOEMPR, &v) < 0)
98 err(-1, "ioctl(CFIOCGOEMPR)");
106 int fd = getfd(O_RDONLY);
107 if (ioctl(fd, CFIOCGPLR, &plr) < 0)
108 err(-1, "ioctl(CFIOCGPLR)");
116 int fd = getfd(O_WRONLY);
117 if (ioctl(fd, CFIOCSPLR, 0) < 0)
118 err(-1, "ioctl(CFIOCPLR)");
123 main(int argc, char *argv[])
125 dvname = getenv("CFI");
127 dvname = "/dev/cfi0";
130 if (strcmp(argv[1], "-f") == 0) {
132 errx(1, "missing device name for -f option");
134 argc -= 2, argv += 2;
135 } else if (strcmp(argv[1], "-?") == 0)
138 for (; argc > 1; argc--, argv++) {
139 if (strcasecmp(argv[1], "fact") == 0) {
140 printf("0x%llx\n", (unsigned long long) getfactorypr());
141 } else if (strcasecmp(argv[1], "oem") == 0) {
142 printf("0x%llx\n", (unsigned long long) getoempr());
143 } else if (strcasecmp(argv[1], "woem") == 0) {
145 errx(1, "missing value for woem");
146 setoempr((uint64_t) strtoull(argv[2], NULL, 0));
148 } else if (strcasecmp(argv[1], "plr") == 0) {
149 printf("0x%x\n", getplr());
150 } else if (strcasecmp(argv[1], "wplr") == 0) {