2 * Copyright (c) 2008 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.
34 #include "ah_diagcodes.h"
47 /* XXX this should likely be defined somewhere in the HAL */
48 /* XXX This is a lot larger than the v14 ROM */
49 #define MAX_EEPROM_SIZE 16384
51 uint16_t eep[MAX_EEPROM_SIZE];
56 fprintf(stderr, " %s [-i ifname] -d <dumpfile>\n", progname);
60 #define NUM_PER_LINE 8
63 do_eeprom_dump(const char *dumpfile, uint16_t *eebuf, int eelen)
68 fp = fopen(dumpfile, "w");
73 /* eelen is in bytes; eebuf is in 2 byte words */
74 for (i = 0; i < eelen / 2; i++) {
75 if (i % NUM_PER_LINE == 0)
76 fprintf(fp, "%.4x: ", i);
77 fprintf(fp, "%.4x%s", (int32_t)(eebuf[i]), i % NUM_PER_LINE == (NUM_PER_LINE - 1) ? "\n" : " ");
84 main(int argc, char *argv[])
89 const char *dumpname = NULL;
91 s = socket(AF_INET, SOCK_DGRAM, 0);
94 ifname = getenv("ATH");
99 while ((c = getopt(argc, argv, "d:i:t:")) != -1)
108 fd = fopen(optarg, "r");
110 err(-1, "Cannot open %s", optarg);
119 strncpy(atd.ad_name, ifname, sizeof (atd.ad_name));
121 /* Read in the entire EEPROM */
122 atd.ad_id = HAL_DIAG_EEPROM;
123 atd.ad_out_data = (caddr_t) eep;
124 atd.ad_out_size = sizeof(eep);
125 if (ioctl(s, SIOCGATHDIAG, &atd) < 0)
126 err(1, "ioctl: %s", atd.ad_name);
128 /* Dump file? Then just write to it */
129 if (dumpname != NULL) {
130 do_eeprom_dump(dumpname, (uint16_t *) &eep, sizeof(eep));