From owner-svn-src-all@FreeBSD.ORG Thu Feb 5 18:15:21 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B59751065673; Thu, 5 Feb 2009 18:15:21 +0000 (UTC) (envelope-from sam@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E40238FC18; Thu, 5 Feb 2009 18:15:20 +0000 (UTC) (envelope-from sam@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n15IFKJo033833; Thu, 5 Feb 2009 18:15:20 GMT (envelope-from sam@svn.freebsd.org) Received: (from sam@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n15IFKwc033830; Thu, 5 Feb 2009 18:15:20 GMT (envelope-from sam@svn.freebsd.org) Message-Id: <200902051815.n15IFKwc033830@svn.freebsd.org> From: Sam Leffler Date: Thu, 5 Feb 2009 18:15:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r188157 - in head/tools/tools: . cfi X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Feb 2009 18:15:22 -0000 Author: sam Date: Thu Feb 5 18:15:20 2009 New Revision: 188157 URL: http://svn.freebsd.org/changeset/base/188157 Log: add cfi test tool Sponsored by: Carlson Wireless Reviewed by: imp, Chris Andreson Added: head/tools/tools/cfi/ head/tools/tools/cfi/Makefile (contents, props changed) head/tools/tools/cfi/cfi.c (contents, props changed) Modified: head/tools/tools/README Modified: head/tools/tools/README ============================================================================== --- head/tools/tools/README Thu Feb 5 18:12:07 2009 (r188156) +++ head/tools/tools/README Thu Feb 5 18:15:20 2009 (r188157) @@ -12,6 +12,7 @@ ansify Convert K&R-style function defin ath Tools specific to the Atheros 802.11 support backout_commit A tool for reading in a commit message and generating a script that will backout the commit. +cfi Common Flash Interface (CFI) tool commitsdb A tool for reconstructing commit history using md5 checksums of the commit logs. crypto Test and exercise tools related to the crypto framework Added: head/tools/tools/cfi/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/tools/cfi/Makefile Thu Feb 5 18:15:20 2009 (r188157) @@ -0,0 +1,7 @@ +# $FreeBSD$ + +PROG= cfi +BINDIR= /usr/local/bin +NO_MAN= + +.include Added: head/tools/tools/cfi/cfi.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/tools/cfi/cfi.c Thu Feb 5 18:15:20 2009 (r188157) @@ -0,0 +1,156 @@ +/*- + * Copyright (c) 2009 Sam Leffler, Errno Consulting + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any + * redistribution must be conditioned upon including a substantially + * similar Disclaimer requirement for further binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. + * + * $FreeBSD$ + */ + +/* + * cfi [-f device] op + * (default device is /dev/cfi0). + */ +#include +#include +#include +#include + +#include +#include +#include + +const char *progname; +const char *dvname; + +static void +usage(void) +{ + int i; + + fprintf(stderr, "usage: %s [-f device] op...\n", progname); + fprintf(stderr, "where op's are:\n"); + fprintf(stderr, "fact\t\tread factory PR segment\n"); + fprintf(stderr, "oem\t\tread OEM segment\n"); + fprintf(stderr, "woem value\twrite OEM segment\n"); + fprintf(stderr, "plr\t\tread PLR\n"); + fprintf(stderr, "wplr\t\twrite PLR\n"); + exit(-1); +} + +static int +getfd(int mode) +{ + int fd = open(dvname, mode, 0); + if (fd < 0) + err(-1, "open"); + return fd; +} + +static uint64_t +getfactorypr(void) +{ + uint64_t v; + int fd = getfd(O_RDONLY); + if (ioctl(fd, CFIOCGFACTORYPR, &v) < 0) + err(-1, "ioctl(CFIOCGFACTORYPR)"); + close(fd); + return v; +} + +static uint64_t +getoempr(void) +{ + uint64_t v; + int fd = getfd(O_RDONLY); + if (ioctl(fd, CFIOCGOEMPR, &v) < 0) + err(-1, "ioctl(CFIOCGOEMPR)"); + close(fd); + return v; +} + +static void +setoempr(uint64_t v) +{ + int fd = getfd(O_WRONLY); + if (ioctl(fd, CFIOCSOEMPR, &v) < 0) + err(-1, "ioctl(CFIOCGOEMPR)"); + close(fd); +} + +static uint32_t +getplr(void) +{ + uint32_t plr; + int fd = getfd(O_RDONLY); + if (ioctl(fd, CFIOCGPLR, &plr) < 0) + err(-1, "ioctl(CFIOCGPLR)"); + close(fd); + return plr; +} + +static void +setplr(void) +{ + int fd = getfd(O_WRONLY); + if (ioctl(fd, CFIOCSPLR, 0) < 0) + err(-1, "ioctl(CFIOCPLR)"); + close(fd); +} + +int +main(int argc, char *argv[]) +{ + dvname = getenv("CFI"); + if (dvname == NULL) + dvname = "/dev/cfi0"; + progname = argv[0]; + if (argc > 1) { + if (strcmp(argv[1], "-f") == 0) { + if (argc < 2) + errx(1, "missing device name for -f option"); + dvname = argv[2]; + argc -= 2, argv += 2; + } else if (strcmp(argv[1], "-?") == 0) + usage(); + } + for (; argc > 1; argc--, argv++) { + if (strcasecmp(argv[1], "fact") == 0) { + printf("0x%llx\n", (unsigned long long) getfactorypr()); + } else if (strcasecmp(argv[1], "oem") == 0) { + printf("0x%llx\n", (unsigned long long) getoempr()); + } else if (strcasecmp(argv[1], "woem") == 0) { + if (argc < 2) + errx(1, "missing value for woem"); + setoempr((uint64_t) strtoull(argv[2], NULL, 0)); + argc--, argv++; + } else if (strcasecmp(argv[1], "plr") == 0) { + printf("0x%x\n", getplr()); + } else if (strcasecmp(argv[1], "wplr") == 0) { + setplr(); + } else + usage(); + } +}