Hey,

here is the first official patch to support a user specified NIC via pci id 
(bus:slot:func).
example: flashrom -p nic3com=xx:xx.x

Signed-off-by: Christian Ruppert <spook...@gmail.com>

Regards,
Christian Ruppert

Index: flash.h
===================================================================
--- flash.h	(revision 509)
+++ flash.h	(working copy)
@@ -29,6 +29,7 @@
 #include <unistd.h>
 #include <stdint.h>
 #include <stdio.h>
+#include <pci/pci.h>
 
 /* for iopl and outb under Solaris */
 #if defined (__sun) && (defined(__i386) || defined(__amd64))
@@ -545,6 +546,7 @@
 
 /* PCI handling for board/chipset_enable */
 struct pci_access *pacc;
+struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
 struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
 struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
 			      uint16_t card_vendor, uint16_t card_device);
@@ -607,6 +609,7 @@
 		      const unsigned char *writearr, unsigned char *readarr);
 
 /* nic3com.c */
+extern struct pci_filter nic3com_filter;
 int nic3com_init(void);
 int nic3com_shutdown(void);
 void *nic3com_map(const char *descr, unsigned long phys_addr, size_t len);
Index: nic3com.c
===================================================================
--- nic3com.c	(revision 509)
+++ nic3com.c	(working copy)
@@ -69,9 +69,36 @@
 	{},
 };
 
+uint32_t nic3com_validate(struct pci_dev *dev)
+{
+	int i = 0;
+	uint32_t addr = -1;
+
+	for (i = 0; nics[i].device_name != NULL; i++) {
+		if (dev->device_id != nics[i].device_id)
+			continue;
+
+		addr = pci_read_long(dev, PCI_IO_BASE_ADDRESS) & ~0x03;
+
+		printf("Found NIC \"3COM %s\" (%04x:%04x), addr = 0x%x\n",
+				nics[i].device_name, PCI_VENDOR_ID_3COM,
+				nics[i].device_id, addr);
+
+		if (nics[i].status == NT) {
+			printf("===\nThis NIC is UNTESTED. Please email a "
+			       "report including the 'flashrom -p nic3com'\n"
+			       "output to flash...@coreboot.org if it works "
+			       "for you. Thank you for your help!\n===\n");
+		}
+
+		return addr;
+	}
+
+	return addr;
+}
+
 int nic3com_init(void)
 {
-	int i, found = 0;
 	struct pci_dev *dev;
 
 #if defined (__sun) && (defined(__i386) || defined(__amd64))
@@ -90,29 +117,18 @@
 	pci_init(pacc);         /* Initialize the PCI library */
 	pci_scan_bus(pacc);     /* We want to get the list of devices */
 
-	for (i = 0; nics[i].device_name != NULL; i++) {
-		dev = pci_dev_find(PCI_VENDOR_ID_3COM, nics[i].device_id);
-		if (!dev)
-			continue;
+	if (!nic3com_filter.vendor && !nic3com_filter.device)
+	{
+		pci_filter_init(pacc, &nic3com_filter);
+		nic3com_filter.vendor = PCI_VENDOR_ID_3COM;
+	}
 
-		io_base_addr = pci_read_long(dev, PCI_IO_BASE_ADDRESS) & ~0x03;
+	dev = pci_dev_find_filter(nic3com_filter);
 
-		printf("Found NIC \"3COM %s\" (%04x:%04x), addr = 0x%x\n",
-		       nics[i].device_name, PCI_VENDOR_ID_3COM,
-		       nics[i].device_id, io_base_addr);
-
-		if (nics[i].status == NT) {
-			printf("===\nThis NIC is UNTESTED. Please email a "
-			       "report including the 'flashrom -p nic3com'\n"
-			       "output to flash...@coreboot.org if it works "
-			       "for you. Thank you for your help!\n===\n");
-		}
-
-		found = 1;
-		break;
-	}
-
-	if (!found) {
+	if (dev && (dev->vendor_id == PCI_VENDOR_ID_3COM))
+		io_base_addr = nic3com_validate(dev);
+	else
+	{
 		fprintf(stderr, "Error: No supported 3COM NIC found.\n");
 		exit(1);
 	}
Index: flashrom.c
===================================================================
--- flashrom.c	(revision 509)
+++ flashrom.c	(working copy)
@@ -29,12 +29,14 @@
 #include <string.h>
 #include <stdlib.h>
 #include <getopt.h>
+#include <pci/pci.h>
 #include "flash.h"
 
 char *chip_to_probe = NULL;
 int exclude_start_page, exclude_end_page;
 int verbose = 0;
 int programmer = PROGRAMMER_INTERNAL;
+struct pci_filter nic3com_filter;
 
 const struct programmer_entry programmer_table[] = {
 	{
@@ -372,10 +374,12 @@
 		{0, 0, 0, 0}
 	};
 
+	struct pci_access *pacc;
 	char *filename = NULL;
 
 	unsigned int exclude_start_position = 0, exclude_end_position = 0;	// [x,y)
 	char *tempstr = NULL, *tempstr2 = NULL;
+	char *msg = NULL;
 
 	print_version();
 
@@ -454,6 +458,18 @@
 				programmer = PROGRAMMER_DUMMY;
 			} else if (strncmp(optarg, "nic3com", 7) == 0) {
 				programmer = PROGRAMMER_NIC3COM;
+				if (optarg[7] == '=') {
+					pacc = pci_alloc();
+					pci_filter_init(pacc, &nic3com_filter);
+
+					if( (msg = pci_filter_parse_slot(&nic3com_filter, (optarg + 8))) )
+					{
+						fprintf(stderr, "%s\n", msg);
+						exit(1);
+					}
+
+					pci_cleanup(pacc);
+				}
 			} else {
 				printf("Error: Unknown programmer.\n");
 				exit(1);
Index: internal.c
===================================================================
--- internal.c	(revision 509)
+++ internal.c	(working copy)
@@ -34,6 +34,17 @@
 
 struct pci_access *pacc;	/* For board and chipset_enable */
 
+struct pci_dev *pci_dev_find_filter(struct pci_filter filter)
+{
+	struct pci_dev *temp;
+
+	for (temp = pacc->devices; temp; temp = temp->next)
+		if (pci_filter_match(&filter, temp))
+			return temp;
+
+	return NULL;
+}
+
 struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device)
 {
 	struct pci_dev *temp;

Attachment: signature.asc
Description: This is a digitally signed message part.

-- 
coreboot mailing list: coreboot@coreboot.org
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to