Index: flash.h =================================================================== --- flash.h (Revision 509) +++ flash.h (Arbeitskopie) @@ -29,6 +29,7 @@ #include #include #include +#include /* 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 (Arbeitskopie) @@ -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 flashrom@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,16 @@ 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 flashrom@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 (Arbeitskopie) @@ -29,12 +29,14 @@ #include #include #include +#include #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,19 @@ 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); + free(msg); + exit(1); + } + + pci_cleanup(pacc); + } } else { printf("Error: Unknown programmer.\n"); exit(1); Index: internal.c =================================================================== --- internal.c (Revision 509) +++ internal.c (Arbeitskopie) @@ -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;