From owner-svn-src-head@FreeBSD.ORG Sat Jan 22 23:44:56 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C0F00106566B; Sat, 22 Jan 2011 23:44:56 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AEAFA8FC08; Sat, 22 Jan 2011 23:44:56 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p0MNiu6l008600; Sat, 22 Jan 2011 23:44:56 GMT (envelope-from adrian@svn.freebsd.org) Received: (from adrian@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p0MNiu22008596; Sat, 22 Jan 2011 23:44:56 GMT (envelope-from adrian@svn.freebsd.org) Message-Id: <201101222344.p0MNiu22008596@svn.freebsd.org> From: Adrian Chadd Date: Sat, 22 Jan 2011 23:44:56 +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: r217739 - in head/tools/tools/ath: . ath_prom_read X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 22 Jan 2011 23:44:56 -0000 Author: adrian Date: Sat Jan 22 23:44:56 2011 New Revision: 217739 URL: http://svn.freebsd.org/changeset/base/217739 Log: Add a new tool which takes a text hexdump of the current EEPROM contents. Added: head/tools/tools/ath/ath_prom_read/ head/tools/tools/ath/ath_prom_read/Makefile (contents, props changed) head/tools/tools/ath/ath_prom_read/ath_prom_read.c (contents, props changed) Modified: head/tools/tools/ath/Makefile Modified: head/tools/tools/ath/Makefile ============================================================================== --- head/tools/tools/ath/Makefile Sat Jan 22 23:37:42 2011 (r217738) +++ head/tools/tools/ath/Makefile Sat Jan 22 23:44:56 2011 (r217739) @@ -1,5 +1,5 @@ # $FreeBSD$ -SUBDIR= athdebug athdecode athkey athpoke athprom athrd athregs athstats ath_ee_v14_print +SUBDIR= athdebug athdecode athkey athpoke athprom athrd athregs athstats ath_ee_v14_print ath_prom_read .include Added: head/tools/tools/ath/ath_prom_read/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/tools/ath/ath_prom_read/Makefile Sat Jan 22 23:44:56 2011 (r217739) @@ -0,0 +1,22 @@ +# $FreeBSD$ + +PROG= ath_prom_read + +.include + +.include <../Makefile.inc> + +CLEANFILES+= opt_ah.h ah_osdep.h + +CFLAGS+=-DATH_SUPPORT_ANI +CFLAGS+=-DATH_SUPPORT_TDMA + +CFLAGS+=-I${.CURDIR} +CFLAGS+=-I${SRCDIR}/sys/net80211 + +opt_ah.h: + touch opt_ah.h +ah_osdep.h: + echo 'typedef void *HAL_SOFTC;' >ah_osdep.h + echo 'typedef int HAL_BUS_TAG;' >>ah_osdep.h + echo 'typedef void *HAL_BUS_HANDLE;' >>ah_osdep.h Added: head/tools/tools/ath/ath_prom_read/ath_prom_read.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/tools/ath/ath_prom_read/ath_prom_read.c Sat Jan 22 23:44:56 2011 (r217739) @@ -0,0 +1,134 @@ +/*- + * Copyright (c) 2008 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$ + */ +#include "diag.h" + +#include "ah.h" +#include "ah_diagcodes.h" + +#include +#include +#include +#include +#include +#include + +struct ath_diag atd; +int s; +const char *progname; + +/* XXX this should likely be defined somewhere in the HAL */ +/* XXX This is a lot larger than the v14 ROM */ +#define MAX_EEPROM_SIZE 16384 + +uint16_t eep[MAX_EEPROM_SIZE]; + +static void +usage() +{ + fprintf(stderr, " %s [-i ifname] -d \n", progname); + exit(-1); +} + +#define NUM_PER_LINE 8 + +static void +do_eeprom_dump(const char *dumpfile, uint16_t *eebuf, int eelen) +{ + FILE *fp; + int i; + + fp = fopen(dumpfile, "w"); + if (!fp) { + err(1, "fopen"); + } + + /* eelen is in bytes; eebuf is in 2 byte words */ + for (i = 0; i < eelen / 2; i++) { + if (i % NUM_PER_LINE == 0) + fprintf(fp, "%.4x: ", i); + fprintf(fp, "%.4x%s", (int32_t)(eebuf[i]), i % NUM_PER_LINE == (NUM_PER_LINE - 1) ? "\n" : " "); + } + fprintf(fp, "\n"); + fclose(fp); +} + +int +main(int argc, char *argv[]) +{ + FILE *fd = NULL; + const char *ifname; + int c; + const char *dumpname = NULL; + + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) + err(1, "socket"); + ifname = getenv("ATH"); + if (!ifname) + ifname = ATH_DEFAULT; + + progname = argv[0]; + while ((c = getopt(argc, argv, "d:i:t:")) != -1) + switch (c) { + case 'd': + dumpname = optarg; + break; + case 'i': + ifname = optarg; + break; + case 't': + fd = fopen(optarg, "r"); + if (fd == NULL) + err(-1, "Cannot open %s", optarg); + break; + default: + usage(); + /*NOTREACHED*/ + } + argc -= optind; + argv += optind; + + strncpy(atd.ad_name, ifname, sizeof (atd.ad_name)); + + /* Read in the entire EEPROM */ + atd.ad_id = HAL_DIAG_EEPROM; + atd.ad_out_data = (caddr_t) eep; + atd.ad_out_size = sizeof(eep); + if (ioctl(s, SIOCGATHDIAG, &atd) < 0) + err(1, atd.ad_name); + + /* Dump file? Then just write to it */ + if (dumpname != NULL) { + do_eeprom_dump(dumpname, (uint16_t *) &eep, sizeof(eep)); + } + return 0; +} +