diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2007-05-09 10:17:44 +0000 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2007-05-09 10:17:44 +0000 |
commit | c7dc7cc196a4bd5ba1cfafc87b193b89ae01a470 (patch) | |
tree | 06360b19621400a94e7ea8fa8c4a33e33392197b /util/flashrom/flashrom.c | |
parent | 33d1af37ae58c34288ae5fad9879a2ea2b752620 (diff) | |
download | coreboot-c7dc7cc196a4bd5ba1cfafc87b193b89ae01a470.tar.xz |
Fix coding style of flashrom by running indent on all files:
indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs *.[ch]
Some minor fixups were required, and maybe a few more cosmetic
changeѕ are needed.
Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@2643 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/flashrom/flashrom.c')
-rw-r--r-- | util/flashrom/flashrom.c | 242 |
1 files changed, 119 insertions, 123 deletions
diff --git a/util/flashrom/flashrom.c b/util/flashrom/flashrom.c index 04c86001d3..cf895a0a59 100644 --- a/util/flashrom/flashrom.c +++ b/util/flashrom/flashrom.c @@ -51,54 +51,52 @@ #include "debug.h" char *chip_to_probe = NULL; -struct pci_access *pacc; /* For board and chipset_enable */ +struct pci_access *pacc; /* For board and chipset_enable */ int exclude_start_page, exclude_end_page; -int force=0, verbose=0; +int force = 0, verbose = 0; int fd_mem; /* * */ -struct pci_dev * -pci_dev_find(uint16_t vendor, uint16_t device) +struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device) { - struct pci_dev *temp; - struct pci_filter filter; + struct pci_dev *temp; + struct pci_filter filter; - pci_filter_init(NULL, &filter); - filter.vendor = vendor; - filter.device = device; + pci_filter_init(NULL, &filter); + filter.vendor = vendor; + filter.device = device; - for (temp = pacc->devices; temp; temp = temp->next) - if (pci_filter_match(&filter, temp)) - return temp; + for (temp = pacc->devices; temp; temp = temp->next) + if (pci_filter_match(&filter, temp)) + return temp; - return NULL; + return NULL; } /* * */ -struct pci_dev * -pci_card_find(uint16_t vendor, uint16_t device, - uint16_t card_vendor, uint16_t card_device) +struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device, + uint16_t card_vendor, uint16_t card_device) { - struct pci_dev *temp; - struct pci_filter filter; - - pci_filter_init(NULL, &filter); - filter.vendor = vendor; - filter.device = device; - - for (temp = pacc->devices; temp; temp = temp->next) - if (pci_filter_match(&filter, temp)) { - if ((card_vendor == pci_read_word(temp, 0x2C)) && - (card_device == pci_read_word(temp, 0x2E))) - return temp; - } + struct pci_dev *temp; + struct pci_filter filter; + + pci_filter_init(NULL, &filter); + filter.vendor = vendor; + filter.device = device; + + for (temp = pacc->devices; temp; temp = temp->next) + if (pci_filter_match(&filter, temp)) { + if ((card_vendor == pci_read_word(temp, 0x2C)) && + (card_device == pci_read_word(temp, 0x2E))) + return temp; + } - return NULL; + return NULL; } struct flashchip *probe_flash(struct flashchip *flash) @@ -111,8 +109,8 @@ struct flashchip *probe_flash(struct flashchip *flash) flash++; continue; } - printf_debug("Probing for %s, %d KB\n", - flash->name, flash->total_size); + printf_debug("Probing for %s, %d KB\n", + flash->name, flash->total_size); size = flash->total_size * 1024; @@ -132,11 +130,11 @@ struct flashchip *probe_flash(struct flashchip *flash) if (getpagesize() > size) { size = getpagesize(); printf("WARNING: size: %d -> %ld (page size)\n", - flash->total_size * 1024, (unsigned long) size); + flash->total_size * 1024, (unsigned long)size); } bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED, - fd_mem, (off_t)flash_baseaddr ); + fd_mem, (off_t) flash_baseaddr); if (bios == MAP_FAILED) { perror("Error: Can't mmap " MEM_DEV "."); exit(1); @@ -148,7 +146,7 @@ struct flashchip *probe_flash(struct flashchip *flash) flash->name, flash_baseaddr); return flash; } - munmap((void *) bios, size); + munmap((void *)bios, size); flash++; } @@ -162,11 +160,12 @@ int verify_flash(struct flashchip *flash, uint8_t *buf) volatile uint8_t *bios = flash->virt_addr; printf("Verifying flash "); - - if(verbose) printf("address: 0x00000000\b\b\b\b\b\b\b\b\b\b"); - + + if (verbose) + printf("address: 0x00000000\b\b\b\b\b\b\b\b\b\b"); + for (idx = 0; idx < total_size; idx++) { - if (verbose && ( (idx & 0xfff) == 0xfff )) + if (verbose && ((idx & 0xfff) == 0xfff)) printf("0x%08x", idx); if (*(bios + idx) != *(buf + idx)) { @@ -176,38 +175,37 @@ int verify_flash(struct flashchip *flash, uint8_t *buf) printf("- FAILED\n"); return 1; } - - if (verbose && ( (idx & 0xfff) == 0xfff )) + + if (verbose && ((idx & 0xfff) == 0xfff)) printf("\b\b\b\b\b\b\b\b\b\b"); } - if (verbose) + if (verbose) printf("\b\b\b\b\b\b\b\b\b\b "); - + printf("- VERIFIED \n"); return 0; } - void usage(const char *name) { printf("usage: %s [-rwvEVfh] [-c chipname] [-s exclude_start]\n", name); printf(" [-e exclude_end] [-m vendor:part] [-l file.layout] [-i imagename] [file]\n"); - printf(" -r | --read: read flash and save into file\n" - " -w | --write: write file into flash (default when\n" - " file is specified)\n" - " -v | --verify: verify flash against file\n" - " -E | --erase: erase flash device\n" - " -V | --verbose: more verbose output\n" - " -c | --chip <chipname>: probe only for specified flash chip\n" - " -s | --estart <addr>: exclude start position\n" - " -e | --eend <addr>: exclude end postion\n" - " -m | --mainboard <vendor:part>: override mainboard settings\n" - " -f | --force: force write without checking image\n" - " -l | --layout <file.layout>: read rom layout from file\n" - " -i | --image <name>: only flash image name from flash layout\n" - "\n" - " If no file is specified, then all that happens\n" - " is that flash info is dumped.\n\n"); + printf + (" -r | --read: read flash and save into file\n" + " -w | --write: write file into flash (default when\n" + " file is specified)\n" + " -v | --verify: verify flash against file\n" + " -E | --erase: erase flash device\n" + " -V | --verbose: more verbose output\n" + " -c | --chip <chipname>: probe only for specified flash chip\n" + " -s | --estart <addr>: exclude start position\n" + " -e | --eend <addr>: exclude end postion\n" + " -m | --mainboard <vendor:part>: override mainboard settings\n" + " -f | --force: force write without checking image\n" + " -l | --layout <file.layout>: read rom layout from file\n" + " -i | --image <name>: only flash image name from flash layout\n" + "\n" " If no file is specified, then all that happens\n" + " is that flash info is dumped.\n\n"); exit(1); } @@ -219,46 +217,42 @@ int main(int argc, char *argv[]) struct flashchip *flash; int opt; int option_index = 0; - int read_it = 0, - write_it = 0, - erase_it = 0, - verify_it = 0; + int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0; int ret = 0; - static struct option long_options[]= { - { "read", 0, 0, 'r' }, - { "write", 0, 0, 'w' }, - { "erase", 0, 0, 'E' }, - { "verify", 0, 0, 'v' }, - { "chip", 1, 0, 'c' }, - { "estart", 1, 0, 's' }, - { "eend", 1, 0, 'e' }, - { "mainboard", 1, 0, 'm' }, - { "verbose", 0, 0, 'V' }, - { "force", 0, 0, 'f' }, - { "layout", 1, 0, 'l' }, - { "image", 1, 0, 'i' }, - { "help", 0, 0, 'h' }, - { 0, 0, 0, 0 } + static struct option long_options[] = { + {"read", 0, 0, 'r'}, + {"write", 0, 0, 'w'}, + {"erase", 0, 0, 'E'}, + {"verify", 0, 0, 'v'}, + {"chip", 1, 0, 'c'}, + {"estart", 1, 0, 's'}, + {"eend", 1, 0, 'e'}, + {"mainboard", 1, 0, 'm'}, + {"verbose", 0, 0, 'V'}, + {"force", 0, 0, 'f'}, + {"layout", 1, 0, 'l'}, + {"image", 1, 0, 'i'}, + {"help", 0, 0, 'h'}, + {0, 0, 0, 0} }; - - char *filename = NULL; + char *filename = NULL; - unsigned int exclude_start_position=0, exclude_end_position=0; // [x,y) - char *tempstr=NULL, *tempstr2=NULL; + unsigned int exclude_start_position = 0, exclude_end_position = 0; // [x,y) + char *tempstr = NULL, *tempstr2 = NULL; if (argc > 1) { /* Yes, print them. */ int i; - printf_debug ("The arguments are:\n"); + printf_debug("The arguments are:\n"); for (i = 1; i < argc; ++i) - printf_debug ("%s\n", argv[i]); + printf_debug("%s\n", argv[i]); } setbuf(stdout, NULL); - while ((opt = getopt_long(argc, argv, "rwvVEfc:s:e:m:l:i:h", long_options, - &option_index)) != EOF) { + while ((opt = getopt_long(argc, argv, "rwvVEfc:s:e:m:l:i:h", + long_options, &option_index)) != EOF) { switch (opt) { case 'r': read_it = 1; @@ -280,34 +274,34 @@ int main(int argc, char *argv[]) break; case 's': tempstr = strdup(optarg); - sscanf(tempstr,"%x",&exclude_start_position); + sscanf(tempstr, "%x", &exclude_start_position); break; case 'e': tempstr = strdup(optarg); - sscanf(tempstr,"%x",&exclude_end_position); + sscanf(tempstr, "%x", &exclude_end_position); break; case 'm': tempstr = strdup(optarg); strtok(tempstr, ":"); - tempstr2=strtok(NULL, ":"); + tempstr2 = strtok(NULL, ":"); if (tempstr2) { - lb_vendor=tempstr; - lb_part=tempstr2; + lb_vendor = tempstr; + lb_part = tempstr2; } else { printf("warning: ignored wrong format of" - " mainboard: %s\n", tempstr); + " mainboard: %s\n", tempstr); } break; case 'f': - force=1; + force = 1; break; case 'l': - tempstr=strdup(optarg); + tempstr = strdup(optarg); if (read_romlayout(tempstr)) exit(1); break; case 'i': - tempstr=strdup(optarg); + tempstr = strdup(optarg); find_romentry(tempstr); break; case 'h': @@ -325,17 +319,18 @@ int main(int argc, char *argv[]) if (optind < argc) filename = argv[optind++]; - /* First get full io access */ + /* First get full io access */ #if defined (__sun) && (defined(__i386) || defined(__amd64)) - if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0){ + if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0) { #else if (iopl(3) != 0) { #endif - fprintf(stderr, "ERROR: iopl failed: \"%s\"\n", strerror(errno)); + fprintf(stderr, "ERROR: iopl failed: \"%s\"\n", + strerror(errno)); exit(1); } - /* Initialize PCI access for flash enables */ + /* Initialize PCI access for flash enables */ pacc = pci_alloc(); /* Get the pci_access structure */ /* Set all options you want -- here we stick with the defaults */ pci_init(pacc); /* Initialize the PCI library */ @@ -343,7 +338,8 @@ int main(int argc, char *argv[]) /* Open the memory device. A lot of functions need it */ if ((fd_mem = open(MEM_DEV, O_RDWR)) < 0) { - perror("Error: Can not access memory using " MEM_DEV ". You need to be root."); + perror("Error: Can not access memory using " MEM_DEV + ". You need to be root."); exit(1); } @@ -357,13 +353,13 @@ int main(int argc, char *argv[]) /* try to enable it. Failure IS an option, since not all motherboards * really need this to be done, etc., etc. */ - ret = chipset_flash_enable(); - if (ret == -2) - printf("WARNING: No chipset found. Flash detection " - "will most likely fail.\n"); - - board_flash_enable(lb_vendor, lb_part); + ret = chipset_flash_enable(); + if (ret == -2) { + printf("WARNING: No chipset found. Flash detection " + "will most likely fail.\n"); + } + board_flash_enable(lb_vendor, lb_part); if ((flash = probe_flash(flashchips)) == NULL) { printf("No EEPROM/flash device found.\n"); @@ -380,11 +376,11 @@ int main(int argc, char *argv[]) size = flash->total_size * 1024; buf = (uint8_t *) calloc(size, sizeof(char)); - + if (erase_it) { printf("Erasing flash chip\n"); flash->erase(flash); - exit(0); + exit(0); } else if (read_it) { if ((image = fopen(filename, "w")) == NULL) { perror(filename); @@ -392,13 +388,13 @@ int main(int argc, char *argv[]) } printf("Reading Flash..."); if (flash->read == NULL) - memcpy(buf, (const char *) flash->virt_addr, size); + memcpy(buf, (const char *)flash->virt_addr, size); else flash->read(flash, buf); if (exclude_end_position - exclude_start_position > 0) - memset(buf+exclude_start_position, 0, - exclude_end_position-exclude_start_position); + memset(buf + exclude_start_position, 0, + exclude_end_position - exclude_start_position); fwrite(buf, sizeof(char), size, image); fclose(image); @@ -414,7 +410,7 @@ int main(int argc, char *argv[]) perror(filename); exit(1); } - if(image_stat.st_size!=flash->total_size*1024) { + if (image_stat.st_size != flash->total_size * 1024) { fprintf(stderr, "Error: Image size doesnt match\n"); exit(1); } @@ -430,26 +426,26 @@ int main(int argc, char *argv[]) * it to the rom layout feature below and drop exclude range * completely once all flash chips can do rom layouts. stepan */ - + // //////////////////////////////////////////////////////////// if (exclude_end_position - exclude_start_position > 0) - memcpy(buf+exclude_start_position, - (const char *) flash->virt_addr+exclude_start_position, - exclude_end_position-exclude_start_position); + memcpy(buf + exclude_start_position, + (const char *)flash->virt_addr + exclude_start_position, + exclude_end_position - exclude_start_position); - exclude_start_page = exclude_start_position/flash->page_size; - if ((exclude_start_position%flash->page_size) != 0) { + exclude_start_page = exclude_start_position / flash->page_size; + if ((exclude_start_position % flash->page_size) != 0) { exclude_start_page++; } - exclude_end_page = exclude_end_position/flash->page_size; + exclude_end_page = exclude_end_position / flash->page_size; // //////////////////////////////////////////////////////////// // This should be moved into each flash part's code to do it // cleanly. This does the job. - handle_romentries(buf, (uint8_t *)flash->virt_addr); - + handle_romentries(buf, (uint8_t *) flash->virt_addr); + // //////////////////////////////////////////////////////////// - + if (write_it) ret |= flash->write(flash, buf); |