diff --git a/82802ab.c b/82802ab.c index 58d3467..328cf4f 100644 --- a/82802ab.c +++ b/82802ab.c @@ -33,13 +33,13 @@ // I need that Berkeley bit-map printer void print_82802ab_status(uint8_t status) { - printf_debug("%s", status & 0x80 ? "Ready:" : "Busy:"); - printf_debug("%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:"); - printf_debug("%s", status & 0x20 ? "BE ERROR:" : "BE OK:"); - printf_debug("%s", status & 0x10 ? "PROG ERR:" : "PROG OK:"); - printf_debug("%s", status & 0x8 ? "VP ERR:" : "VPP OK:"); - printf_debug("%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:"); - printf_debug("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:"); + print(MSG_DEBUG, "%s", status & 0x80 ? "Ready:" : "Busy:"); + print(MSG_DEBUG, "%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:"); + print(MSG_DEBUG, "%s", status & 0x20 ? "BE ERROR:" : "BE OK:"); + print(MSG_DEBUG, "%s", status & 0x10 ? "PROG ERR:" : "PROG OK:"); + print(MSG_DEBUG, "%s", status & 0x8 ? "VP ERR:" : "VPP OK:"); + print(MSG_DEBUG, "%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:"); + print(MSG_DEBUG, "%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:"); } int probe_82802ab(struct flashchip *flash) @@ -63,7 +63,7 @@ int probe_82802ab(struct flashchip *flash) programmer_delay(10); - printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); + print(MSG_DEBUG, "%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); if (id1 != flash->manufacture_id || id2 != flash->model_id) return 0; @@ -112,10 +112,10 @@ int erase_82802ab_block(struct flashchip *flash, int offset) print_82802ab_status(status); if (check_erased_range(flash, offset, flash->page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } - printf("DONE BLOCK 0x%x\n", offset); + print(MSG_NORMAL, "DONE BLOCK 0x%x\n", offset); return 0; } @@ -125,14 +125,14 @@ int erase_82802ab(struct flashchip *flash) int i; unsigned int total_size = flash->total_size * 1024; - printf("total_size is %d; flash->page_size is %d\n", + print(MSG_NORMAL, "total_size is %d; flash->page_size is %d\n", total_size, flash->page_size); for (i = 0; i < total_size; i += flash->page_size) if (erase_82802ab_block(flash, i)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } - printf("DONE ERASE\n"); + print(MSG_NORMAL, "DONE ERASE\n"); return 0; } @@ -159,14 +159,14 @@ int write_82802ab(struct flashchip *flash, uint8_t *buf) uint8_t *tmpbuf = malloc(page_size); if (!tmpbuf) { - printf("Could not allocate memory!\n"); + print(MSG_NORMAL, "Could not allocate memory!\n"); exit(1); } - printf("Programming page: \n"); + print(MSG_NORMAL, "Programming page: \n"); for (i = 0; i < total_size / page_size; i++) { printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); - printf("%04d at address: 0x%08x", i, i * page_size); + print(MSG_NORMAL, "%04d at address: 0x%08x", i, i * page_size); /* Auto Skip Blocks, which already contain the desired data * Faster, because we only write, what has changed @@ -177,19 +177,19 @@ int write_82802ab(struct flashchip *flash, uint8_t *buf) */ chip_readn(tmpbuf, bios + i * page_size, page_size); if (!memcmp((void *)(buf + i * page_size), tmpbuf, page_size)) { - printf("SKIPPED\n"); + print(MSG_NORMAL, "SKIPPED\n"); continue; } /* erase block by block and write block by block; this is the most secure way */ if (erase_82802ab_block(flash, i * page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } write_page_82802ab(bios, buf + i * page_size, bios + i * page_size, page_size); } - printf("\n"); + print(MSG_NORMAL, "\n"); free(tmpbuf); return 0; diff --git a/am29f040b.c b/am29f040b.c index 46a5ef4..a84aeb1 100644 --- a/am29f040b.c +++ b/am29f040b.c @@ -40,7 +40,7 @@ static int erase_sector_29f040b(struct flashchip *flash, unsigned long address) toggle_ready_jedec(bios + address); if (check_erased_range(flash, address, page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; @@ -54,7 +54,7 @@ static int write_sector_29f040b(chipaddr bios, uint8_t *src, chipaddr dst, for (i = 0; i < page_size; i++) { if ((i & 0xfff) == 0xfff) - printf("0x%08lx", dst - bios); + print(MSG_NORMAL, "0x%08lx", dst - bios); chip_writeb(0xAA, bios + 0x555); chip_writeb(0x55, bios + 0x2AA); @@ -65,7 +65,7 @@ static int write_sector_29f040b(chipaddr bios, uint8_t *src, chipaddr dst, toggle_ready_jedec(bios); if ((i & 0xfff) == 0xfff) - printf("\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b"); } return 0; @@ -87,7 +87,7 @@ int probe_29f040b(struct flashchip *flash) programmer_delay(10); - printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); + print(MSG_DEBUG, "%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); if (id1 == flash->manufacture_id && id2 == flash->model_id) return 1; @@ -111,7 +111,7 @@ int erase_29f040b(struct flashchip *flash) toggle_ready_jedec(bios); if (check_erased_range(flash, 0, total_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; @@ -124,21 +124,21 @@ int write_29f040b(struct flashchip *flash, uint8_t *buf) int page_size = flash->page_size; chipaddr bios = flash->virtual_memory; - printf("Programming page "); + print(MSG_NORMAL, "Programming page "); for (i = 0; i < total_size / page_size; i++) { /* erase the page before programming */ if (erase_sector_29f040b(flash, i * page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } /* write to the sector */ - printf("%04d at address: ", i); + print(MSG_NORMAL, "%04d at address: ", i); write_sector_29f040b(bios, buf + i * page_size, bios + i * page_size, page_size); - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); } - printf("\n"); + print(MSG_NORMAL, "\n"); return 0; } diff --git a/bitbang_spi.c b/bitbang_spi.c index abf5530..a6b63d8 100644 --- a/bitbang_spi.c +++ b/bitbang_spi.c @@ -99,14 +99,14 @@ int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt, if (bufsize > oldbufsize) { bufout = realloc(bufout, bufsize); if (!bufout) { - fprintf(stderr, "Out of memory!\n"); + print(MSG_ERROR, "Out of memory!\n"); if (bufin) free(bufin); exit(1); } bufin = realloc(bufout, bufsize); if (!bufin) { - fprintf(stderr, "Out of memory!\n"); + print(MSG_ERROR, "Out of memory!\n"); if (bufout) free(bufout); exit(1); @@ -143,7 +143,7 @@ int bitbang_spi_write_256(struct flashchip *flash, uint8_t *buf) int total_size = 1024 * flash->total_size; int i; - printf_debug("total_size is %d\n", total_size); + print(MSG_DEBUG, "total_size is %d\n", total_size); for (i = 0; i < total_size; i += 256) { int l, r; if (i + 256 <= total_size) @@ -152,7 +152,7 @@ int bitbang_spi_write_256(struct flashchip *flash, uint8_t *buf) l = total_size - i; if ((r = spi_nbyte_program(i, &buf[i], l))) { - fprintf(stderr, "%s: write fail %d\n", __func__, r); + print(MSG_ERROR, "%s: write fail %d\n", __func__, r); return 1; } diff --git a/board_enable.c b/board_enable.c index 769b402..479e762 100644 --- a/board_enable.c +++ b/board_enable.c @@ -79,7 +79,7 @@ static int w83627hf_gpio24_raise(uint16_t port, const char *name) /* Is this the W83627HF? */ if (sio_read(port, 0x20) != 0x52) { /* Super I/O device ID reg. */ - fprintf(stderr, "\nERROR: %s: W83627HF: Wrong ID: 0x%02X.\n", + print(MSG_ERROR, "\nERROR: %s: W83627HF: Wrong ID: 0x%02X.\n", name, sio_read(port, 0x20)); w836xx_ext_leave(port); return -1; @@ -119,7 +119,7 @@ static int w83627thf_gpio4_4_raise(uint16_t port, const char *name) /* Is this the W83627THF? */ if (sio_read(port, 0x20) != 0x82) { /* Super I/O device ID reg. */ - fprintf(stderr, "\nERROR: %s: W83627THF: Wrong ID: 0x%02X.\n", + print(MSG_ERROR, "\nERROR: %s: W83627THF: Wrong ID: 0x%02X.\n", name, sio_read(port, 0x20)); w836xx_ext_leave(port); return -1; @@ -197,7 +197,7 @@ static void vt823x_gpio_set(struct pci_dev *dev, uint8_t gpio, int raise) val |= 0x01; pci_write_byte(dev, 0xE4, val); } else { - fprintf(stderr, "\nERROR: " + print(MSG_ERROR, "\nERROR: " "VT823x GPIO%02d is not implemented.\n", gpio); return; } @@ -227,7 +227,7 @@ static int board_via_epia_m(const char *name) dev = pci_dev_find(0x1106, 0x3177); /* VT8235 ISA bridge */ if (!dev) { - fprintf(stderr, "\nERROR: VT8235 ISA bridge not found.\n"); + print(MSG_ERROR, "\nERROR: VT8235 ISA bridge not found.\n"); return -1; } @@ -250,7 +250,7 @@ static int board_asus_a7v8x_mx(const char *name) if (!dev) dev = pci_dev_find(0x1106, 0x3227); /* VT8237 ISA bridge */ if (!dev) { - fprintf(stderr, "\nERROR: VT823x ISA bridge not found.\n"); + print(MSG_ERROR, "\nERROR: VT823x ISA bridge not found.\n"); return -1; } @@ -269,7 +269,7 @@ static int board_via_epia_sp(const char *name) dev = pci_dev_find(0x1106, 0x3227); /* VT8237R ISA bridge */ if (!dev) { - fprintf(stderr, "\nERROR: VT8237R ISA bridge not found.\n"); + print(MSG_ERROR, "\nERROR: VT8237R ISA bridge not found.\n"); return -1; } @@ -287,7 +287,7 @@ static int board_via_epia_n(const char *name) dev = pci_dev_find(0x1106, 0x3227); /* VT8237R ISA bridge */ if (!dev) { - fprintf(stderr, "\nERROR: VT8237R ISA bridge not found.\n"); + print(MSG_ERROR, "\nERROR: VT8237R ISA bridge not found.\n"); return -1; } @@ -339,7 +339,7 @@ static int board_asus_p5a(const char *name) } if (i == ASUSP5A_LOOP) { - printf("%s: Unable to contact device.\n", name); + print(MSG_NORMAL, "%s: Unable to contact device.\n", name); return -1; } @@ -355,7 +355,7 @@ static int board_asus_p5a(const char *name) } if ((i == ASUSP5A_LOOP) || !(tmp & 0x10)) { - printf("%s: failed to read device.\n", name); + print(MSG_NORMAL, "%s: failed to read device.\n", name); return -1; } @@ -382,7 +382,7 @@ static int board_asus_p5a(const char *name) } if ((i == ASUSP5A_LOOP) || !(tmp & 0x10)) { - printf("%s: failed to write to device.\n", name); + print(MSG_NORMAL, "%s: failed to write to device.\n", name); return -1; } @@ -420,7 +420,7 @@ static int board_shuttle_fn25(const char *name) dev = pci_dev_find(0x10DE, 0x0050); /* NVIDIA CK804 ISA Bridge. */ if (!dev) { - fprintf(stderr, + fprint(MSG_NORMAL, stderr, "\nERROR: NVIDIA nForce4 ISA bridge not found.\n"); return -1; } @@ -441,7 +441,7 @@ static int nvidia_mcp_gpio_set(int gpio, int raise) uint8_t tmp; if ((gpio < 0) || (gpio > 31)) { - fprintf(stderr, "\nERROR: unsupported GPIO: %d.\n", gpio); + print(MSG_ERROR, "\nERROR: unsupported GPIO: %d.\n", gpio); return -1; } @@ -452,7 +452,7 @@ static int nvidia_mcp_gpio_set(int gpio, int raise) case 0x0060: /* MCP2 */ break; default: - fprintf(stderr, "\nERROR: no nVidia SMBus controller found.\n"); + print(MSG_ERROR, "\nERROR: no nVidia SMBus controller found.\n"); return -1; } @@ -618,7 +618,7 @@ static int intel_ich_gpio_set(int gpio, int raise) } if (!dev) { - fprintf(stderr, "\nERROR: No Known Intel LPC Bridge found.\n"); + print(MSG_ERROR, "\nERROR: No Known Intel LPC Bridge found.\n"); return -1; } @@ -636,12 +636,12 @@ static int intel_ich_gpio_set(int gpio, int raise) allowed = (intel_ich_gpio_table[i].bank2 >> (gpio - 64)) & 0x01; if (!allowed) { - fprintf(stderr, "\nERROR: This Intel LPC Bridge does not allow" + print(MSG_ERROR, "\nERROR: This Intel LPC Bridge does not allow" " setting GPIO%02d\n", gpio); return -1; } - printf("\nIntel ICH LPC Bridge: %sing GPIO%02d.\n", + print(MSG_NORMAL, "\nIntel ICH LPC Bridge: %sing GPIO%02d.\n", raise ? "Rais" : "Dropp", gpio); if (gpio < 32) { @@ -660,7 +660,7 @@ static int intel_ich_gpio_set(int gpio, int raise) if (dev->device_id > 0x2800) { tmp = INL(base); if (!(tmp & (1 << gpio))) { - fprintf(stderr, "\nERROR: This Intel LPC Bridge" + print(MSG_ERROR, "\nERROR: This Intel LPC Bridge" " does not allow setting GPIO%02d\n", gpio); return -1; @@ -692,7 +692,7 @@ static int intel_ich_gpio_set(int gpio, int raise) if (dev->device_id > 0x2800) { tmp = INL(base + 30); if (!(tmp & (1 << gpio))) { - fprintf(stderr, "\nERROR: This Intel LPC Bridge" + print(MSG_ERROR, "\nERROR: This Intel LPC Bridge" " does not allow setting GPIO%02d\n", gpio + 32); return -1; @@ -721,7 +721,7 @@ static int intel_ich_gpio_set(int gpio, int raise) tmp = INL(base + 40); if (!(tmp & (1 << gpio))) { - fprintf(stderr, "\nERROR: This Intel LPC Bridge does " + print(MSG_ERROR, "\nERROR: This Intel LPC Bridge does " "not allow setting GPIO%02d\n", gpio + 64); return -1; } @@ -851,7 +851,7 @@ static int board_aopen_vkm400(const char *name) dev = pci_dev_find(0x1106, 0x3227); /* VT8237 ISA bridge */ if (!dev) { - fprintf(stderr, "\nERROR: VT8237 ISA bridge not found.\n"); + print(MSG_ERROR, "\nERROR: VT8237 ISA bridge not found.\n"); return -1; } @@ -873,7 +873,7 @@ static int board_msi_kt4v(const char *name) dev = pci_dev_find(0x1106, 0x3177); /* VT8235 ISA bridge */ if (!dev) { - fprintf(stderr, "\nERROR: VT823x ISA bridge not found.\n"); + print(MSG_ERROR, "\nERROR: VT823x ISA bridge not found.\n"); return -1; } @@ -897,7 +897,7 @@ static int board_soyo_sy_7vca(const char *name) /* VT82C686 Power management */ dev = pci_dev_find(0x1106, 0x3057); if (!dev) { - fprintf(stderr, "\nERROR: VT82C686 PM device not found.\n"); + print(MSG_ERROR, "\nERROR: VT82C686 PM device not found.\n"); return -1; } @@ -950,7 +950,7 @@ static uint16_t smsc_find_runtime(uint16_t sio_port, uint16_t chip_id, /* Verify the chip ID. */ OUTB(0x55, sio_port); /* Enable configuration. */ if (sio_read(sio_port, 0x20) != chip_id) { - fprintf(stderr, "\nERROR: SMSC Super I/O not found.\n"); + print(MSG_ERROR, "\nERROR: SMSC Super I/O not found.\n"); goto out; } @@ -962,7 +962,7 @@ static uint16_t smsc_find_runtime(uint16_t sio_port, uint16_t chip_id, } if (rt_port == 0) { - fprintf(stderr, "\nERROR: " + print(MSG_ERROR, "\nERROR: " "Super I/O runtime interface not available.\n"); } out: @@ -982,7 +982,7 @@ static int board_mitac_6513wu(const char *name) dev = pci_dev_find(0x8086, 0x2410); /* Intel 82801AA ISA bridge */ if (!dev) { - fprintf(stderr, "\nERROR: Intel 82801AA ISA bridge not found.\n"); + print(MSG_ERROR, "\nERROR: Intel 82801AA ISA bridge not found.\n"); return -1; } @@ -1017,7 +1017,7 @@ static int board_asus_a7v8x(const char *name) w836xx_ext_leave(0x2E); if (id != 0x8701) { - fprintf(stderr, "\nERROR: IT8703F SuperIO not found.\n"); + print(MSG_ERROR, "\nERROR: IT8703F SuperIO not found.\n"); return -1; } @@ -1028,7 +1028,7 @@ static int board_asus_a7v8x(const char *name) w836xx_ext_leave(0x2E); if (!base) { - fprintf(stderr, "\nERROR: Failed to read IT8703F SuperIO GPIO" + print(MSG_ERROR, "\nERROR: Failed to read IT8703F SuperIO GPIO" " Base.\n"); return -1; } @@ -1059,7 +1059,7 @@ it8712f_gpio_set(unsigned int line, int raise) /* Check line */ if ((port > 4) || /* also catches unsigned -1 */ ((port < 4) && (line > 7)) || ((port == 4) && (line > 5))) { - fprintf(stderr, + fprint(MSG_NORMAL, stderr, "\nERROR: Unsupported IT8712F GPIO Line %02d.\n", line); return -1; } @@ -1070,7 +1070,7 @@ it8712f_gpio_set(unsigned int line, int raise) exit_conf_mode_ite(0x2E); if (id != 0x8712) { - fprintf(stderr, "\nERROR: IT8712F SuperIO not found.\n"); + print(MSG_ERROR, "\nERROR: IT8712F SuperIO not found.\n"); return -1; } @@ -1081,7 +1081,7 @@ it8712f_gpio_set(unsigned int line, int raise) exit_conf_mode_ite(0x2E); if (!base) { - fprintf(stderr, "\nERROR: Failed to read IT8712F SuperIO GPIO" + print(MSG_ERROR, "\nERROR: Failed to read IT8712F SuperIO GPIO" " Base.\n"); return -1; } @@ -1114,7 +1114,7 @@ static int board_asus_m2v_mx(const char *name) dev = pci_dev_find(0x1106, 0x3337); /* VT8237A ISA bridge */ if (!dev) { - fprintf(stderr, "\nERROR: VT8237A ISA bridge not found.\n"); + print(MSG_ERROR, "\nERROR: VT8237A ISA bridge not found.\n"); return -1; } @@ -1240,10 +1240,10 @@ static struct board_pciid_enable *board_match_coreboot_name(const char *vendor, if (partmatch) { /* a second entry has a matching part name */ - printf("AMBIGUOUS BOARD NAME: %s\n", part); - printf("At least vendors '%s' and '%s' match.\n", + print(MSG_NORMAL, "AMBIGUOUS BOARD NAME: %s\n", part); + print(MSG_NORMAL, "At least vendors '%s' and '%s' match.\n", partmatch->lb_vendor, board->lb_vendor); - printf("Please use the full -m vendor:part syntax.\n"); + print(MSG_NORMAL, "Please use the full -m vendor:part syntax.\n"); return NULL; } partmatch = board; @@ -1257,7 +1257,7 @@ static struct board_pciid_enable *board_match_coreboot_name(const char *vendor, * coreboot table. If it was, the coreboot implementor is * expected to fix flashrom, too. */ - printf("\nUnknown vendor:board from -m option: %s:%s\n\n", + print(MSG_NORMAL, "\nUnknown vendor:board from -m option: %s:%s\n\n", vendor, part); } return NULL; @@ -1312,14 +1312,14 @@ int board_flash_enable(const char *vendor, const char *part) board = board_match_pci_card_ids(); if (board) { - printf("Disabling flash write protection for board \"%s %s\"... ", + print(MSG_NORMAL, "Disabling flash write protection for board \"%s %s\"... ", board->vendor_name, board->board_name); ret = board->enable(board->vendor_name); if (ret) - printf("FAILED!\n"); + print(MSG_NORMAL, "FAILED!\n"); else - printf("OK.\n"); + print(MSG_NORMAL, "OK.\n"); } return ret; diff --git a/buspirate_spi.c b/buspirate_spi.c index a1c8265..cd0ec3b 100644 --- a/buspirate_spi.c +++ b/buspirate_spi.c @@ -52,7 +52,7 @@ int serialport_write(unsigned char *buf, unsigned int writecnt) if (tmp == -1) return 1; if (!tmp) - printf_debug("Empty write\n"); + print(MSG_DEBUG, "Empty write\n"); } return 0; @@ -67,7 +67,7 @@ int serialport_read(unsigned char *buf, unsigned int readcnt) if (tmp == -1) return 1; if (!tmp) - printf_debug("Empty read\n"); + print(MSG_DEBUG, "Empty read\n"); } return 0; @@ -77,7 +77,7 @@ int buspirate_discard_read(void) { int flags; - printf_debug("%s\n", __func__); + print(MSG_DEBUG, "%s\n", __func__); flags = fcntl(sp_fd, F_GETFL); flags |= O_NONBLOCK; fcntl(sp_fd, F_SETFL, flags); @@ -99,14 +99,14 @@ int buspirate_sendrecv(unsigned char *buf, unsigned int writecnt, unsigned int r { int i, ret = 0; - printf_debug("%s: write %i, read %i\n", __func__, writecnt, readcnt); + print(MSG_DEBUG, "%s: write %i, read %i\n", __func__, writecnt, readcnt); if (!writecnt && !readcnt) { - fprintf(stderr, "Zero length command!\n"); + print(MSG_ERROR, "Zero length command!\n"); return 1; } - printf_debug("Sending"); + print(MSG_DEBUG, "Sending"); for (i = 0; i < writecnt; i++) - printf_debug(" 0x%02x", buf[i]); + print(MSG_DEBUG, " 0x%02x", buf[i]); #ifdef FAKE_COMMUNICATION /* Placate the caller for now. */ if (readcnt) { @@ -124,10 +124,10 @@ int buspirate_sendrecv(unsigned char *buf, unsigned int writecnt, unsigned int r if (ret) return ret; #endif - printf_debug(", receiving"); + print(MSG_DEBUG, ", receiving"); for (i = 0; i < readcnt; i++) - printf_debug(" 0x%02x", buf[i]); - printf_debug("\n"); + print(MSG_DEBUG, " 0x%02x", buf[i]); + print(MSG_DEBUG, "\n"); return 0; } @@ -160,13 +160,13 @@ int buspirate_spi_init(void) dev = extract_param(&programmer_param, "dev=", ",:"); speed = extract_param(&programmer_param, "spispeed=", ",:"); if (strlen(programmer_param)) - fprintf(stderr, "Unhandled programmer parameters: %s\n", + print(MSG_ERROR, "Unhandled programmer parameters: %s\n", programmer_param); free(programmer_param); programmer_param = NULL; } if (!dev) { - fprintf(stderr, "No serial device given. Use flashrom -p " + print(MSG_ERROR, "No serial device given. Use flashrom -p " "buspiratespi:dev=/dev/ttyUSB0\n"); return 1; } @@ -178,10 +178,10 @@ int buspirate_spi_init(void) break; } if (!spispeeds[i].name) - fprintf(stderr, "Invalid SPI speed, using default.\n"); + print(MSG_ERROR, "Invalid SPI speed, using default.\n"); } /* This works because speeds numbering starts at 0 and is contiguous. */ - printf_debug("SPI speed is %sHz\n", spispeeds[spispeed].name); + print(MSG_DEBUG, "SPI speed is %sHz\n", spispeeds[spispeed].name); ret = buspirate_serialport_setup(dev); if (ret) @@ -206,12 +206,12 @@ int buspirate_spi_init(void) if (ret) return ret; if (memcmp(buf, "BBIO", 4)) { - fprintf(stderr, "Entering raw bitbang mode failed!\n"); + print(MSG_ERROR, "Entering raw bitbang mode failed!\n"); return 1; } - printf_debug("Raw bitbang mode version %c\n", buf[4]); + print(MSG_DEBUG, "Raw bitbang mode version %c\n", buf[4]); if (buf[4] != '1') { - fprintf(stderr, "Can't handle raw bitbang mode version %c!\n", + print(MSG_ERROR, "Can't handle raw bitbang mode version %c!\n", buf[4]); return 1; } @@ -219,12 +219,12 @@ int buspirate_spi_init(void) buf[0] = 0x01; ret = buspirate_sendrecv(buf, 1, 4); if (memcmp(buf, "SPI", 3)) { - fprintf(stderr, "Entering raw SPI mode failed!\n"); + print(MSG_ERROR, "Entering raw SPI mode failed!\n"); return 1; } - printf_debug("Raw SPI mode version %c\n", buf[3]); + print(MSG_DEBUG, "Raw SPI mode version %c\n", buf[3]); if (buf[3] != '1') { - fprintf(stderr, "Can't handle raw SPI mode version %c!\n", + print(MSG_ERROR, "Can't handle raw SPI mode version %c!\n", buf[3]); return 1; } @@ -235,7 +235,7 @@ int buspirate_spi_init(void) if (ret) return 1; if (buf[0] != 0x01) { - fprintf(stderr, "Protocol error while setting power/CS/AUX!\n"); + print(MSG_ERROR, "Protocol error while setting power/CS/AUX!\n"); return 1; } @@ -245,7 +245,7 @@ int buspirate_spi_init(void) if (ret) return 1; if (buf[0] != 0x01) { - fprintf(stderr, "Protocol error while setting SPI speed!\n"); + print(MSG_ERROR, "Protocol error while setting SPI speed!\n"); return 1; } @@ -255,7 +255,7 @@ int buspirate_spi_init(void) if (ret) return 1; if (buf[0] != 0x01) { - fprintf(stderr, "Protocol error while setting SPI config!\n"); + print(MSG_ERROR, "Protocol error while setting SPI config!\n"); return 1; } @@ -265,7 +265,7 @@ int buspirate_spi_init(void) if (ret) return 1; if (buf[0] != 0x01) { - fprintf(stderr, "Protocol error while raising CS#!\n"); + print(MSG_ERROR, "Protocol error while raising CS#!\n"); return 1; } @@ -286,12 +286,12 @@ int buspirate_spi_shutdown(void) if (ret) return ret; if (memcmp(buf, "BBIO", 4)) { - fprintf(stderr, "Entering raw bitbang mode failed!\n"); + print(MSG_ERROR, "Entering raw bitbang mode failed!\n"); return 1; } - printf_debug("Raw bitbang mode version %c\n", buf[4]); + print(MSG_DEBUG, "Raw bitbang mode version %c\n", buf[4]); if (buf[4] != '1') { - fprintf(stderr, "Can't handle raw bitbang mode version %c!\n", + print(MSG_ERROR, "Can't handle raw bitbang mode version %c!\n", buf[4]); return 1; } @@ -305,7 +305,7 @@ int buspirate_spi_shutdown(void) ret = buspirate_serialport_shutdown(); if (ret) return ret; - printf_debug("Bus Pirate shutdown completed.\n"); + print(MSG_DEBUG, "Bus Pirate shutdown completed.\n"); return 0; } @@ -322,7 +322,7 @@ int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt, /* +2 is pretty arbitrary. */ buf = realloc(buf, writecnt + readcnt + 2); if (!buf) { - fprintf(stderr, "Out of memory!\n"); + print(MSG_ERROR, "Out of memory!\n"); exit(1); // -1 } @@ -332,7 +332,7 @@ int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt, if (ret) return SPI_GENERIC_ERROR; if (buf[0] != 0x01) { - fprintf(stderr, "Protocol error while lowering CS#!\n"); + print(MSG_ERROR, "Protocol error while lowering CS#!\n"); return SPI_GENERIC_ERROR; } @@ -345,7 +345,7 @@ int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt, if (ret) return SPI_GENERIC_ERROR; if (buf[0] != 0x01) { - fprintf(stderr, "Protocol error while reading/writing SPI!\n"); + print(MSG_ERROR, "Protocol error while reading/writing SPI!\n"); return SPI_GENERIC_ERROR; } memcpy(readarr, buf + i, readcnt); @@ -357,7 +357,7 @@ int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt, if (ret) return SPI_GENERIC_ERROR; if (buf[0] != 0x01) { - fprintf(stderr, "Protocol error while raising CS#!\n"); + print(MSG_ERROR, "Protocol error while raising CS#!\n"); return SPI_GENERIC_ERROR; } diff --git a/cbtable.c b/cbtable.c index 9d7e758..aec992a 100644 --- a/cbtable.c +++ b/cbtable.c @@ -97,29 +97,29 @@ static struct lb_header *find_lb_table(void *base, unsigned long start, (struct lb_record *)(((char *)base) + addr + sizeof(*head)); if (memcmp(head->signature, "LBIO", 4) != 0) continue; - printf_debug("Found candidate at: %08lx-%08lx\n", + print(MSG_DEBUG, "Found candidate at: %08lx-%08lx\n", addr, addr + head->table_bytes); if (head->header_bytes != sizeof(*head)) { - fprintf(stderr, "Header bytes of %d are incorrect.\n", + print(MSG_ERROR, "Header bytes of %d are incorrect.\n", head->header_bytes); continue; } if (count_lb_records(head) != head->table_entries) { - fprintf(stderr, "Bad record count: %d.\n", + print(MSG_ERROR, "Bad record count: %d.\n", head->table_entries); continue; } if (compute_checksum((uint8_t *) head, sizeof(*head)) != 0) { - fprintf(stderr, "Bad header checksum.\n"); + print(MSG_ERROR, "Bad header checksum.\n"); continue; } if (compute_checksum(recs, head->table_bytes) != head->table_checksum) { - fprintf(stderr, "Bad table checksum: %04x.\n", + print(MSG_ERROR, "Bad table checksum: %04x.\n", head->table_checksum); continue; } - printf_debug("Found coreboot table at 0x%08lx.\n", addr); + print(MSG_DEBUG, "Found coreboot table at 0x%08lx.\n", addr); return head; }; @@ -135,18 +135,18 @@ static void find_mainboard(struct lb_record *ptr, unsigned long addr) rec = (struct lb_mainboard *)ptr; max_size = rec->size - sizeof(*rec); - printf("Vendor ID: %.*s, part ID: %.*s\n", + print(MSG_NORMAL, "Vendor ID: %.*s, part ID: %.*s\n", max_size - rec->vendor_idx, rec->strings + rec->vendor_idx, max_size - rec->part_number_idx, rec->strings + rec->part_number_idx); - snprintf(vendor, 255, "%.*s", max_size - rec->vendor_idx, + snprint(MSG_NORMAL, vendor, 255, "%.*s", max_size - rec->vendor_idx, rec->strings + rec->vendor_idx); - snprintf(part, 255, "%.*s", max_size - rec->part_number_idx, + snprint(MSG_NORMAL, part, 255, "%.*s", max_size - rec->part_number_idx, rec->strings + rec->part_number_idx); if (lb_part) { - printf("Overwritten by command line, vendor ID: %s, part ID: %s.\n", lb_vendor, lb_part); + print(MSG_NORMAL, "Overwritten by command line, vendor ID: %s, part ID: %s.\n", lb_vendor, lb_part); } else { partvendor_from_cbtable = 1; lb_part = strdup(part); @@ -211,16 +211,16 @@ int coreboot_init(void) } if (!lb_table) { - printf("No coreboot table found.\n"); + print(MSG_NORMAL, "No coreboot table found.\n"); return -1; } addr = ((char *)lb_table) - ((char *)table_area) + start; - fprintf(stdout, "coreboot table found at 0x%lx.\n", + fprint(MSG_NORMAL, stdout, "coreboot table found at 0x%lx.\n", (unsigned long)lb_table - (unsigned long)table_area + start); rec = (struct lb_record *)(((char *)lb_table) + lb_table->header_bytes); last = (struct lb_record *)(((char *)rec) + lb_table->table_bytes); - printf_debug("coreboot header(%d) checksum: %04x table(%d) checksum: %04x entries: %d\n", + print(MSG_DEBUG, "coreboot header(%d) checksum: %04x table(%d) checksum: %04x entries: %d\n", lb_table->header_bytes, lb_table->header_checksum, lb_table->table_bytes, lb_table->table_checksum, lb_table->table_entries); diff --git a/chipset_enable.c b/chipset_enable.c index 3bdd7d0..873357f 100644 --- a/chipset_enable.c +++ b/chipset_enable.c @@ -93,8 +93,8 @@ static int enable_flash_sis_mapping(struct pci_dev *dev, const char *name) pci_write_byte(dev, 0x40, new); newer = pci_read_byte(dev, 0x40); if (newer != new) { - printf_debug("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name); - printf_debug("Stuck at 0x%x\n", newer); + print(MSG_DEBUG, "tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name); + print(MSG_DEBUG, "Stuck at 0x%x\n", newer); return -1; } return 0; @@ -110,9 +110,9 @@ static struct pci_dev *find_southbridge(uint16_t vendor, const char *name) if (!sbdev) sbdev = pci_dev_find_vendorclass(vendor, 0x0000); if (!sbdev) - fprintf(stderr, "No southbridge found for %s!\n", name); + print(MSG_ERROR, "No southbridge found for %s!\n", name); if (sbdev) - printf_debug("Found southbridge %04x:%04x at %02x:%02x:%01x\n", + print(MSG_DEBUG, "Found southbridge %04x:%04x at %02x:%02x:%01x\n", sbdev->vendor_id, sbdev->device_id, sbdev->bus, sbdev->dev, sbdev->func); return sbdev; @@ -191,8 +191,8 @@ static int enable_flash_sis530(struct pci_dev *dev, const char *name) pci_write_byte(sbdev, 0x45, new); newer = pci_read_byte(dev, 0x45); if (newer != new) { - printf_debug("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x45, new, name); - printf_debug("Stuck at 0x%x\n", newer); + print(MSG_DEBUG, "tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x45, new, name); + print(MSG_DEBUG, "Stuck at 0x%x\n", newer); ret = -1; } @@ -217,8 +217,8 @@ static int enable_flash_sis540(struct pci_dev *dev, const char *name) pci_write_byte(sbdev, 0x45, new); newer = pci_read_byte(dev, 0x45); if (newer != new) { - printf_debug("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x45, new, name); - printf_debug("Stuck at 0x%x\n", newer); + print(MSG_DEBUG, "tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x45, new, name); + print(MSG_DEBUG, "Stuck at 0x%x\n", newer); ret = -1; } @@ -264,7 +264,7 @@ static int enable_flash_piix4(struct pci_dev *dev, const char *name) pci_write_word(dev, xbcs, new); if (pci_read_word(dev, xbcs) != new) { - printf_debug("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", xbcs, new, name); + print(MSG_DEBUG, "tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", xbcs, new, name); return -1; } @@ -286,11 +286,11 @@ static int enable_flash_ich(struct pci_dev *dev, const char *name, */ old = pci_read_byte(dev, bios_cntl); - printf_debug("\nBIOS Lock Enable: %sabled, ", + print(MSG_DEBUG, "\nBIOS Lock Enable: %sabled, ", (old & (1 << 1)) ? "en" : "dis"); - printf_debug("BIOS Write Enable: %sabled, ", + print(MSG_DEBUG, "BIOS Write Enable: %sabled, ", (old & (1 << 0)) ? "en" : "dis"); - printf_debug("BIOS_CNTL is 0x%x\n", old); + print(MSG_DEBUG, "BIOS_CNTL is 0x%x\n", old); new = old | 1; @@ -300,7 +300,7 @@ static int enable_flash_ich(struct pci_dev *dev, const char *name, pci_write_byte(dev, bios_cntl, new); if (pci_read_byte(dev, bios_cntl) != new) { - printf_debug("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", bios_cntl, new, name); + print(MSG_DEBUG, "tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", bios_cntl, new, name); return -1; } @@ -327,26 +327,26 @@ static int enable_flash_ich_dc(struct pci_dev *dev, const char *name) /* FWH_SEL1 */ fwh_conf = pci_read_long(dev, 0xd0); for (i = 7; i >= 0; i--) - printf_debug("\n0x%08x/0x%08x FWH IDSEL: 0x%x", + print(MSG_DEBUG, "\n0x%08x/0x%08x FWH IDSEL: 0x%x", (0x1ff8 + i) * 0x80000, (0x1ff0 + i) * 0x80000, (fwh_conf >> (i * 4)) & 0xf); /* FWH_SEL2 */ fwh_conf = pci_read_word(dev, 0xd4); for (i = 3; i >= 0; i--) - printf_debug("\n0x%08x/0x%08x FWH IDSEL: 0x%x", + print(MSG_DEBUG, "\n0x%08x/0x%08x FWH IDSEL: 0x%x", (0xff4 + i) * 0x100000, (0xff0 + i) * 0x100000, (fwh_conf >> (i * 4)) & 0xf); /* FWH_DEC_EN1 */ fwh_conf = pci_read_word(dev, 0xd8); for (i = 7; i >= 0; i--) - printf_debug("\n0x%08x/0x%08x FWH decode %sabled", + print(MSG_DEBUG, "\n0x%08x/0x%08x FWH decode %sabled", (0x1ff8 + i) * 0x80000, (0x1ff0 + i) * 0x80000, (fwh_conf >> (i + 0x8)) & 0x1 ? "en" : "dis"); for (i = 3; i >= 0; i--) - printf_debug("\n0x%08x/0x%08x FWH decode %sabled", + print(MSG_DEBUG, "\n0x%08x/0x%08x FWH decode %sabled", (0xff4 + i) * 0x100000, (0xff0 + i) * 0x100000, (fwh_conf >> i) & 0x1 ? "en" : "dis"); @@ -359,7 +359,7 @@ static int enable_flash_ich_dc(struct pci_dev *dev, const char *name) fwh_conf = (uint32_t)strtoul(idsel, NULL, 0); /* FIXME: Need to undo this on shutdown. */ - printf("\nSetting IDSEL=0x%x for top 16 MB", fwh_conf); + print(MSG_NORMAL, "\nSetting IDSEL=0x%x for top 16 MB", fwh_conf); pci_write_long(dev, 0xd0, fwh_conf); pci_write_word(dev, 0xd4, fwh_conf); } @@ -377,10 +377,10 @@ static int enable_flash_vt8237s_spi(struct pci_dev *dev, const char *name) uint32_t mmio_base; mmio_base = (pci_read_long(dev, 0xbc)) << 8; - printf_debug("MMIO base at = 0x%x\n", mmio_base); + print(MSG_DEBUG, "MMIO base at = 0x%x\n", mmio_base); spibar = physmap("VT8237S MMIO registers", mmio_base, 0x70); - printf_debug("0x6c: 0x%04x (CLOCK/DEBUG)\n", + print(MSG_DEBUG, "0x6c: 0x%04x (CLOCK/DEBUG)\n", mmio_readw(spibar + 0x6c)); /* Not sure if it speaks all these bus protocols. */ @@ -408,20 +408,20 @@ static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name, /* Get physical address of Root Complex Register Block */ tmp = pci_read_long(dev, 0xf0) & 0xffffc000; - printf_debug("\nRoot Complex Register Block address = 0x%x\n", tmp); + print(MSG_DEBUG, "\nRoot Complex Register Block address = 0x%x\n", tmp); /* Map RCBA to virtual memory */ rcrb = physmap("ICH RCRB", tmp, 0x4000); gcs = mmio_readl(rcrb + 0x3410); - printf_debug("GCS = 0x%x: ", gcs); - printf_debug("BIOS Interface Lock-Down: %sabled, ", + print(MSG_DEBUG, "GCS = 0x%x: ", gcs); + print(MSG_DEBUG, "BIOS Interface Lock-Down: %sabled, ", (gcs & 0x1) ? "en" : "dis"); bbs = (gcs >> 10) & 0x3; - printf_debug("BOOT BIOS Straps: 0x%x (%s)\n", bbs, straps_names[bbs]); + print(MSG_DEBUG, "BOOT BIOS Straps: 0x%x (%s)\n", bbs, straps_names[bbs]); buc = mmio_readb(rcrb + 0x3414); - printf_debug("Top Swap : %s\n", + print(MSG_DEBUG, "Top Swap : %s\n", (buc & 1) ? "enabled (A16 inverted)" : "not enabled"); /* It seems the ICH7 does not support SPI and LPC chips at the same @@ -459,105 +459,105 @@ static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name, } /* SPIBAR is at RCRB+0x3020 for ICH[78] and RCRB+0x3800 for ICH9. */ - printf_debug("SPIBAR = 0x%x + 0x%04x\n", tmp, spibar_offset); + print(MSG_DEBUG, "SPIBAR = 0x%x + 0x%04x\n", tmp, spibar_offset); /* Assign Virtual Address */ spibar = rcrb + spibar_offset; switch (spi_controller) { case SPI_CONTROLLER_ICH7: - printf_debug("0x00: 0x%04x (SPIS)\n", + print(MSG_DEBUG, "0x00: 0x%04x (SPIS)\n", mmio_readw(spibar + 0)); - printf_debug("0x02: 0x%04x (SPIC)\n", + print(MSG_DEBUG, "0x02: 0x%04x (SPIC)\n", mmio_readw(spibar + 2)); - printf_debug("0x04: 0x%08x (SPIA)\n", + print(MSG_DEBUG, "0x04: 0x%08x (SPIA)\n", mmio_readl(spibar + 4)); for (i = 0; i < 8; i++) { int offs; offs = 8 + (i * 8); - printf_debug("0x%02x: 0x%08x (SPID%d)\n", offs, + print(MSG_DEBUG, "0x%02x: 0x%08x (SPID%d)\n", offs, mmio_readl(spibar + offs), i); - printf_debug("0x%02x: 0x%08x (SPID%d+4)\n", offs + 4, + print(MSG_DEBUG, "0x%02x: 0x%08x (SPID%d+4)\n", offs + 4, mmio_readl(spibar + offs + 4), i); } - printf_debug("0x50: 0x%08x (BBAR)\n", + print(MSG_DEBUG, "0x50: 0x%08x (BBAR)\n", mmio_readl(spibar + 0x50)); - printf_debug("0x54: 0x%04x (PREOP)\n", + print(MSG_DEBUG, "0x54: 0x%04x (PREOP)\n", mmio_readw(spibar + 0x54)); - printf_debug("0x56: 0x%04x (OPTYPE)\n", + print(MSG_DEBUG, "0x56: 0x%04x (OPTYPE)\n", mmio_readw(spibar + 0x56)); - printf_debug("0x58: 0x%08x (OPMENU)\n", + print(MSG_DEBUG, "0x58: 0x%08x (OPMENU)\n", mmio_readl(spibar + 0x58)); - printf_debug("0x5c: 0x%08x (OPMENU+4)\n", + print(MSG_DEBUG, "0x5c: 0x%08x (OPMENU+4)\n", mmio_readl(spibar + 0x5c)); for (i = 0; i < 4; i++) { int offs; offs = 0x60 + (i * 4); - printf_debug("0x%02x: 0x%08x (PBR%d)\n", offs, + print(MSG_DEBUG, "0x%02x: 0x%08x (PBR%d)\n", offs, mmio_readl(spibar + offs), i); } - printf_debug("\n"); + print(MSG_DEBUG, "\n"); if (mmio_readw(spibar) & (1 << 15)) { - printf("WARNING: SPI Configuration Lockdown activated.\n"); + print(MSG_NORMAL, "WARNING: SPI Configuration Lockdown activated.\n"); ichspi_lock = 1; } ich_init_opcodes(); break; case SPI_CONTROLLER_ICH9: tmp2 = mmio_readw(spibar + 4); - printf_debug("0x04: 0x%04x (HSFS)\n", tmp2); - printf_debug("FLOCKDN %i, ", (tmp2 >> 15 & 1)); - printf_debug("FDV %i, ", (tmp2 >> 14) & 1); - printf_debug("FDOPSS %i, ", (tmp2 >> 13) & 1); - printf_debug("SCIP %i, ", (tmp2 >> 5) & 1); - printf_debug("BERASE %i, ", (tmp2 >> 3) & 3); - printf_debug("AEL %i, ", (tmp2 >> 2) & 1); - printf_debug("FCERR %i, ", (tmp2 >> 1) & 1); - printf_debug("FDONE %i\n", (tmp2 >> 0) & 1); + print(MSG_DEBUG, "0x04: 0x%04x (HSFS)\n", tmp2); + print(MSG_DEBUG, "FLOCKDN %i, ", (tmp2 >> 15 & 1)); + print(MSG_DEBUG, "FDV %i, ", (tmp2 >> 14) & 1); + print(MSG_DEBUG, "FDOPSS %i, ", (tmp2 >> 13) & 1); + print(MSG_DEBUG, "SCIP %i, ", (tmp2 >> 5) & 1); + print(MSG_DEBUG, "BERASE %i, ", (tmp2 >> 3) & 3); + print(MSG_DEBUG, "AEL %i, ", (tmp2 >> 2) & 1); + print(MSG_DEBUG, "FCERR %i, ", (tmp2 >> 1) & 1); + print(MSG_DEBUG, "FDONE %i\n", (tmp2 >> 0) & 1); tmp = mmio_readl(spibar + 0x50); - printf_debug("0x50: 0x%08x (FRAP)\n", tmp); - printf_debug("BMWAG %i, ", (tmp >> 24) & 0xff); - printf_debug("BMRAG %i, ", (tmp >> 16) & 0xff); - printf_debug("BRWA %i, ", (tmp >> 8) & 0xff); - printf_debug("BRRA %i\n", (tmp >> 0) & 0xff); + print(MSG_DEBUG, "0x50: 0x%08x (FRAP)\n", tmp); + print(MSG_DEBUG, "BMWAG %i, ", (tmp >> 24) & 0xff); + print(MSG_DEBUG, "BMRAG %i, ", (tmp >> 16) & 0xff); + print(MSG_DEBUG, "BRWA %i, ", (tmp >> 8) & 0xff); + print(MSG_DEBUG, "BRRA %i\n", (tmp >> 0) & 0xff); - printf_debug("0x54: 0x%08x (FREG0)\n", + print(MSG_DEBUG, "0x54: 0x%08x (FREG0)\n", mmio_readl(spibar + 0x54)); - printf_debug("0x58: 0x%08x (FREG1)\n", + print(MSG_DEBUG, "0x58: 0x%08x (FREG1)\n", mmio_readl(spibar + 0x58)); - printf_debug("0x5C: 0x%08x (FREG2)\n", + print(MSG_DEBUG, "0x5C: 0x%08x (FREG2)\n", mmio_readl(spibar + 0x5C)); - printf_debug("0x60: 0x%08x (FREG3)\n", + print(MSG_DEBUG, "0x60: 0x%08x (FREG3)\n", mmio_readl(spibar + 0x60)); - printf_debug("0x64: 0x%08x (FREG4)\n", + print(MSG_DEBUG, "0x64: 0x%08x (FREG4)\n", mmio_readl(spibar + 0x64)); - printf_debug("0x74: 0x%08x (PR0)\n", + print(MSG_DEBUG, "0x74: 0x%08x (PR0)\n", mmio_readl(spibar + 0x74)); - printf_debug("0x78: 0x%08x (PR1)\n", + print(MSG_DEBUG, "0x78: 0x%08x (PR1)\n", mmio_readl(spibar + 0x78)); - printf_debug("0x7C: 0x%08x (PR2)\n", + print(MSG_DEBUG, "0x7C: 0x%08x (PR2)\n", mmio_readl(spibar + 0x7C)); - printf_debug("0x80: 0x%08x (PR3)\n", + print(MSG_DEBUG, "0x80: 0x%08x (PR3)\n", mmio_readl(spibar + 0x80)); - printf_debug("0x84: 0x%08x (PR4)\n", + print(MSG_DEBUG, "0x84: 0x%08x (PR4)\n", mmio_readl(spibar + 0x84)); - printf_debug("0x90: 0x%08x (SSFS, SSFC)\n", + print(MSG_DEBUG, "0x90: 0x%08x (SSFS, SSFC)\n", mmio_readl(spibar + 0x90)); - printf_debug("0x94: 0x%04x (PREOP)\n", + print(MSG_DEBUG, "0x94: 0x%04x (PREOP)\n", mmio_readw(spibar + 0x94)); - printf_debug("0x96: 0x%04x (OPTYPE)\n", + print(MSG_DEBUG, "0x96: 0x%04x (OPTYPE)\n", mmio_readw(spibar + 0x96)); - printf_debug("0x98: 0x%08x (OPMENU)\n", + print(MSG_DEBUG, "0x98: 0x%08x (OPMENU)\n", mmio_readl(spibar + 0x98)); - printf_debug("0x9C: 0x%08x (OPMENU+4)\n", + print(MSG_DEBUG, "0x9C: 0x%08x (OPMENU+4)\n", mmio_readl(spibar + 0x9C)); - printf_debug("0xA0: 0x%08x (BBAR)\n", + print(MSG_DEBUG, "0xA0: 0x%08x (BBAR)\n", mmio_readl(spibar + 0xA0)); - printf_debug("0xB0: 0x%08x (FDOC)\n", + print(MSG_DEBUG, "0xB0: 0x%08x (FDOC)\n", mmio_readl(spibar + 0xB0)); if (tmp2 & (1 << 15)) { - printf("WARNING: SPI Configuration Lockdown activated.\n"); + print(MSG_NORMAL, "WARNING: SPI Configuration Lockdown activated.\n"); ichspi_lock = 1; } ich_init_opcodes(); @@ -568,18 +568,18 @@ static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name, } old = pci_read_byte(dev, 0xdc); - printf_debug("SPI Read Configuration: "); + print(MSG_DEBUG, "SPI Read Configuration: "); new = (old >> 2) & 0x3; switch (new) { case 0: case 1: case 2: - printf_debug("prefetching %sabled, caching %sabled, ", + print(MSG_DEBUG, "prefetching %sabled, caching %sabled, ", (new & 0x2) ? "en" : "dis", (new & 0x1) ? "dis" : "en"); break; default: - printf_debug("invalid prefetching/caching settings, "); + print(MSG_DEBUG, "invalid prefetching/caching settings, "); break; } @@ -619,7 +619,7 @@ static int enable_flash_vt823x(struct pci_dev *dev, const char *name) pci_write_byte(dev, 0x40, val); if (pci_read_byte(dev, 0x40) != val) { - printf("\nWARNING: Failed to enable flash write on \"%s\"\n", + print(MSG_NORMAL, "\nWARNING: Failed to enable flash write on \"%s\"\n", name); return -1; } @@ -703,7 +703,7 @@ static int enable_flash_sc1100(struct pci_dev *dev, const char *name) new = pci_read_byte(dev, 0x52); if (new != 0xee) { - printf_debug("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x52, new, name); + print(MSG_DEBUG, "tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x52, new, name); return -1; } @@ -721,7 +721,7 @@ static int enable_flash_amd8111(struct pci_dev *dev, const char *name) if (new != old) { pci_write_byte(dev, 0x43, new); if (pci_read_byte(dev, 0x43) != new) { - printf_debug("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x43, new, name); + print(MSG_DEBUG, "tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x43, new, name); } } @@ -733,7 +733,7 @@ static int enable_flash_amd8111(struct pci_dev *dev, const char *name) pci_write_byte(dev, 0x40, new); if (pci_read_byte(dev, 0x40) != new) { - printf_debug("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name); + print(MSG_DEBUG, "tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name); return -1; } @@ -753,7 +753,7 @@ static int enable_flash_sb600(struct pci_dev *dev, const char *name) /* No protection flags for this region?*/ if ((prot & 0x3) == 0) continue; - printf_debug("SB600 %s%sprotected from %u to %u\n", + print(MSG_DEBUG, "SB600 %s%sprotected from %u to %u\n", (prot & 0x1) ? "write " : "", (prot & 0x2) ? "read " : "", (prot & 0xfffffc00), @@ -762,7 +762,7 @@ static int enable_flash_sb600(struct pci_dev *dev, const char *name) pci_write_byte(dev, reg, prot); prot = pci_read_long(dev, reg); if (prot & 0x3) - printf("SB600 %s%sunprotect failed from %u to %u\n", + print(MSG_NORMAL, "SB600 %s%sunprotect failed from %u to %u\n", (prot & 0x1) ? "write " : "", (prot & 0x2) ? "read " : "", (prot & 0xfffffc00), @@ -772,7 +772,7 @@ static int enable_flash_sb600(struct pci_dev *dev, const char *name) /* Read SPI_BaseAddr */ tmp = pci_read_long(dev, 0xa0); tmp &= 0xffffffe0; /* remove bits 4-0 (reserved) */ - printf_debug("SPI base address is at 0x%x\n", tmp); + print(MSG_DEBUG, "SPI base address is at 0x%x\n", tmp); /* If the BAR has address 0, it is unlikely SPI is used. */ if (!tmp) @@ -788,17 +788,17 @@ static int enable_flash_sb600(struct pci_dev *dev, const char *name) sb600_spibar += tmp & 0xfff; tmp = pci_read_long(dev, 0xa0); - printf_debug("AltSpiCSEnable=%i, SpiRomEnable=%i, " + print(MSG_DEBUG, "AltSpiCSEnable=%i, SpiRomEnable=%i, " "AbortEnable=%i\n", tmp & 0x1, (tmp & 0x2) >> 1, (tmp & 0x4) >> 2); tmp = (pci_read_byte(dev, 0xba) & 0x4) >> 2; - printf_debug("PrefetchEnSPIFromIMC=%i, ", tmp); + print(MSG_DEBUG, "PrefetchEnSPIFromIMC=%i, ", tmp); tmp = pci_read_byte(dev, 0xbb); - printf_debug("PrefetchEnSPIFromHost=%i, SpiOpEnInLpcMode=%i\n", + print(MSG_DEBUG, "PrefetchEnSPIFromHost=%i, SpiOpEnInLpcMode=%i\n", tmp & 0x1, (tmp & 0x20) >> 5); tmp = mmio_readl(sb600_spibar); - printf_debug("SpiArbEnable=%i, SpiAccessMacRomEn=%i, " + print(MSG_DEBUG, "SpiArbEnable=%i, SpiAccessMacRomEn=%i, " "SpiHostAccessRomEn=%i, ArbWaitCount=%i, " "SpiBridgeDisable=%i, DropOneClkOnRd=%i\n", (tmp >> 19) & 0x1, (tmp >> 22) & 0x1, @@ -810,7 +810,7 @@ static int enable_flash_sb600(struct pci_dev *dev, const char *name) smbus_dev = pci_dev_find(0x1002, 0x4385); if (has_spi && !smbus_dev) { - fprintf(stderr, "ERROR: SMBus device not found. Not enabling SPI.\n"); + print(MSG_ERROR, "ERROR: SMBus device not found. Not enabling SPI.\n"); has_spi = 0; } if (has_spi) { @@ -818,22 +818,22 @@ static int enable_flash_sb600(struct pci_dev *dev, const char *name) /* GPIO11/SPI_DO and GPIO12/SPI_DI status */ reg = pci_read_byte(smbus_dev, 0xAB); reg &= 0xC0; - printf_debug("GPIO11 used for %s\n", (reg & (1 << 6)) ? "GPIO" : "SPI_DO"); - printf_debug("GPIO12 used for %s\n", (reg & (1 << 7)) ? "GPIO" : "SPI_DI"); + print(MSG_DEBUG, "GPIO11 used for %s\n", (reg & (1 << 6)) ? "GPIO" : "SPI_DO"); + print(MSG_DEBUG, "GPIO12 used for %s\n", (reg & (1 << 7)) ? "GPIO" : "SPI_DI"); if (reg != 0x00) has_spi = 0; /* GPIO31/SPI_HOLD and GPIO32/SPI_CS status */ reg = pci_read_byte(smbus_dev, 0x83); reg &= 0xC0; - printf_debug("GPIO31 used for %s\n", (reg & (1 << 6)) ? "GPIO" : "SPI_HOLD"); - printf_debug("GPIO32 used for %s\n", (reg & (1 << 7)) ? "GPIO" : "SPI_CS"); + print(MSG_DEBUG, "GPIO31 used for %s\n", (reg & (1 << 6)) ? "GPIO" : "SPI_HOLD"); + print(MSG_DEBUG, "GPIO32 used for %s\n", (reg & (1 << 7)) ? "GPIO" : "SPI_CS"); /* SPI_HOLD is not used on all boards, filter it out. */ if ((reg & 0x80) != 0x00) has_spi = 0; /* GPIO47/SPI_CLK status */ reg = pci_read_byte(smbus_dev, 0xA7); reg &= 0x40; - printf_debug("GPIO47 used for %s\n", (reg & (1 << 6)) ? "GPIO" : "SPI_CLK"); + print(MSG_DEBUG, "GPIO47 used for %s\n", (reg & (1 << 6)) ? "GPIO" : "SPI_CLK"); if (reg != 0x00) has_spi = 0; } @@ -848,24 +848,24 @@ static int enable_flash_sb600(struct pci_dev *dev, const char *name) OUTB(0x8f, 0xcd6); reg = INB(0xcd7); reg &= 0x0e; - printf_debug("ROM strap override is %sactive", (reg & 0x02) ? "" : "not "); + print(MSG_DEBUG, "ROM strap override is %sactive", (reg & 0x02) ? "" : "not "); if (reg & 0x02) { switch ((reg & 0x0c) >> 2) { case 0x00: - printf_debug(": LPC"); + print(MSG_DEBUG, ": LPC"); break; case 0x01: - printf_debug(": PCI"); + print(MSG_DEBUG, ": PCI"); break; case 0x02: - printf_debug(": FWH"); + print(MSG_DEBUG, ": FWH"); break; case 0x03: - printf_debug(": SPI"); + print(MSG_DEBUG, ": SPI"); break; } } - printf_debug("\n"); + print(MSG_DEBUG, "\n"); /* Force enable SPI ROM in SB600 PM register. * If we enable SPI ROM here, we have to disable it after we leave. @@ -904,7 +904,7 @@ static int enable_flash_ck804(struct pci_dev *dev, const char *name) if (new != old) { pci_write_byte(dev, 0x88, new); if (pci_read_byte(dev, 0x88) != new) { - printf_debug("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x88, new, name); + print(MSG_DEBUG, "tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x88, new, name); } } @@ -915,7 +915,7 @@ static int enable_flash_ck804(struct pci_dev *dev, const char *name) pci_write_byte(dev, 0x6d, new); if (pci_read_byte(dev, 0x6d) != new) { - printf_debug("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name); + print(MSG_DEBUG, "tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name); return -1; } @@ -932,7 +932,7 @@ static int enable_flash_sb400(struct pci_dev *dev, const char *name) smbusdev = pci_dev_find(0x1002, 0x4372); if (!smbusdev) { - fprintf(stderr, "ERROR: SMBus device not found. Aborting.\n"); + print(MSG_ERROR, "ERROR: SMBus device not found. Aborting.\n"); exit(1); } @@ -981,7 +981,7 @@ static int enable_flash_mcp55(struct pci_dev *dev, const char *name) pci_write_byte(dev, 0x6d, new); if (pci_read_byte(dev, 0x6d) != new) { - printf_debug("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name); + print(MSG_DEBUG, "tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name); return -1; } @@ -1043,7 +1043,7 @@ static int get_flashbase_sc520(struct pci_dev *dev, const char *name) flashbase = parx << 12; } } else { - printf("AMD Elan SC520 detected, but no BOOTCS. Assuming flash at 4G\n"); + print(MSG_NORMAL, "AMD Elan SC520 detected, but no BOOTCS. Assuming flash at 4G\n"); } /* 4. Clean up */ @@ -1184,18 +1184,18 @@ int chipset_flash_enable(void) } if (dev) { - printf("Found chipset \"%s %s\", enabling flash write... ", + print(MSG_NORMAL, "Found chipset \"%s %s\", enabling flash write... ", chipset_enables[i].vendor_name, chipset_enables[i].device_name); ret = chipset_enables[i].doit(dev, chipset_enables[i].device_name); if (ret) - printf("FAILED!\n"); + print(MSG_NORMAL, "FAILED!\n"); else - printf("OK.\n"); + print(MSG_NORMAL, "OK.\n"); } - printf("This chipset supports the following protocols: %s.\n", + print(MSG_NORMAL, "This chipset supports the following protocols: %s.\n", flashbuses_to_text(buses_supported)); return ret; diff --git a/dummyflasher.c b/dummyflasher.c index 903f88b..205f062 100644 --- a/dummyflasher.c +++ b/dummyflasher.c @@ -27,7 +27,7 @@ int dummy_init(void) { int i; - printf_debug("%s\n", __func__); + print(MSG_DEBUG, "%s\n", __func__); /* "all" is equivalent to specifying no type. */ if (programmer_param && (!strcmp(programmer_param, "all"))) { @@ -43,94 +43,94 @@ int dummy_init(void) buses_supported = CHIP_BUSTYPE_NONE; if (strstr(programmer_param, "parallel")) { buses_supported |= CHIP_BUSTYPE_PARALLEL; - printf_debug("Enabling support for %s flash.\n", "parallel"); + print(MSG_DEBUG, "Enabling support for %s flash.\n", "parallel"); } if (strstr(programmer_param, "lpc")) { buses_supported |= CHIP_BUSTYPE_LPC; - printf_debug("Enabling support for %s flash.\n", "LPC"); + print(MSG_DEBUG, "Enabling support for %s flash.\n", "LPC"); } if (strstr(programmer_param, "fwh")) { buses_supported |= CHIP_BUSTYPE_FWH; - printf_debug("Enabling support for %s flash.\n", "FWH"); + print(MSG_DEBUG, "Enabling support for %s flash.\n", "FWH"); } if (strstr(programmer_param, "spi")) { buses_supported |= CHIP_BUSTYPE_SPI; spi_controller = SPI_CONTROLLER_DUMMY; - printf_debug("Enabling support for %s flash.\n", "SPI"); + print(MSG_DEBUG, "Enabling support for %s flash.\n", "SPI"); } if (buses_supported == CHIP_BUSTYPE_NONE) - printf_debug("Support for all flash bus types disabled.\n"); + print(MSG_DEBUG, "Support for all flash bus types disabled.\n"); free(programmer_param); return 0; } int dummy_shutdown(void) { - printf_debug("%s\n", __func__); + print(MSG_DEBUG, "%s\n", __func__); return 0; } void *dummy_map(const char *descr, unsigned long phys_addr, size_t len) { - printf_debug("%s: Mapping %s, 0x%lx bytes at 0x%08lx\n", + print(MSG_DEBUG, "%s: Mapping %s, 0x%lx bytes at 0x%08lx\n", __func__, descr, (unsigned long)len, phys_addr); return (void *)phys_addr; } void dummy_unmap(void *virt_addr, size_t len) { - printf_debug("%s: Unmapping 0x%lx bytes at %p\n", + print(MSG_DEBUG, "%s: Unmapping 0x%lx bytes at %p\n", __func__, (unsigned long)len, virt_addr); } void dummy_chip_writeb(uint8_t val, chipaddr addr) { - printf_debug("%s: addr=0x%lx, val=0x%02x\n", __func__, addr, val); + print(MSG_DEBUG, "%s: addr=0x%lx, val=0x%02x\n", __func__, addr, val); } void dummy_chip_writew(uint16_t val, chipaddr addr) { - printf_debug("%s: addr=0x%lx, val=0x%04x\n", __func__, addr, val); + print(MSG_DEBUG, "%s: addr=0x%lx, val=0x%04x\n", __func__, addr, val); } void dummy_chip_writel(uint32_t val, chipaddr addr) { - printf_debug("%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val); + print(MSG_DEBUG, "%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val); } void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len) { size_t i; - printf_debug("%s: addr=0x%lx, len=0x%08lx, writing data (hex):", + print(MSG_DEBUG, "%s: addr=0x%lx, len=0x%08lx, writing data (hex):", __func__, addr, (unsigned long)len); for (i = 0; i < len; i++) { if ((i % 16) == 0) - printf_debug("\n"); - printf_debug("%02x ", buf[i]) + print(MSG_DEBUG, "\n"); + print(MSG_DEBUG, "%02x ", buf[i]) } } uint8_t dummy_chip_readb(const chipaddr addr) { - printf_debug("%s: addr=0x%lx, returning 0xff\n", __func__, addr); + print(MSG_DEBUG, "%s: addr=0x%lx, returning 0xff\n", __func__, addr); return 0xff; } uint16_t dummy_chip_readw(const chipaddr addr) { - printf_debug("%s: addr=0x%lx, returning 0xffff\n", __func__, addr); + print(MSG_DEBUG, "%s: addr=0x%lx, returning 0xffff\n", __func__, addr); return 0xffff; } uint32_t dummy_chip_readl(const chipaddr addr) { - printf_debug("%s: addr=0x%lx, returning 0xffffffff\n", __func__, addr); + print(MSG_DEBUG, "%s: addr=0x%lx, returning 0xffffffff\n", __func__, addr); return 0xffffffff; } void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len) { - printf_debug("%s: addr=0x%lx, len=0x%lx, returning array of 0xff\n", + print(MSG_DEBUG, "%s: addr=0x%lx, len=0x%lx, returning array of 0xff\n", __func__, addr, (unsigned long)len); memset(buf, 0xff, len); return; @@ -141,18 +141,18 @@ int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt, { int i; - printf_debug("%s:", __func__); + print(MSG_DEBUG, "%s:", __func__); - printf_debug(" writing %u bytes:", writecnt); + print(MSG_DEBUG, " writing %u bytes:", writecnt); for (i = 0; i < writecnt; i++) - printf_debug(" 0x%02x", writearr[i]); + print(MSG_DEBUG, " 0x%02x", writearr[i]); - printf_debug(" reading %u bytes:", readcnt); + print(MSG_DEBUG, " reading %u bytes:", readcnt); for (i = 0; i < readcnt; i++) { - printf_debug(" 0xff"); + print(MSG_DEBUG, " 0xff"); readarr[i] = 0xff; } - printf_debug("\n"); + print(MSG_DEBUG, "\n"); return 0; } diff --git a/en29f002a.c b/en29f002a.c index 020df32..7da01c9 100644 --- a/en29f002a.c +++ b/en29f002a.c @@ -47,7 +47,7 @@ int probe_en29f512(struct flashchip *flash) chip_writeb(0x55, bios + 0x2AA); chip_writeb(0xF0, bios + 0x555); - printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); + print(MSG_DEBUG, "%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); if (id1 == flash->manufacture_id && id2 == flash->model_id) return 1; @@ -80,7 +80,7 @@ int probe_en29f002a(struct flashchip *flash) chip_writeb(0x55, bios + 0xAAA); chip_writeb(0xF0, bios + 0x555); - printf_debug("%s: id1 0x%x, id2 0x%x\n", __func__, id1, id2); + print(MSG_DEBUG, "%s: id1 0x%x, id2 0x%x\n", __func__, id1, id2); if (id1 == flash->manufacture_id && id2 == flash->model_id) return 1; diff --git a/flashrom.c b/flashrom.c index 64a6835..6396e79 100644 --- a/flashrom.c +++ b/flashrom.c @@ -368,7 +368,7 @@ char *extract_param(char **haystack, char *needle, char *delim) if (devlen) { dev = malloc(devlen + 1); if (!dev) { - fprintf(stderr, "Out of memory!\n"); + print(MSG_ERROR, "Out of memory!\n"); exit(1); } strncpy(dev, param_pos, devlen); @@ -380,7 +380,7 @@ char *extract_param(char **haystack, char *needle, char *delim) memmove(param_pos, rest, strlen(rest) + 1); tmp = realloc(*haystack, strlen(*haystack) + 1); if (!tmp) { - fprintf(stderr, "Out of memory!\n"); + print(MSG_ERROR, "Out of memory!\n"); exit(1); } *haystack = tmp; @@ -397,7 +397,7 @@ int check_erased_range(struct flashchip *flash, int start, int len) uint8_t *cmpbuf = malloc(len); if (!cmpbuf) { - fprintf(stderr, "Could not allocate memory!\n"); + print(MSG_ERROR, "Could not allocate memory!\n"); exit(1); } memset(cmpbuf, 0xff, len); @@ -425,16 +425,16 @@ int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, c goto out_free; if (!flash->read) { - fprintf(stderr, "ERROR: flashrom has no read function for this flash chip.\n"); + print(MSG_ERROR, "ERROR: flashrom has no read function for this flash chip.\n"); return 1; } if (!readbuf) { - fprintf(stderr, "Could not allocate memory!\n"); + print(MSG_ERROR, "Could not allocate memory!\n"); exit(1); } if (start + len > flash->total_size * 1024) { - fprintf(stderr, "Error: %s called with start 0x%x + len 0x%x >" + print(MSG_ERROR, "Error: %s called with start 0x%x + len 0x%x >" " total_size 0x%x\n", __func__, start, len, flash->total_size * 1024); ret = -1; @@ -462,7 +462,7 @@ int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, c if (cmpbuf[starthere - start + j] != readbuf[j]) { /* Only print the first failure. */ if (!failcount++) - fprintf(stderr, "%s FAILED at 0x%08x! " + print(MSG_ERROR, "%s FAILED at 0x%08x! " "Expected=0x%02x, Read=0x%02x,", message, starthere + j, cmpbuf[starthere - start + j], @@ -471,7 +471,7 @@ int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, c } } if (failcount) { - fprintf(stderr, " failed byte count from 0x%08x-0x%08x: 0x%x\n", + print(MSG_ERROR, " failed byte count from 0x%08x-0x%08x: 0x%x\n", start, start + len - 1, failcount); ret = -1; } @@ -535,7 +535,7 @@ int generate_testpattern(uint8_t *buf, uint32_t size, int variant) int i; if (!buf) { - fprintf(stderr, "Invalid buffer!\n"); + print(MSG_ERROR, "Invalid buffer!\n"); return 1; } @@ -623,7 +623,7 @@ int check_max_decode(enum chipbustype buses, uint32_t size) if ((buses & CHIP_BUSTYPE_PARALLEL) && (max_rom_decode.parallel < size)) { limitexceeded++; - printf_debug("Chip size %u kB is bigger than supported " + print(MSG_DEBUG, "Chip size %u kB is bigger than supported " "size %u kB of chipset/board/programmer " "for %s interface, " "probe/read/erase/write may fail. ", size / 1024, @@ -631,7 +631,7 @@ int check_max_decode(enum chipbustype buses, uint32_t size) } if ((buses & CHIP_BUSTYPE_LPC) && (max_rom_decode.lpc < size)) { limitexceeded++; - printf_debug("Chip size %u kB is bigger than supported " + print(MSG_DEBUG, "Chip size %u kB is bigger than supported " "size %u kB of chipset/board/programmer " "for %s interface, " "probe/read/erase/write may fail. ", size / 1024, @@ -639,7 +639,7 @@ int check_max_decode(enum chipbustype buses, uint32_t size) } if ((buses & CHIP_BUSTYPE_FWH) && (max_rom_decode.fwh < size)) { limitexceeded++; - printf_debug("Chip size %u kB is bigger than supported " + print(MSG_DEBUG, "Chip size %u kB is bigger than supported " "size %u kB of chipset/board/programmer " "for %s interface, " "probe/read/erase/write may fail. ", size / 1024, @@ -647,7 +647,7 @@ int check_max_decode(enum chipbustype buses, uint32_t size) } if ((buses & CHIP_BUSTYPE_SPI) && (max_rom_decode.spi < size)) { limitexceeded++; - printf_debug("Chip size %u kB is bigger than supported " + print(MSG_DEBUG, "Chip size %u kB is bigger than supported " "size %u kB of chipset/board/programmer " "for %s interface, " "probe/read/erase/write may fail. ", size / 1024, @@ -659,7 +659,7 @@ int check_max_decode(enum chipbustype buses, uint32_t size) * and the limit is not exceeded on all buses. Tell the user. */ if (bitcount(buses) > limitexceeded) - printf_debug("There is at least one common chip/programmer " + print(MSG_DEBUG, "There is at least one common chip/programmer " "interface which can support a chip of this size. " "You can try --force at your own risk.\n"); return 1; @@ -676,19 +676,19 @@ struct flashchip *probe_flash(struct flashchip *first_flash, int force) for (flash = first_flash; flash && flash->name; flash++) { if (chip_to_probe && strcmp(flash->name, chip_to_probe) != 0) continue; - printf_debug("Probing for %s %s, %d KB: ", + print(MSG_DEBUG, "Probing for %s %s, %d KB: ", flash->vendor, flash->name, flash->total_size); if (!flash->probe && !force) { - printf_debug("failed! flashrom has no probe function for this flash chip.\n"); + print(MSG_DEBUG, "failed! flashrom has no probe function for this flash chip.\n"); continue; } buses_common = buses_supported & flash->bustype; if (!buses_common) { tmp = flashbuses_to_text(buses_supported); - printf_debug("skipped. Host bus type %s ", tmp); + print(MSG_DEBUG, "skipped. Host bus type %s ", tmp); free(tmp); tmp = flashbuses_to_text(flash->bustype); - printf_debug("and chip bus type %s are incompatible.\n", tmp); + print(MSG_DEBUG, "and chip bus type %s are incompatible.\n", tmp); free(tmp); continue; } @@ -716,7 +716,7 @@ notfound: if (!flash || !flash->name) return NULL; - printf("Found chip \"%s %s\" (%d KB, %s) at physical address 0x%lx.\n", + print(MSG_NORMAL, "Found chip \"%s %s\" (%d KB, %s) at physical address 0x%lx.\n", flash->vendor, flash->name, flash->total_size, flashbuses_to_text(flash->bustype), base); @@ -728,12 +728,12 @@ int verify_flash(struct flashchip *flash, uint8_t *buf) int ret; int total_size = flash->total_size * 1024; - printf("Verifying flash... "); + print(MSG_NORMAL, "Verifying flash... "); ret = verify_range(flash, buf, 0, total_size, NULL); if (!ret) - printf("VERIFIED. \n"); + print(MSG_NORMAL, "VERIFIED. \n"); return ret; } @@ -746,17 +746,17 @@ int read_flash(struct flashchip *flash, char *filename) unsigned char *buf = calloc(size, sizeof(char)); if (!filename) { - printf("Error: No filename specified.\n"); + print(MSG_NORMAL, "Error: No filename specified.\n"); return 1; } if ((image = fopen(filename, "w")) == NULL) { perror(filename); exit(1); } - printf("Reading flash... "); + print(MSG_NORMAL, "Reading flash... "); if (!flash->read) { - printf("FAILED!\n"); - fprintf(stderr, "ERROR: flashrom has no read function for this flash chip.\n"); + print(MSG_NORMAL, "FAILED!\n"); + print(MSG_ERROR, "ERROR: flashrom has no read function for this flash chip.\n"); return 1; } else flash->read(flash, buf, 0, size); @@ -764,7 +764,7 @@ int read_flash(struct flashchip *flash, char *filename) numbytes = fwrite(buf, 1, size, image); fclose(image); free(buf); - printf("%s.\n", numbytes == size ? "done" : "FAILED"); + print(MSG_NORMAL, "%s.\n", numbytes == size ? "done" : "FAILED"); if (numbytes != size) return 1; return 0; @@ -774,31 +774,31 @@ int erase_flash(struct flashchip *flash) { int i, j, k, ret = 0, found = 0; - printf("Erasing flash chip... "); + print(MSG_NORMAL, "Erasing flash chip... "); for (k = 0; k < NUM_ERASEFUNCTIONS; k++) { unsigned long done = 0; struct block_eraser eraser = flash->block_erasers[k]; - printf_debug("Looking at blockwise erase function %i... ", k); + print(MSG_DEBUG, "Looking at blockwise erase function %i... ", k); if (!eraser.block_erase && !eraser.eraseblocks[0].count) { - printf_debug("not defined. " + print(MSG_DEBUG, "not defined. " "Looking for another erase function.\n"); continue; } if (!eraser.block_erase && eraser.eraseblocks[0].count) { - printf_debug("eraseblock layout is known, but no " + print(MSG_DEBUG, "eraseblock layout is known, but no " "matching block erase function found. " "Looking for another erase function.\n"); continue; } if (eraser.block_erase && !eraser.eraseblocks[0].count) { - printf_debug("block erase function found, but " + print(MSG_DEBUG, "block erase function found, but " "eraseblock layout is unknown. " "Looking for another erase function.\n"); continue; } found = 1; - printf_debug("trying... "); + print(MSG_DEBUG, "trying... "); for (i = 0; i < NUM_ERASEREGIONS; i++) { /* count==0 for all automatically initialized array * members so the loop below won't be executed for them. @@ -818,25 +818,25 @@ int erase_flash(struct flashchip *flash) /* If no block erase function was found or block erase failed, retry. */ if ((!found || ret) && (flash->erase)) { found = 1; - printf_debug("Trying whole-chip erase function... "); + print(MSG_DEBUG, "Trying whole-chip erase function... "); ret = flash->erase(flash); } if (!found) { - fprintf(stderr, "ERROR: flashrom has no erase function for this flash chip.\n"); + print(MSG_ERROR, "ERROR: flashrom has no erase function for this flash chip.\n"); return 1; } if (ret) { - fprintf(stderr, "FAILED!\n"); + print(MSG_ERROR, "FAILED!\n"); } else { - printf("SUCCESS.\n"); + print(MSG_NORMAL, "SUCCESS.\n"); } return ret; } void emergency_help_message(void) { - fprintf(stderr, "Your flash chip is in an unknown state.\n" + print(MSG_ERROR, "Your flash chip is in an unknown state.\n" "Get help on IRC at irc.freenode.net (channel #flashrom) or\n" "mail flashrom@flashrom.org!\n--------------------" "-----------------------------------------------------------\n" @@ -850,10 +850,10 @@ void usage(const char *name) int remaining = 0; enum programmer p; - printf("usage: %s [-VfLzhR] [-E|-r file|-w file|-v file] [-c chipname]\n" + print(MSG_NORMAL, "usage: %s [-VfLzhR] [-E|-r file|-w file|-v file] [-c chipname]\n" " [-m [vendor:]part] [-l file] [-i image] [-p programmer]\n\n", name); - printf("Please note that the command line interface for flashrom will " + print(MSG_NORMAL, "Please note that the command line interface for flashrom will " "change before\nflashrom 1.0. Do not use flashrom in scripts " "or other automated tools without\nchecking that your flashrom" " version won't interpret options in a different way.\n\n"); @@ -880,27 +880,27 @@ void usage(const char *name) pname = programmer_table[p].name; pnamelen = strlen(pname); if (remaining - pnamelen - 2 < 0) { - printf("\n "); + print(MSG_NORMAL, "\n "); remaining = 43; } else { - printf(" "); + print(MSG_NORMAL, " "); remaining--; } if (p == 0) { - printf("("); + print(MSG_NORMAL, "("); remaining--; } - printf("%s", pname); + print(MSG_NORMAL, "%s", pname); remaining -= pnamelen; if (p < PROGRAMMER_INVALID - 1) { - printf(","); + print(MSG_NORMAL, ","); remaining--; } else { - printf(")\n"); + print(MSG_NORMAL, ")\n"); } } - printf( + print(MSG_NORMAL, " -h | --help: print this help text\n" " -R | --version: print the version (release)\n" "\nYou can specify one of -E, -r, -w, -v or no operation. If no operation is\n" @@ -910,7 +910,7 @@ void usage(const char *name) void print_version(void) { - printf("flashrom v%s\n", flashrom_version); + print(MSG_NORMAL, "flashrom v%s\n", flashrom_version); } int main(int argc, char *argv[]) @@ -969,23 +969,23 @@ int main(int argc, char *argv[]) if (argc > 1) { /* Yes, print them. */ int i; - printf_debug("The arguments are:\n"); + print(MSG_DEBUG, "The arguments are:\n"); for (i = 1; i < argc; ++i) - printf_debug("%s\n", argv[i]); + print(MSG_DEBUG, "%s\n", argv[i]); } /* Safety check. */ if (ARRAY_SIZE(programmer_table) - 1 != PROGRAMMER_INVALID) { - fprintf(stderr, "Programmer table miscompilation!\n"); + print(MSG_ERROR, "Programmer table miscompilation!\n"); exit(1); } if (spi_programmer_count - 1 != SPI_CONTROLLER_INVALID) { - fprintf(stderr, "SPI programmer table miscompilation!\n"); + print(MSG_ERROR, "SPI programmer table miscompilation!\n"); exit(1); } #if BITBANG_SPI_SUPPORT == 1 if (bitbang_spi_master_count - 1 != BITBANG_SPI_INVALID) { - fprintf(stderr, "Bitbanging SPI master table miscompilation!\n"); + print(MSG_ERROR, "Bitbanging SPI master table miscompilation!\n"); exit(1); } #endif @@ -996,7 +996,7 @@ int main(int argc, char *argv[]) switch (opt) { case 'r': if (++operation_specified > 1) { - fprintf(stderr, "More than one operation " + print(MSG_ERROR, "More than one operation " "specified. Aborting.\n"); exit(1); } @@ -1004,7 +1004,7 @@ int main(int argc, char *argv[]) break; case 'w': if (++operation_specified > 1) { - fprintf(stderr, "More than one operation " + print(MSG_ERROR, "More than one operation " "specified. Aborting.\n"); exit(1); } @@ -1013,12 +1013,12 @@ int main(int argc, char *argv[]) case 'v': //FIXME: gracefully handle superfluous -v if (++operation_specified > 1) { - fprintf(stderr, "More than one operation " + print(MSG_ERROR, "More than one operation " "specified. Aborting.\n"); exit(1); } if (dont_verify_it) { - fprintf(stderr, "--verify and --noverify are" + print(MSG_ERROR, "--verify and --noverify are" "mutually exclusive. Aborting.\n"); exit(1); } @@ -1026,7 +1026,7 @@ int main(int argc, char *argv[]) break; case 'n': if (verify_it) { - fprintf(stderr, "--verify and --noverify are" + print(MSG_ERROR, "--verify and --noverify are" "mutually exclusive. Aborting.\n"); exit(1); } @@ -1040,7 +1040,7 @@ int main(int argc, char *argv[]) break; case 'E': if (++operation_specified > 1) { - fprintf(stderr, "More than one operation " + print(MSG_ERROR, "More than one operation " "specified. Aborting.\n"); exit(1); } @@ -1101,7 +1101,7 @@ int main(int argc, char *argv[]) } } if (programmer == PROGRAMMER_INVALID) { - printf("Error: Unknown programmer %s.\n", optarg); + print(MSG_NORMAL, "Error: Unknown programmer %s.\n", optarg); exit(1); } break; @@ -1129,7 +1129,7 @@ int main(int argc, char *argv[]) #endif if (read_it && write_it) { - printf("Error: -r and -w are mutually exclusive.\n"); + print(MSG_NORMAL, "Error: -r and -w are mutually exclusive.\n"); usage(argv[0]); } @@ -1137,12 +1137,12 @@ int main(int argc, char *argv[]) filename = argv[optind++]; if (optind < argc) { - printf("Error: Extra parameter found.\n"); + print(MSG_NORMAL, "Error: Extra parameter found.\n"); usage(argv[0]); } if (programmer_init()) { - fprintf(stderr, "Error: Programmer initialization failed.\n"); + print(MSG_ERROR, "Error: Programmer initialization failed.\n"); exit(1); } @@ -1157,30 +1157,30 @@ int main(int argc, char *argv[]) } if (flashes[1]) { - printf("Multiple flash chips were detected:"); + print(MSG_NORMAL, "Multiple flash chips were detected:"); for (i = 0; i < ARRAY_SIZE(flashes) && flashes[i]; i++) - printf(" %s", flashes[i]->name); - printf("\nPlease specify which chip to use with the -c option.\n"); + print(MSG_NORMAL, " %s", flashes[i]->name); + print(MSG_NORMAL, "\nPlease specify which chip to use with the -c option.\n"); programmer_shutdown(); exit(1); } else if (!flashes[0]) { - printf("No EEPROM/flash device found.\n"); + print(MSG_NORMAL, "No EEPROM/flash device found.\n"); if (!force || !chip_to_probe) { - printf("If you know which flash chip you have, and if this version of flashrom\n"); - printf("supports a similar flash chip, you can try to force read your chip. Run:\n"); - printf("flashrom -f -r -c similar_supported_flash_chip filename\n"); - printf("\n"); - printf("Note: flashrom can never write when the flash chip isn't found automatically.\n"); + print(MSG_NORMAL, "If you know which flash chip you have, and if this version of flashrom\n"); + print(MSG_NORMAL, "supports a similar flash chip, you can try to force read your chip. Run:\n"); + print(MSG_NORMAL, "flashrom -f -r -c similar_supported_flash_chip filename\n"); + print(MSG_NORMAL, "\n"); + print(MSG_NORMAL, "Note: flashrom can never write when the flash chip isn't found automatically.\n"); } if (force && read_it && chip_to_probe) { - printf("Force read (-f -r -c) requested, forcing chip probe success:\n"); + print(MSG_NORMAL, "Force read (-f -r -c) requested, forcing chip probe success:\n"); flashes[0] = probe_flash(flashchips, 1); if (!flashes[0]) { - printf("flashrom does not support a flash chip named '%s'.\n", chip_to_probe); - printf("Run flashrom -L to view the hardware supported in this flashrom version.\n"); + print(MSG_NORMAL, "flashrom does not support a flash chip named '%s'.\n", chip_to_probe); + print(MSG_NORMAL, "Run flashrom -L to view the hardware supported in this flashrom version.\n"); exit(1); } - printf("Please note that forced reads most likely contain garbage.\n"); + print(MSG_NORMAL, "Please note that forced reads most likely contain garbage.\n"); return read_flash(flashes[0], filename); } // FIXME: flash writes stay enabled! @@ -1191,35 +1191,35 @@ int main(int argc, char *argv[]) flash = flashes[0]; if (TEST_OK_MASK != (flash->tested & TEST_OK_MASK)) { - printf("===\n"); + print(MSG_NORMAL, "===\n"); if (flash->tested & TEST_BAD_MASK) { - printf("This flash part has status NOT WORKING for operations:"); + print(MSG_NORMAL, "This flash part has status NOT WORKING for operations:"); if (flash->tested & TEST_BAD_PROBE) - printf(" PROBE"); + print(MSG_NORMAL, " PROBE"); if (flash->tested & TEST_BAD_READ) - printf(" READ"); + print(MSG_NORMAL, " READ"); if (flash->tested & TEST_BAD_ERASE) - printf(" ERASE"); + print(MSG_NORMAL, " ERASE"); if (flash->tested & TEST_BAD_WRITE) - printf(" WRITE"); - printf("\n"); + print(MSG_NORMAL, " WRITE"); + print(MSG_NORMAL, "\n"); } if ((!(flash->tested & TEST_BAD_PROBE) && !(flash->tested & TEST_OK_PROBE)) || (!(flash->tested & TEST_BAD_READ) && !(flash->tested & TEST_OK_READ)) || (!(flash->tested & TEST_BAD_ERASE) && !(flash->tested & TEST_OK_ERASE)) || (!(flash->tested & TEST_BAD_WRITE) && !(flash->tested & TEST_OK_WRITE))) { - printf("This flash part has status UNTESTED for operations:"); + print(MSG_NORMAL, "This flash part has status UNTESTED for operations:"); if (!(flash->tested & TEST_BAD_PROBE) && !(flash->tested & TEST_OK_PROBE)) - printf(" PROBE"); + print(MSG_NORMAL, " PROBE"); if (!(flash->tested & TEST_BAD_READ) && !(flash->tested & TEST_OK_READ)) - printf(" READ"); + print(MSG_NORMAL, " READ"); if (!(flash->tested & TEST_BAD_ERASE) && !(flash->tested & TEST_OK_ERASE)) - printf(" ERASE"); + print(MSG_NORMAL, " ERASE"); if (!(flash->tested & TEST_BAD_WRITE) && !(flash->tested & TEST_OK_WRITE)) - printf(" WRITE"); - printf("\n"); + print(MSG_NORMAL, " WRITE"); + print(MSG_NORMAL, "\n"); } - printf("Please email a report to flashrom@flashrom.org if any " + print(MSG_NORMAL, "Please email a report to flashrom@flashrom.org if any " "of the above operations\nwork correctly for you with " "this flash part. Please include the flashrom\noutput " "with the additional -V option for all operations you " @@ -1230,21 +1230,21 @@ int main(int argc, char *argv[]) size = flash->total_size * 1024; if (check_max_decode((buses_supported & flash->bustype), size) && (!force)) { - fprintf(stderr, "Chip is too big for this programmer " + print(MSG_ERROR, "Chip is too big for this programmer " "(-V gives details). Use --force to override.\n"); programmer_shutdown(); return 1; } if (!(read_it | write_it | verify_it | erase_it)) { - printf("No operations were specified.\n"); + print(MSG_NORMAL, "No operations were specified.\n"); // FIXME: flash writes stay enabled! programmer_shutdown(); exit(1); } if (!filename && !erase_it) { - printf("Error: No filename specified.\n"); + print(MSG_NORMAL, "Error: No filename specified.\n"); // FIXME: flash writes stay enabled! programmer_shutdown(); exit(1); @@ -1258,13 +1258,13 @@ int main(int argc, char *argv[]) if (erase_it) { if (flash->tested & TEST_BAD_ERASE) { - fprintf(stderr, "Erase is not working on this chip. "); + print(MSG_ERROR, "Erase is not working on this chip. "); if (!force) { - fprintf(stderr, "Aborting.\n"); + print(MSG_ERROR, "Aborting.\n"); programmer_shutdown(); return 1; } else { - fprintf(stderr, "Continuing anyway.\n"); + print(MSG_ERROR, "Continuing anyway.\n"); } } if (erase_flash(flash)) { @@ -1281,24 +1281,24 @@ int main(int argc, char *argv[]) struct stat image_stat; if (flash->tested & TEST_BAD_ERASE) { - fprintf(stderr, "Erase is not working on this chip " + print(MSG_ERROR, "Erase is not working on this chip " "and erase is needed for write. "); if (!force) { - fprintf(stderr, "Aborting.\n"); + print(MSG_ERROR, "Aborting.\n"); programmer_shutdown(); return 1; } else { - fprintf(stderr, "Continuing anyway.\n"); + print(MSG_ERROR, "Continuing anyway.\n"); } } if (flash->tested & TEST_BAD_WRITE) { - fprintf(stderr, "Write is not working on this chip. "); + print(MSG_ERROR, "Write is not working on this chip. "); if (!force) { - fprintf(stderr, "Aborting.\n"); + print(MSG_ERROR, "Aborting.\n"); programmer_shutdown(); return 1; } else { - fprintf(stderr, "Continuing anyway.\n"); + print(MSG_ERROR, "Continuing anyway.\n"); } } if ((image = fopen(filename, "r")) == NULL) { @@ -1312,7 +1312,7 @@ int main(int argc, char *argv[]) exit(1); } if (image_stat.st_size != flash->total_size * 1024) { - fprintf(stderr, "Error: Image size doesn't match\n"); + print(MSG_ERROR, "Error: Image size doesn't match\n"); programmer_shutdown(); exit(1); } @@ -1321,7 +1321,7 @@ int main(int argc, char *argv[]) show_id(buf, size, force); fclose(image); if (numbytes != size) { - fprintf(stderr, "Error: Failed to read file. Got %ld bytes, wanted %ld!\n", numbytes, size); + print(MSG_ERROR, "Error: Failed to read file. Got %ld bytes, wanted %ld!\n", numbytes, size); programmer_shutdown(); return 1; } @@ -1334,20 +1334,20 @@ int main(int argc, char *argv[]) // //////////////////////////////////////////////////////////// if (write_it) { - printf("Writing flash chip... "); + print(MSG_NORMAL, "Writing flash chip... "); if (!flash->write) { - fprintf(stderr, "Error: flashrom has no write function for this flash chip.\n"); + print(MSG_ERROR, "Error: flashrom has no write function for this flash chip.\n"); programmer_shutdown(); return 1; } ret = flash->write(flash, buf); if (ret) { - fprintf(stderr, "FAILED!\n"); + print(MSG_ERROR, "FAILED!\n"); emergency_help_message(); programmer_shutdown(); return 1; } else { - printf("COMPLETE.\n"); + print(MSG_NORMAL, "COMPLETE.\n"); } } diff --git a/flashrom_print.c b/flashrom_print.c new file mode 100644 index 0000000..8efb7e7 --- /dev/null +++ b/flashrom_print.c @@ -0,0 +1,63 @@ +#include +#include + +#define MSG_NORMAL 0 +#define MSG_DEBUG 1 +#define MSG_ERROR 2 + +int print(int type, const char *fmt, ...) +{ + va_list ap; + char *p, *sval; + int ival; + double dval; + unsigned int uint; + FILE *output_type; + + switch (type) + { + case MSG_DEBUG: + output_type = STDOUT; + fputs("DEBUG: ", output_type); + break; + case MSG_ERROR: + output_type = STDERR; + fputs("ERROR: ", output_type); + break; + case MSG_NORMAL: + default: + output_type = STDOUT; + break; + } + + va_start(ap, fmt); + for (p = fmt; *p; p++) + { + if (*p != '%') + { + fputs(*p, output_type); + continue; + } + switch (*++p) + { + case 'u': + case 'd': + ival = va_arg(ap, int); + fprintf(output_type, "%d", ival); + break; + case 'f': + dval = va_arg(ap, double); + fprintf(output_type, "%f", dval); + break; + case 's': + for (sval = va_arg(ap, char *); *sval; sval++) + fputs(*sval, output_type); + break; + default: + fputs(*p, output_type); + break; + } + } + va_end(ap); +} + diff --git a/ft2232_spi.c b/ft2232_spi.c index d565a6f..0d7b61b 100644 --- a/ft2232_spi.c +++ b/ft2232_spi.c @@ -51,7 +51,7 @@ int send_buf(struct ftdi_context *ftdic, const unsigned char *buf, int size) int r; r = ftdi_write_data(ftdic, (unsigned char *) buf, size); if (r < 0) { - fprintf(stderr, "ftdi_write_data: %d, %s\n", r, + print(MSG_ERROR, "ftdi_write_data: %d, %s\n", r, ftdi_get_error_string(ftdic)); return 1; } @@ -63,7 +63,7 @@ int get_buf(struct ftdi_context *ftdic, const unsigned char *buf, int size) int r; r = ftdi_read_data(ftdic, (unsigned char *) buf, size); if (r < 0) { - fprintf(stderr, "ftdi_read_data: %d, %s\n", r, + print(MSG_ERROR, "ftdi_read_data: %d, %s\n", r, ftdi_get_error_string(ftdic)); return 1; } @@ -80,7 +80,7 @@ int ft2232_spi_init(void) enum ftdi_interface ft2232_interface = INTERFACE_B; if (ftdi_init(ftdic) < 0) { - fprintf(stderr, "ftdi_init failed\n"); + print(MSG_ERROR, "ftdi_init failed\n"); return EXIT_FAILURE; // TODO } @@ -104,48 +104,48 @@ int ft2232_spi_init(void) ft2232_interface = INTERFACE_B; break; default: - fprintf(stderr, "Invalid interface specified, " + print(MSG_ERROR, "Invalid interface specified, " "using default.\n"); } } free(programmer_param); } - printf_debug("Using device type %s ", + print(MSG_DEBUG, "Using device type %s ", (ft2232_type == FTDI_FT2232H) ? "2232H" : "4232H"); - printf_debug("interface %s\n", + print(MSG_DEBUG, "interface %s\n", (ft2232_interface == INTERFACE_A) ? "A" : "B"); f = ftdi_usb_open(ftdic, 0x0403, ft2232_type); if (f < 0 && f != -5) { - fprintf(stderr, "Unable to open FTDI device: %d (%s)\n", f, + print(MSG_ERROR, "Unable to open FTDI device: %d (%s)\n", f, ftdi_get_error_string(ftdic)); exit(-1); // TODO } if (ftdi_set_interface(ftdic, ft2232_interface) < 0) { - fprintf(stderr, "Unable to select interface: %s\n", + print(MSG_ERROR, "Unable to select interface: %s\n", ftdic->error_str); } if (ftdi_usb_reset(ftdic) < 0) { - fprintf(stderr, "Unable to reset FTDI device\n"); + print(MSG_ERROR, "Unable to reset FTDI device\n"); } if (ftdi_set_latency_timer(ftdic, 2) < 0) { - fprintf(stderr, "Unable to set latency timer\n"); + print(MSG_ERROR, "Unable to set latency timer\n"); } if (ftdi_write_data_set_chunksize(ftdic, 512)) { - fprintf(stderr, "Unable to set chunk size\n"); + print(MSG_ERROR, "Unable to set chunk size\n"); } if (ftdi_set_bitmode(ftdic, 0x00, BITMODE_BITBANG_SPI) < 0) { - fprintf(stderr, "Unable to set bitmode to SPI\n"); + print(MSG_ERROR, "Unable to set bitmode to SPI\n"); } #if CLOCK_5X - printf_debug("Disable divide-by-5 front stage\n"); + print(MSG_DEBUG, "Disable divide-by-5 front stage\n"); buf[0] = 0x8a; /* Disable divide-by-5. */ if (send_buf(ftdic, buf, 1)) return -1; @@ -156,7 +156,7 @@ int ft2232_spi_init(void) #define MPSSE_CLK 12.0 #endif - printf_debug("Set clock divisor\n"); + print(MSG_DEBUG, "Set clock divisor\n"); buf[0] = 0x86; /* command "set divisor" */ /* valueL/valueH are (desired_divisor - 1) */ buf[1] = (DIVIDE_BY - 1) & 0xff; @@ -164,16 +164,16 @@ int ft2232_spi_init(void) if (send_buf(ftdic, buf, 3)) return -1; - printf("SPI clock is %fMHz\n", + print(MSG_NORMAL, "SPI clock is %fMHz\n", (double)(MPSSE_CLK / (((DIVIDE_BY - 1) + 1) * 2))); /* Disconnect TDI/DO to TDO/DI for loopback. */ - printf_debug("No loopback of TDI/DO TDO/DI\n"); + print(MSG_DEBUG, "No loopback of TDI/DO TDO/DI\n"); buf[0] = 0x85; if (send_buf(ftdic, buf, 1)) return -1; - printf_debug("Set data bits\n"); + print(MSG_DEBUG, "Set data bits\n"); /* Set data bits low-byte command: * value: 0x08 CS=high, DI=low, DO=low, SK=low * dir: 0x0b CS=output, DI=input, DO=output, SK=output @@ -185,7 +185,7 @@ int ft2232_spi_init(void) if (send_buf(ftdic, buf, 3)) return -1; - // printf_debug("\nft2232 chosen\n"); + // print(MSG_DEBUG, "\nft2232 chosen\n"); buses_supported = CHIP_BUSTYPE_SPI; spi_controller = SPI_CONTROLLER_FT2232; @@ -212,7 +212,7 @@ int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, if (bufsize > oldbufsize) { buf = realloc(buf, bufsize); if (!buf) { - fprintf(stderr, "Out of memory!\n"); + print(MSG_ERROR, "Out of memory!\n"); exit(1); } oldbufsize = bufsize; @@ -224,7 +224,7 @@ int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, * and deassert CS# all in one shot. If reading, we do three separate * operations. */ - printf_debug("Assert CS#\n"); + print(MSG_DEBUG, "Assert CS#\n"); buf[i++] = SET_BITS_LOW; buf[i++] = 0 & ~CS_BIT; /* assertive */ buf[i++] = 0x0b; @@ -249,7 +249,7 @@ int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, failed = ret; /* We can't abort here, we still have to deassert CS#. */ if (ret) - fprintf(stderr, "send_buf failed before read: %i\n", + print(MSG_ERROR, "send_buf failed before read: %i\n", ret); i = 0; if (ret == 0) { @@ -262,18 +262,18 @@ int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, failed |= ret; /* We can't abort here either. */ if (ret) - fprintf(stderr, "get_buf failed: %i\n", ret); + print(MSG_ERROR, "get_buf failed: %i\n", ret); } } - printf_debug("De-assert CS#\n"); + print(MSG_DEBUG, "De-assert CS#\n"); buf[i++] = SET_BITS_LOW; buf[i++] = CS_BIT; buf[i++] = 0x0b; ret = send_buf(ftdic, buf, i); failed |= ret; if (ret) - fprintf(stderr, "send_buf failed at end: %i\n", ret); + print(MSG_ERROR, "send_buf failed at end: %i\n", ret); return failed ? -1 : 0; } @@ -291,13 +291,13 @@ int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf) spi_disable_blockprotect(); /* Erase first. */ - printf("Erasing flash before programming... "); + print(MSG_NORMAL, "Erasing flash before programming... "); if (erase_flash(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } - printf("done.\n"); - printf_debug("total_size is %d\n", total_size); + print(MSG_NORMAL, "done.\n"); + print(MSG_DEBUG, "total_size is %d\n", total_size); for (i = 0; i < total_size; i += 256) { int l, r; if (i + 256 <= total_size) @@ -306,7 +306,7 @@ int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf) l = total_size - i; if ((r = spi_nbyte_program(i, &buf[i], l))) { - fprintf(stderr, "%s: write fail %d\n", __func__, r); + print(MSG_ERROR, "%s: write fail %d\n", __func__, r); return 1; } diff --git a/gfxnvidia.c b/gfxnvidia.c index 1e9b679..70c8b7b 100644 --- a/gfxnvidia.c +++ b/gfxnvidia.c @@ -64,7 +64,7 @@ int gfxnvidia_init(void) io_base_addr = pcidev_init(PCI_VENDOR_ID_NVIDIA, PCI_BASE_ADDRESS_0, gfx_nvidia, programmer_param); io_base_addr += 0x300000; - printf("Detected NVIDIA I/O base address: 0x%x.\n", io_base_addr); + print(MSG_NORMAL, "Detected NVIDIA I/O base address: 0x%x.\n", io_base_addr); /* Allow access to flash interface (will disable screen). */ reg32 = pci_read_long(pcidev_dev, 0x50); diff --git a/ichspi.c b/ichspi.c index cd02b96..da45a07 100644 --- a/ichspi.c +++ b/ichspi.c @@ -216,7 +216,7 @@ static int generate_opcodes(OPCODES * op) uint32_t opmenu[2]; if (op == NULL) { - printf_debug("\n%s: null OPCODES pointer!\n", __func__); + print(MSG_DEBUG, "\n%s: null OPCODES pointer!\n", __func__); return -1; } @@ -235,7 +235,7 @@ static int generate_opcodes(OPCODES * op) opmenu[1] = REGREAD32(ICH9_REG_OPMENU + 4); break; default: - printf_debug("%s: unsupported chipset\n", __func__); + print(MSG_DEBUG, "%s: unsupported chipset\n", __func__); return -1; } @@ -301,7 +301,7 @@ int program_opcodes(OPCODES * op) opmenu[1] |= ((uint32_t) op->opcode[a].opcode) << ((a - 4) * 8); } - printf_debug("\n%s: preop=%04x optype=%04x opmenu=%08x%08x\n", __func__, preop, optype, opmenu[0], opmenu[1]); + print(MSG_DEBUG, "\n%s: preop=%04x optype=%04x opmenu=%08x%08x\n", __func__, preop, optype, opmenu[0], opmenu[1]); switch (spi_controller) { case SPI_CONTROLLER_ICH7: case SPI_CONTROLLER_VIA: @@ -317,7 +317,7 @@ int program_opcodes(OPCODES * op) REGWRITE32(ICH9_REG_OPMENU + 4, opmenu[1]); break; default: - printf_debug("%s: unsupported chipset\n", __func__); + print(MSG_DEBUG, "%s: unsupported chipset\n", __func__); return -1; } @@ -338,22 +338,22 @@ int ich_init_opcodes(void) return 0; if (ichspi_lock) { - printf_debug("Generating OPCODES... "); + print(MSG_DEBUG, "Generating OPCODES... "); curopcodes_done = &O_EXISTING; rc = generate_opcodes(curopcodes_done); } else { - printf_debug("Programming OPCODES... "); + print(MSG_DEBUG, "Programming OPCODES... "); curopcodes_done = &O_ST_M25P; rc = program_opcodes(curopcodes_done); } if (rc) { curopcodes = NULL; - printf_debug("failed\n"); + print(MSG_DEBUG, "failed\n"); return 1; } else { curopcodes = curopcodes_done; - printf_debug("done\n"); + print(MSG_DEBUG, "done\n"); return 0; } } @@ -425,7 +425,7 @@ static int ich7_run_opcode(OPCODE op, uint32_t offset, opmenu >>= 8; } if (opcode_index == 8) { - printf_debug("Opcode %x not found.\n", op.opcode); + print(MSG_DEBUG, "Opcode %x not found.\n", op.opcode); return 1; } temp16 |= ((uint16_t) (opcode_index & 0x07)) << 4; @@ -453,11 +453,11 @@ static int ich7_run_opcode(OPCODE op, uint32_t offset, programmer_delay(10); } if (!timeout) { - printf_debug("timeout\n"); + print(MSG_DEBUG, "timeout\n"); } if ((REGREAD16(ICH7_REG_SPIS) & SPIS_FCERR) != 0) { - printf_debug("Transaction error!\n"); + print(MSG_DEBUG, "Transaction error!\n"); return 1; } @@ -542,7 +542,7 @@ static int ich9_run_opcode(OPCODE op, uint32_t offset, opmenu >>= 8; } if (opcode_index == 8) { - printf_debug("Opcode %x not found.\n", op.opcode); + print(MSG_DEBUG, "Opcode %x not found.\n", op.opcode); return 1; } temp32 |= ((uint32_t) (opcode_index & 0x07)) << (8 + 4); @@ -570,11 +570,11 @@ static int ich9_run_opcode(OPCODE op, uint32_t offset, programmer_delay(10); } if (!timeout) { - printf_debug("timeout\n"); + print(MSG_DEBUG, "timeout\n"); } if ((REGREAD32(ICH9_REG_SSFS) & SSFS_FCERR) != 0) { - printf_debug("Transaction error!\n"); + print(MSG_DEBUG, "Transaction error!\n"); return 1; } @@ -610,7 +610,7 @@ static int run_opcode(OPCODE op, uint32_t offset, return SPI_INVALID_LENGTH; return ich9_run_opcode(op, offset, datalength, data); default: - printf_debug("%s: unsupported chipset\n", __func__); + print(MSG_DEBUG, "%s: unsupported chipset\n", __func__); } /* If we ever get here, something really weird happened */ @@ -624,14 +624,14 @@ static int ich_spi_write_page(struct flashchip *flash, uint8_t * bytes, uint32_t remaining = page_size; int towrite; - printf_debug("ich_spi_write_page: offset=%d, number=%d, buf=%p\n", + print(MSG_DEBUG, "ich_spi_write_page: offset=%d, number=%d, buf=%p\n", offset, page_size, bytes); for (; remaining > 0; remaining -= towrite) { towrite = min(remaining, maxdata); if (spi_nbyte_program(offset + (page_size - remaining), &bytes[page_size - remaining], towrite)) { - printf_debug("Error writing"); + print(MSG_DEBUG, "Error writing"); return 1; } } @@ -659,14 +659,14 @@ int ich_spi_write_256(struct flashchip *flash, uint8_t * buf) spi_disable_blockprotect(); /* Erase first */ - printf("Erasing flash before programming... "); + print(MSG_NORMAL, "Erasing flash before programming... "); if (erase_flash(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } - printf("done.\n"); + print(MSG_NORMAL, "done.\n"); - printf("Programming page: \n"); + print(MSG_NORMAL, "Programming page: \n"); for (i = 0; i < total_size / erase_size; i++) { if (spi_controller == SPI_CONTROLLER_VIA) maxdata = 16; @@ -678,7 +678,7 @@ int ich_spi_write_256(struct flashchip *flash, uint8_t * buf) } } - printf("\n"); + print(MSG_NORMAL, "\n"); return rc; } @@ -705,7 +705,7 @@ int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt, /* unknown / not programmed command */ if (opcode_index == -1) { - printf_debug("Invalid OPCODE 0x%02x\n", cmd); + print(MSG_DEBUG, "Invalid OPCODE 0x%02x\n", cmd); return SPI_INVALID_OPCODE; } @@ -732,7 +732,7 @@ int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt, result = run_opcode(*opcode, addr, count, data); if (result) { - printf_debug("run OPCODE 0x%02x failed\n", opcode->opcode); + print(MSG_DEBUG, "run OPCODE 0x%02x failed\n", opcode->opcode); } return result; diff --git a/internal.c b/internal.c index fc662c5..f37227d 100644 --- a/internal.c +++ b/internal.c @@ -109,7 +109,7 @@ void get_io_perms(void) #else if (iopl(3) != 0) { #endif - fprintf(stderr, "ERROR: Could not get I/O privileges (%s).\n" + print(MSG_ERROR, "ERROR: Could not get I/O privileges (%s).\n" "You need to be root.\n", strerror(errno)); exit(1); } @@ -144,7 +144,7 @@ int internal_init(void) */ ret = chipset_flash_enable(); if (ret == -2) { - printf("WARNING: No chipset found. Flash detection " + print(MSG_NORMAL, "WARNING: No chipset found. Flash detection " "will most likely fail.\n"); } diff --git a/it87spi.c b/it87spi.c index a5dc06e..a6676c4 100644 --- a/it87spi.c +++ b/it87spi.c @@ -69,31 +69,31 @@ static uint16_t find_ite_spi_flash_port(uint16_t port) if (0x8716 == id || 0x8718 == id) { /* NOLDN, reg 0x24, mask out lowest bit (suspend) */ tmp = sio_read(port, 0x24) & 0xFE; - printf("Serial flash segment 0x%08x-0x%08x %sabled\n", + print(MSG_NORMAL, "Serial flash segment 0x%08x-0x%08x %sabled\n", 0xFFFE0000, 0xFFFFFFFF, (tmp & 1 << 1) ? "en" : "dis"); - printf("Serial flash segment 0x%08x-0x%08x %sabled\n", + print(MSG_NORMAL, "Serial flash segment 0x%08x-0x%08x %sabled\n", 0x000E0000, 0x000FFFFF, (tmp & 1 << 1) ? "en" : "dis"); - printf("Serial flash segment 0x%08x-0x%08x %sabled\n", + print(MSG_NORMAL, "Serial flash segment 0x%08x-0x%08x %sabled\n", 0xFFEE0000, 0xFFEFFFFF, (tmp & 1 << 2) ? "en" : "dis"); - printf("Serial flash segment 0x%08x-0x%08x %sabled\n", + print(MSG_NORMAL, "Serial flash segment 0x%08x-0x%08x %sabled\n", 0xFFF80000, 0xFFFEFFFF, (tmp & 1 << 3) ? "en" : "dis"); - printf("LPC write to serial flash %sabled\n", + print(MSG_NORMAL, "LPC write to serial flash %sabled\n", (tmp & 1 << 4) ? "en" : "dis"); /* The LPC->SPI force write enable below only makes sense for * non-programmer mode. */ /* If any serial flash segment is enabled, enable writing. */ if ((tmp & 0xe) && (!(tmp & 1 << 4))) { - printf("Enabling LPC write to serial flash\n"); + print(MSG_NORMAL, "Enabling LPC write to serial flash\n"); tmp |= 1 << 4; sio_write(port, 0x24, tmp); } - printf("Serial flash pin %i\n", (tmp & 1 << 5) ? 87 : 29); + print(MSG_NORMAL, "Serial flash pin %i\n", (tmp & 1 << 5) ? 87 : 29); /* LDN 0x7, reg 0x64/0x65 */ sio_write(port, 0x07, 0x7); flashport = sio_read(port, 0x64) << 8; flashport |= sio_read(port, 0x65); - printf("Serial flash port 0x%04x\n", flashport); + print(MSG_NORMAL, "Serial flash port 0x%04x\n", flashport); if (programmer_param && !strlen(programmer_param)) { free(programmer_param); programmer_param = NULL; @@ -101,7 +101,7 @@ static uint16_t find_ite_spi_flash_port(uint16_t port) if (programmer_param && (portpos = strstr(programmer_param, "port="))) { portpos += 5; flashport = strtol(portpos, (char **)NULL, 0); - printf("Forcing serial flash port 0x%04x\n", flashport); + print(MSG_NORMAL, "Forcing serial flash port 0x%04x\n", flashport); sio_write(port, 0x64, (flashport >> 8)); sio_write(port, 0x65, (flashport & 0xff)); } @@ -167,7 +167,7 @@ int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt, busy = INB(it8716f_flashport) & 0x80; } while (busy); if (readcnt > 3) { - printf("%s called with unsupported readcnt %i.\n", + print(MSG_NORMAL, "%s called with unsupported readcnt %i.\n", __func__, readcnt); return SPI_INVALID_LENGTH; } @@ -197,7 +197,7 @@ int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt, writeenc = 0x3; break; default: - printf("%s called with unsupported writecnt %i.\n", + print(MSG_NORMAL, "%s called with unsupported writecnt %i.\n", __func__, writecnt); return SPI_INVALID_LENGTH; } @@ -278,12 +278,12 @@ int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf) } else { spi_disable_blockprotect(); /* Erase first */ - printf("Erasing flash before programming... "); + print(MSG_NORMAL, "Erasing flash before programming... "); if (erase_flash(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } - printf("done.\n"); + print(MSG_NORMAL, "done.\n"); for (i = 0; i < total_size / 256; i++) { it8716f_spi_page_program(flash, i, buf); } diff --git a/jedec.c b/jedec.c index 83a0b83..f2fade6 100644 --- a/jedec.c +++ b/jedec.c @@ -84,12 +84,12 @@ int probe_jedec(struct flashchip *flash) else if (flash->probe_timing == TIMING_ZERO) { /* No delay. */ probe_timing_enter = probe_timing_exit = 0; } else if (flash->probe_timing == TIMING_FIXME) { /* == _IGNORED */ - printf_debug("Chip lacks correct probe timing information, " + print(MSG_DEBUG, "Chip lacks correct probe timing information, " "using default 10mS/40uS. "); probe_timing_enter = 10000; probe_timing_exit = 40; } else { - printf("Chip has negative value in probe_timing, failing " + print(MSG_NORMAL, "Chip has negative value in probe_timing, failing " "without chip access\n"); return 0; } @@ -128,9 +128,9 @@ int probe_jedec(struct flashchip *flash) chip_writeb(0xF0, bios + 0x5555); programmer_delay(probe_timing_exit); - printf_debug("%s: id1 0x%02x, id2 0x%02x", __func__, largeid1, largeid2); + print(MSG_DEBUG, "%s: id1 0x%02x, id2 0x%02x", __func__, largeid1, largeid2); if (!oddparity(id1)) - printf_debug(", id1 parity violation"); + print(MSG_DEBUG, ", id1 parity violation"); /* Read the product ID location again. We should now see normal flash contents. */ flashcontent1 = chip_readb(bios); @@ -147,11 +147,11 @@ int probe_jedec(struct flashchip *flash) } if (largeid1 == flashcontent1) - printf_debug(", id1 is normal flash content"); + print(MSG_DEBUG, ", id1 is normal flash content"); if (largeid2 == flashcontent2) - printf_debug(", id2 is normal flash content"); + print(MSG_DEBUG, ", id2 is normal flash content"); - printf_debug("\n"); + print(MSG_DEBUG, "\n"); if (largeid1 == flash->manufacture_id && largeid2 == flash->model_id) return 1; @@ -181,7 +181,7 @@ int erase_sector_jedec(struct flashchip *flash, unsigned int page, unsigned int toggle_ready_jedec(bios); if (check_erased_range(flash, page, pagesize)) { - fprintf(stderr,"ERASE FAILED!\n"); + fprint(MSG_NORMAL, stderr,"ERASE FAILED!\n"); return -1; } return 0; @@ -210,7 +210,7 @@ int erase_block_jedec(struct flashchip *flash, unsigned int block, unsigned int toggle_ready_jedec(bios); if (check_erased_range(flash, block, blocksize)) { - fprintf(stderr,"ERASE FAILED!\n"); + fprint(MSG_NORMAL, stderr,"ERASE FAILED!\n"); return -1; } return 0; @@ -239,7 +239,7 @@ int erase_chip_jedec(struct flashchip *flash) toggle_ready_jedec(bios); if (check_erased_range(flash, 0, total_size)) { - fprintf(stderr,"ERASE FAILED!\n"); + fprint(MSG_NORMAL, stderr,"ERASE FAILED!\n"); return -1; } return 0; @@ -274,11 +274,11 @@ retry: failed = verify_range(flash, src, start, page_size, NULL); if (failed && tried++ < MAX_REFLASH_TRIES) { - fprintf(stderr, "retrying.\n"); + print(MSG_ERROR, "retrying.\n"); goto retry; } if (failed) { - fprintf(stderr, " page 0x%lx failed!\n", + print(MSG_ERROR, " page 0x%lx failed!\n", (d - bios) / page_size); } return failed; @@ -325,7 +325,7 @@ int write_sector_jedec(chipaddr bios, uint8_t *src, dst++, src++; } if (failed) - fprintf(stderr, " writing sector at 0x%lx failed!\n", olddst); + print(MSG_ERROR, " writing sector at 0x%lx failed!\n", olddst); return failed; } @@ -337,19 +337,19 @@ int write_jedec(struct flashchip *flash, uint8_t *buf) int page_size = flash->page_size; if (erase_chip_jedec(flash)) { - fprintf(stderr,"ERASE FAILED!\n"); + fprint(MSG_NORMAL, stderr,"ERASE FAILED!\n"); return -1; } - printf("Programming page: "); + print(MSG_NORMAL, "Programming page: "); for (i = 0; i < total_size / page_size; i++) { - printf("%04d at address: 0x%08x", i, i * page_size); + print(MSG_NORMAL, "%04d at address: 0x%08x", i, i * page_size); if (write_page_write_jedec(flash, buf + i * page_size, i * page_size, page_size)) failed = 1; - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); } - printf("\n"); + print(MSG_NORMAL, "\n"); return failed; } @@ -362,21 +362,21 @@ int write_jedec_1(struct flashchip *flash, uint8_t * buf) programmer_delay(10); if (erase_flash(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } - printf("Programming page: "); + print(MSG_NORMAL, "Programming page: "); for (i = 0; i < flash->total_size; i++) { if ((i & 0x3) == 0) - printf("address: 0x%08lx", (unsigned long)i * 1024); + print(MSG_NORMAL, "address: 0x%08lx", (unsigned long)i * 1024); write_sector_jedec(bios, buf + i * 1024, dst + i * 1024, 1024); if ((i & 0x3) == 0) - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); } - printf("\n"); + print(MSG_NORMAL, "\n"); return 0; } diff --git a/layout.c b/layout.c index c432ebe..34265ab 100644 --- a/layout.c +++ b/layout.c @@ -70,7 +70,7 @@ int show_id(uint8_t *bios, int size, int force) mb_vendor_offset = *(walk - 2); if ((*walk) == 0 || ((*walk) & 0x3ff) != 0 || (*walk) > size || mb_part_offset > size || mb_vendor_offset > size) { - printf("Flash image seems to be a legacy BIOS. Disabling checks.\n"); + print(MSG_NORMAL, "Flash image seems to be a legacy BIOS. Disabling checks.\n"); return 0; } @@ -78,25 +78,25 @@ int show_id(uint8_t *bios, int size, int force) mb_vendor = (char *)(bios + size - mb_vendor_offset); if (!isprint((unsigned char)*mb_part) || !isprint((unsigned char)*mb_vendor)) { - printf("Flash image seems to have garbage in the ID location." + print(MSG_NORMAL, "Flash image seems to have garbage in the ID location." " Disabling checks.\n"); return 0; } - printf_debug("coreboot last image size " + print(MSG_DEBUG, "coreboot last image size " "(not ROM size) is %d bytes.\n", *walk); mainboard_part = strdup(mb_part); mainboard_vendor = strdup(mb_vendor); - printf_debug("Manufacturer: %s\n", mainboard_vendor); - printf_debug("Mainboard ID: %s\n", mainboard_part); + print(MSG_DEBUG, "Manufacturer: %s\n", mainboard_vendor); + print(MSG_DEBUG, "Mainboard ID: %s\n", mainboard_part); /* * If lb_vendor is not set, the coreboot table was * not found. Nor was -m VENDOR:PART specified. */ if (!lb_vendor || !lb_part) { - printf("Note: If the following flash access fails, " + print(MSG_NORMAL, "Note: If the following flash access fails, " "try -m :.\n"); return 0; } @@ -106,13 +106,13 @@ int show_id(uint8_t *bios, int size, int force) */ if (!strcasecmp(mainboard_vendor, lb_vendor) && !strcasecmp(mainboard_part, lb_part)) { - printf_debug("This firmware image matches this mainboard.\n"); + print(MSG_DEBUG, "This firmware image matches this mainboard.\n"); } else { if (force) { - printf("WARNING: This firmware image does not " + print(MSG_NORMAL, "WARNING: This firmware image does not " "seem to fit to this machine - forcing it.\n"); } else { - printf("ERROR: Your firmware image (%s:%s) does not " + print(MSG_NORMAL, "ERROR: Your firmware image (%s:%s) does not " "appear to\n be correct for the detected " "mainboard (%s:%s)\n\nOverride with --force if you " "are absolutely sure that you\nare using a correct " @@ -136,7 +136,7 @@ int read_romlayout(char *name) romlayout = fopen(name, "r"); if (!romlayout) { - fprintf(stderr, "ERROR: Could not open ROM layout (%s).\n", + print(MSG_ERROR, "ERROR: Could not open ROM layout (%s).\n", name); return -1; } @@ -154,7 +154,7 @@ int read_romlayout(char *name) tstr1 = strtok(tempstr, ":"); tstr2 = strtok(NULL, ":"); if (!tstr1 || !tstr2) { - fprintf(stderr, "Error parsing layout file.\n"); + print(MSG_ERROR, "Error parsing layout file.\n"); fclose(romlayout); return 1; } @@ -165,7 +165,7 @@ int read_romlayout(char *name) } for (i = 0; i < romimages; i++) { - printf_debug("romlayout %08x - %08x named %s\n", + print(MSG_DEBUG, "romlayout %08x - %08x named %s\n", rom_entries[i].start, rom_entries[i].end, rom_entries[i].name); } @@ -182,16 +182,16 @@ int find_romentry(char *name) if (!romimages) return -1; - printf("Looking for \"%s\"... ", name); + print(MSG_NORMAL, "Looking for \"%s\"... ", name); for (i = 0; i < romimages; i++) { if (!strcmp(rom_entries[i].name, name)) { rom_entries[i].included = 1; - printf("found.\n"); + print(MSG_NORMAL, "found.\n"); return i; } } - printf("not found.\n"); // Not found. Error. + print(MSG_NORMAL, "not found.\n"); // Not found. Error. return -1; } diff --git a/m29f002.c b/m29f002.c index 01a7a50..ae88f2b 100644 --- a/m29f002.c +++ b/m29f002.c @@ -32,7 +32,7 @@ int erase_m29f002(struct flashchip *flash) programmer_delay(10); toggle_ready_jedec(bios); if (check_erased_range(flash, 0, flash->total_size * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; @@ -55,7 +55,7 @@ static int rewrite_block(struct flashchip *flash, uint8_t *src, programmer_delay(10); toggle_ready_jedec(bios); if (check_erased_range(flash, start, size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } @@ -77,11 +77,11 @@ static int do_block(struct flashchip *flash, uint8_t *src, int i, unsigned long start, int size) { int ret; - printf("%d at address: 0x%08lx", i, start); + print(MSG_NORMAL, "%d at address: 0x%08lx", i, start); ret = rewrite_block(flash, src + start, start, size); if (ret) return ret; - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); return 0; } @@ -94,7 +94,7 @@ int write_m29f002t(struct flashchip *flash, uint8_t *buf) * flash->page_size is set to 64k in flashchips.c */ - printf("Programming block: "); + print(MSG_NORMAL, "Programming block: "); for (i = 0; i < 3; i++) do_block(flash, buf, i, i * page_size, page_size); do_block(flash, buf, i++, 0x30000, 32 * 1024); @@ -102,7 +102,7 @@ int write_m29f002t(struct flashchip *flash, uint8_t *buf) do_block(flash, buf, i++, 0x3a000, 8 * 1024); do_block(flash, buf, i, 0x3c000, 16 * 1024); - printf("\n"); + print(MSG_NORMAL, "\n"); return 0; } @@ -115,7 +115,7 @@ int write_m29f002b(struct flashchip *flash, uint8_t *buf) * flash->page_size is set to 64k in flashchips.c */ - printf("Programming block: "); + print(MSG_NORMAL, "Programming block: "); do_block(flash, buf, i++, 0x00000, 16 * 1024); do_block(flash, buf, i++, 0x04000, 8 * 1024); do_block(flash, buf, i++, 0x06000, 8 * 1024); @@ -123,6 +123,6 @@ int write_m29f002b(struct flashchip *flash, uint8_t *buf) for (; i < 7; i++) do_block(flash, buf, i, (i - 3) * page_size, page_size); - printf("\n"); + print(MSG_NORMAL, "\n"); return 0; } diff --git a/m29f400bt.c b/m29f400bt.c index c327f44..5ba1014 100644 --- a/m29f400bt.c +++ b/m29f400bt.c @@ -72,7 +72,7 @@ int probe_m29f400bt(struct flashchip *flash) programmer_delay(10); - printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); + print(MSG_DEBUG, "%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); if (id1 == flash->manufacture_id && id2 == flash->model_id) return 1; @@ -96,7 +96,7 @@ int erase_m29f400bt(struct flashchip *flash) toggle_ready_jedec(bios); if (check_erased_range(flash, 0, flash->total_size * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; @@ -120,7 +120,7 @@ int block_erase_m29f400bt(struct flashchip *flash, int start, int len) toggle_ready_jedec(bios); if (check_erased_range(flash, start, len)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; @@ -134,7 +134,7 @@ int write_m29f400bt(struct flashchip *flash, uint8_t *buf) chipaddr bios = flash->virtual_memory; //erase_m29f400bt (flash); - printf("Programming page:\n "); + print(MSG_NORMAL, "Programming page:\n "); /********************************* *Pages for M29F400BT: * 16 0x7c000 0x7ffff TOP @@ -150,47 +150,47 @@ int write_m29f400bt(struct flashchip *flash, uint8_t *buf) * 64 0x10000 0x1ffff * 64 0x00000 0x0ffff BOTTOM *********************************/ - printf("total_size/page_size = %d\n", total_size / page_size); + print(MSG_NORMAL, "total_size/page_size = %d\n", total_size / page_size); for (i = 0; i < (total_size / page_size) - 1; i++) { - printf("%04d at address: 0x%08x\n", i, i * page_size); + print(MSG_NORMAL, "%04d at address: 0x%08x\n", i, i * page_size); if (block_erase_m29f400bt(flash, i * page_size, page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + i * page_size, bios + i * page_size, page_size); - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); } - printf("%04d at address: 0x%08x\n", 7, 0x70000); + print(MSG_NORMAL, "%04d at address: 0x%08x\n", 7, 0x70000); if (block_erase_m29f400bt(flash, 0x70000, 32 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x70000, bios + 0x70000, 32 * 1024); - printf("%04d at address: 0x%08x\n", 8, 0x78000); + print(MSG_NORMAL, "%04d at address: 0x%08x\n", 8, 0x78000); if (block_erase_m29f400bt(flash, 0x78000, 8 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x78000, bios + 0x78000, 8 * 1024); - printf("%04d at address: 0x%08x\n", 9, 0x7a000); + print(MSG_NORMAL, "%04d at address: 0x%08x\n", 9, 0x7a000); if (block_erase_m29f400bt(flash, 0x7a000, 8 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x7a000, bios + 0x7a000, 8 * 1024); - printf("%04d at address: 0x%08x\n", 10, 0x7c000); + print(MSG_NORMAL, "%04d at address: 0x%08x\n", 10, 0x7c000); if (block_erase_m29f400bt(flash, 0x7c000, 16 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x7c000, bios + 0x7c000, 16 * 1024); - printf("\n"); + print(MSG_NORMAL, "\n"); return 0; } @@ -199,7 +199,7 @@ int write_coreboot_m29f400bt(struct flashchip *flash, uint8_t *buf) { chipaddr bios = flash->virtual_memory; - printf("Programming page:\n "); + print(MSG_NORMAL, "Programming page:\n "); /********************************* *Pages for M29F400BT: * 16 0x7c000 0x7ffff TOP @@ -215,35 +215,35 @@ int write_coreboot_m29f400bt(struct flashchip *flash, uint8_t *buf) * 64 0x10000 0x1ffff * 64 0x00000 0x0ffff BOTTOM *********************************/ - printf("%04d at address: 0x%08x\n", 7, 0x00000); + print(MSG_NORMAL, "%04d at address: 0x%08x\n", 7, 0x00000); if (block_erase_m29f400bt(flash, 0x00000, 64 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x00000, bios + 0x00000, 64 * 1024); - printf("%04d at address: 0x%08x\n", 7, 0x10000); + print(MSG_NORMAL, "%04d at address: 0x%08x\n", 7, 0x10000); if (block_erase_m29f400bt(flash, 0x10000, 64 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x10000, bios + 0x10000, 64 * 1024); - printf("%04d at address: 0x%08x\n", 7, 0x20000); + print(MSG_NORMAL, "%04d at address: 0x%08x\n", 7, 0x20000); if (block_erase_m29f400bt(flash, 0x20000, 64 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x20000, bios + 0x20000, 64 * 1024); - printf("%04d at address: 0x%08x\n", 7, 0x30000); + print(MSG_NORMAL, "%04d at address: 0x%08x\n", 7, 0x30000); if (block_erase_m29f400bt(flash, 0x30000, 64 * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } write_page_m29f400bt(bios, buf + 0x30000, bios + 0x30000, 64 * 1024); - printf("\n"); + print(MSG_NORMAL, "\n"); return 0; } diff --git a/mx29f002.c b/mx29f002.c index 7838c3d..af1428d 100644 --- a/mx29f002.c +++ b/mx29f002.c @@ -36,7 +36,7 @@ int probe_29f002(struct flashchip *flash) programmer_delay(10); - printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); + print(MSG_DEBUG, "%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); if (id1 == flash->manufacture_id && id2 == flash->model_id) return 1; @@ -62,7 +62,7 @@ int erase_29f002(struct flashchip *flash) toggle_ready_jedec(bios); if (check_erased_range(flash, 0, flash->total_size * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; diff --git a/pcidev.c b/pcidev.c index 6c92c0a..419f2fc 100644 --- a/pcidev.c +++ b/pcidev.c @@ -44,13 +44,13 @@ uint32_t pcidev_validate(struct pci_dev *dev, uint32_t bar, */ addr = pci_read_long(dev, bar) & ~0x03; - printf("Found \"%s %s\" (%04x:%04x, BDF %02x:%02x.%x).\n", + print(MSG_NORMAL, "Found \"%s %s\" (%04x:%04x, BDF %02x:%02x.%x).\n", devs[i].vendor_name, devs[i].device_name, dev->vendor_id, dev->device_id, dev->bus, dev->dev, dev->func); if (devs[i].status == PCI_NT) { - printf("===\nThis PCI device is UNTESTED. Please " + print(MSG_NORMAL, "===\nThis PCI device is UNTESTED. Please " "report the 'flashrom -p xxxx' output \n" "to flashrom@flashrom.org if it works " "for you. Thank you for your help!\n===\n"); @@ -79,7 +79,7 @@ uint32_t pcidev_init(uint16_t vendor_id, uint32_t bar, filter.vendor = vendor_id; if (pcidev_bdf != NULL) { if ((msg = pci_filter_parse_slot(&filter, pcidev_bdf))) { - fprintf(stderr, "Error: %s\n", msg); + print(MSG_ERROR, "Error: %s\n", msg); exit(1); } } @@ -96,10 +96,10 @@ uint32_t pcidev_init(uint16_t vendor_id, uint32_t bar, /* Only continue if exactly one supported PCI dev has been found. */ if (found == 0) { - fprintf(stderr, "Error: No supported PCI device found.\n"); + print(MSG_ERROR, "Error: No supported PCI device found.\n"); exit(1); } else if (found > 1) { - fprintf(stderr, "Error: Multiple supported PCI devices found. " + print(MSG_ERROR, "Error: Multiple supported PCI devices found. " "Use 'flashrom -p xxxx:bb:dd.f' \n" "to explicitly select the card with the given BDF " "(PCI bus, device, function).\n"); @@ -114,7 +114,7 @@ void print_supported_pcidevs(struct pcidev_status *devs) int i; for (i = 0; devs[i].vendor_name != NULL; i++) { - printf("%s %s [%02x:%02x]%s\n", devs[i].vendor_name, + print(MSG_NORMAL, "%s %s [%02x:%02x]%s\n", devs[i].vendor_name, devs[i].device_name, devs[i].vendor_id, devs[i].device_id, (devs[i].status == PCI_NT) ? " (untested)" : ""); diff --git a/physmap.c b/physmap.c index 3a003fe..8801d2c 100644 --- a/physmap.c +++ b/physmap.c @@ -72,7 +72,7 @@ void *sys_physmap(unsigned long phys_addr, size_t len) void physunmap(void *virt_addr, size_t len) { if (len == 0) { - printf_debug("Not unmapping zero size at %p\n", virt_addr); + print(MSG_DEBUG, "Not unmapping zero size at %p\n", virt_addr); return; } @@ -85,18 +85,18 @@ void *physmap(const char *descr, unsigned long phys_addr, size_t len) void *virt_addr; if (len == 0) { - printf_debug("Not mapping %s, zero size at 0x%08lx.\n", + print(MSG_DEBUG, "Not mapping %s, zero size at 0x%08lx.\n", descr, phys_addr); return NULL; } if ((getpagesize() - 1) & len) { - fprintf(stderr, "Mapping %s at 0x%08lx, unaligned size 0x%lx.\n", + print(MSG_ERROR, "Mapping %s at 0x%08lx, unaligned size 0x%lx.\n", descr, phys_addr, (unsigned long)len); } if ((getpagesize() - 1) & phys_addr) { - fprintf(stderr, "Mapping %s, 0x%lx bytes at unaligned 0x%08lx.\n", + print(MSG_ERROR, "Mapping %s, 0x%lx bytes at unaligned 0x%08lx.\n", descr, (unsigned long)len, phys_addr); } @@ -105,14 +105,14 @@ void *physmap(const char *descr, unsigned long phys_addr, size_t len) if (NULL == virt_addr) { if (NULL == descr) descr = "memory"; - fprintf(stderr, "Error accessing %s, 0x%lx bytes at 0x%08lx\n", descr, (unsigned long)len, phys_addr); + print(MSG_ERROR, "Error accessing %s, 0x%lx bytes at 0x%08lx\n", descr, (unsigned long)len, phys_addr); perror(MEM_DEV " mmap failed"); if (EINVAL == errno) { - fprintf(stderr, "In Linux this error can be caused by the CONFIG_NONPROMISC_DEVMEM (<2.6.27),\n"); - fprintf(stderr, "CONFIG_STRICT_DEVMEM (>=2.6.27) and CONFIG_X86_PAT kernel options.\n"); - fprintf(stderr, "Please check if either is enabled in your kernel before reporting a failure.\n"); - fprintf(stderr, "You can override CONFIG_X86_PAT at boot with the nopat kernel parameter but\n"); - fprintf(stderr, "disabling the other option unfortunately requires a kernel recompile. Sorry!\n"); + print(MSG_ERROR, "In Linux this error can be caused by the CONFIG_NONPROMISC_DEVMEM (<2.6.27),\n"); + print(MSG_ERROR, "CONFIG_STRICT_DEVMEM (>=2.6.27) and CONFIG_X86_PAT kernel options.\n"); + print(MSG_ERROR, "Please check if either is enabled in your kernel before reporting a failure.\n"); + print(MSG_ERROR, "You can override CONFIG_X86_PAT at boot with the nopat kernel parameter but\n"); + print(MSG_ERROR, "disabling the other option unfortunately requires a kernel recompile. Sorry!\n"); } exit(3); } @@ -187,7 +187,7 @@ int setup_cpu_msr(int cpu) sprintf(msrfilename, "/dev/cpu/%d/msr", cpu); if (fd_msr != -1) { - printf("MSR was already initialized\n"); + print(MSG_NORMAL, "MSR was already initialized\n"); return -1; } @@ -195,7 +195,7 @@ int setup_cpu_msr(int cpu) if (fd_msr < 0) { perror("Error while opening /dev/cpu/0/msr"); - printf("Did you run 'modprobe msr'?\n"); + print(MSG_NORMAL, "Did you run 'modprobe msr'?\n"); return -1; } @@ -205,7 +205,7 @@ int setup_cpu_msr(int cpu) void cleanup_cpu_msr(void) { if (fd_msr == -1) { - printf("No MSR initialized.\n"); + print(MSG_NORMAL, "No MSR initialized.\n"); return; } @@ -270,7 +270,7 @@ int setup_cpu_msr(int cpu) sprintf(msrfilename, "/dev/cpu%d", cpu); if (fd_msr != -1) { - printf("MSR was already initialized\n"); + print(MSG_NORMAL, "MSR was already initialized\n"); return -1; } @@ -278,7 +278,7 @@ int setup_cpu_msr(int cpu) if (fd_msr < 0) { perror("Error while opening /dev/cpu0"); - printf("Did you install ports/sysutils/devcpu?\n"); + print(MSG_NORMAL, "Did you install ports/sysutils/devcpu?\n"); return -1; } @@ -288,7 +288,7 @@ int setup_cpu_msr(int cpu) void cleanup_cpu_msr(void) { if (fd_msr == -1) { - printf("No MSR initialized.\n"); + print(MSG_NORMAL, "No MSR initialized.\n"); return; } @@ -326,7 +326,7 @@ int wrmsr(int addr, msr_t msr) int setup_cpu_msr(int cpu) { - printf("No MSR support for your OS yet.\n"); + print(MSG_NORMAL, "No MSR support for your OS yet.\n"); return -1; } diff --git a/pm29f002.c b/pm29f002.c index bf78d13..3652be7 100644 --- a/pm29f002.c +++ b/pm29f002.c @@ -29,15 +29,15 @@ int write_pm29f002(struct flashchip *flash, uint8_t *buf) chipaddr dst = bios; if (erase_flash(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } /* FIXME: use write_sector_jedec? */ - printf("Programming page: "); + print(MSG_NORMAL, "Programming page: "); for (i = 0; i < total_size; i++) { if ((i & 0xfff) == 0) - printf("address: 0x%08lx", (unsigned long)i); + print(MSG_NORMAL, "address: 0x%08lx", (unsigned long)i); /* Pm29F002T/B only support byte-wise programming. */ chip_writeb(0xAA, bios + 0x555); @@ -49,10 +49,10 @@ int write_pm29f002(struct flashchip *flash, uint8_t *buf) toggle_ready_jedec(dst); if ((i & 0xfff) == 0) - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); } - printf("\n"); + print(MSG_NORMAL, "\n"); return 0; } diff --git a/pm49fl00x.c b/pm49fl00x.c index 27a1163..9878e08 100644 --- a/pm49fl00x.c +++ b/pm49fl00x.c @@ -60,18 +60,18 @@ int erase_49fl00x(struct flashchip *flash) * erase_chip_jedec() will not work... Datasheet says * "Chip erase is available in A/A Mux Mode only". */ - printf("Erasing page: "); + print(MSG_NORMAL, "Erasing page: "); for (i = 0; i < total_size / page_size; i++) { /* erase the page */ if (erase_block_jedec(flash, i * page_size, page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } - printf("%04d at address: 0x%08x", i, i * page_size); - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "%04d at address: 0x%08x", i, i * page_size); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } - printf("\n"); + print(MSG_NORMAL, "\n"); /* protected */ write_lockbits_49fl00x(flash->virtual_registers, @@ -91,22 +91,22 @@ int write_49fl00x(struct flashchip *flash, uint8_t *buf) write_lockbits_49fl00x(flash->virtual_registers, total_size, 0, page_size); - printf("Programming page: "); + print(MSG_NORMAL, "Programming page: "); for (i = 0; i < total_size / page_size; i++) { /* erase the page before programming */ if (erase_block_jedec(flash, i * page_size, page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } /* write to the sector */ - printf("%04d at address: 0x%08x", i, i * page_size); + print(MSG_NORMAL, "%04d at address: 0x%08x", i, i * page_size); write_sector_jedec(bios, buf + i * page_size, bios + i * page_size, page_size); - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } - printf("\n"); + print(MSG_NORMAL, "\n"); /* protected */ write_lockbits_49fl00x(flash->virtual_registers, total_size, 1, diff --git a/print.c b/print.c index a2a6c63..ab57a57 100644 --- a/print.c +++ b/print.c @@ -57,7 +57,7 @@ char *flashbuses_to_text(enum chipbustype bustype) return ret; } -#define POS_PRINT(x) do { pos += strlen(x); printf(x); } while (0) +#define POS_PRINT(x) do { pos += strlen(x); print(MSG_NORMAL, x); } while (0) static int digits(int n) { @@ -87,29 +87,29 @@ void print_supported_chips(void) for (f = flashchips; f->name != NULL; f++) chipcount++; - printf("\nSupported flash chips (total: %d):\n\n", chipcount); + print(MSG_NORMAL, "\nSupported flash chips (total: %d):\n\n", chipcount); POS_PRINT("Vendor: Device:"); while (pos < okcol) { - printf("\t"); + print(MSG_NORMAL, "\t"); pos += 8 - (pos % 8); } - printf("Tested OK:\tKnown BAD: Size/KB: Type:\n\n"); - printf("(P = PROBE, R = READ, E = ERASE, W = WRITE)\n\n"); + print(MSG_NORMAL, "Tested OK:\tKnown BAD: Size/KB: Type:\n\n"); + print(MSG_NORMAL, "(P = PROBE, R = READ, E = ERASE, W = WRITE)\n\n"); for (f = flashchips; f->name != NULL; f++) { /* Don't print "unknown XXXX SPI chip" entries. */ if (!strncmp(f->name, "unknown", 7)) continue; - printf("%s", f->vendor); + print(MSG_NORMAL, "%s", f->vendor); for (i = 0; i < 10 - strlen(f->vendor); i++) - printf(" "); - printf("%s", f->name); + print(MSG_NORMAL, " "); + print(MSG_NORMAL, "%s", f->name); pos = 10 + strlen(f->name); while (pos < okcol) { - printf("\t"); + print(MSG_NORMAL, "\t"); pos += 8 - (pos % 8); } if ((f->tested & TEST_OK_MASK)) { @@ -123,24 +123,24 @@ void print_supported_chips(void) POS_PRINT("W "); } while (pos < okcol + 9) { - printf("\t"); + print(MSG_NORMAL, "\t"); pos += 8 - (pos % 8); } if ((f->tested & TEST_BAD_MASK)) { if ((f->tested & TEST_BAD_PROBE)) - printf("P "); + print(MSG_NORMAL, "P "); if ((f->tested & TEST_BAD_READ)) - printf("R "); + print(MSG_NORMAL, "R "); if ((f->tested & TEST_BAD_ERASE)) - printf("E "); + print(MSG_NORMAL, "E "); if ((f->tested & TEST_BAD_WRITE)) - printf("W "); + print(MSG_NORMAL, "W "); } - printf("\t %d", f->total_size); + print(MSG_NORMAL, "\t %d", f->total_size); for (i = 0; i < 10 - digits(f->total_size); i++) - printf(" "); - printf("%s\n", flashbuses_to_text(f->bustype)); + print(MSG_NORMAL, " "); + print(MSG_NORMAL, "%s\n", flashbuses_to_text(f->bustype)); } } @@ -152,17 +152,17 @@ void print_supported_chipsets(void) for (i = 0; c[i].vendor_name != NULL; i++) chipsetcount++; - printf("\nSupported chipsets (total: %d):\n\nVendor: " + print(MSG_NORMAL, "\nSupported chipsets (total: %d):\n\nVendor: " "Chipset: PCI IDs:\n\n", chipsetcount); for (i = 0; c[i].vendor_name != NULL; i++) { - printf("%s", c[i].vendor_name); + print(MSG_NORMAL, "%s", c[i].vendor_name); for (j = 0; j < 25 - strlen(c[i].vendor_name); j++) - printf(" "); - printf("%s", c[i].device_name); + print(MSG_NORMAL, " "); + print(MSG_NORMAL, "%s", c[i].device_name); for (j = 0; j < 25 - strlen(c[i].device_name); j++) - printf(" "); - printf("%04x:%04x%s\n", c[i].vendor_id, c[i].device_id, + print(MSG_NORMAL, " "); + print(MSG_NORMAL, "%04x:%04x%s\n", c[i].vendor_id, c[i].device_id, (c[i].status == OK) ? "" : " (untested)"); } } @@ -174,16 +174,16 @@ void print_supported_boards_helper(const struct board_info *b, const char *msg) for (i = 0; b[i].vendor != NULL; i++) boardcount++; - printf("\n%s (total: %d):\n\n", msg, boardcount); + print(MSG_NORMAL, "\n%s (total: %d):\n\n", msg, boardcount); for (i = 0; b[i].vendor != NULL; i++) { - printf("%s", b[i].vendor); + print(MSG_NORMAL, "%s", b[i].vendor); for (j = 0; j < 25 - strlen(b[i].vendor); j++) - printf(" "); - printf("%s", b[i].name); + print(MSG_NORMAL, " "); + print(MSG_NORMAL, "%s", b[i].name); for (j = 0; j < 28 - strlen(b[i].name); j++) - printf(" "); - printf("\n"); + print(MSG_NORMAL, " "); + print(MSG_NORMAL, "\n"); } } @@ -195,21 +195,21 @@ void print_supported_boards(void) for (i = 0; b[i].vendor_name != NULL; i++) boardcount++; - printf("\nSupported boards which need write-enable code (total: %d):" + print(MSG_NORMAL, "\nSupported boards which need write-enable code (total: %d):" "\n\nVendor: Board: " "Required option:\n\n", boardcount); for (i = 0; b[i].vendor_name != NULL; i++) { - printf("%s", b[i].vendor_name); + print(MSG_NORMAL, "%s", b[i].vendor_name); for (j = 0; j < 25 - strlen(b[i].vendor_name); j++) - printf(" "); - printf("%s", b[i].board_name); + print(MSG_NORMAL, " "); + print(MSG_NORMAL, "%s", b[i].board_name); for (j = 0; j < 30 - strlen(b[i].board_name); j++) - printf(" "); + print(MSG_NORMAL, " "); if (b[i].lb_vendor != NULL) - printf("-m %s:%s\n", b[i].lb_vendor, b[i].lb_part); + print(MSG_NORMAL, "-m %s:%s\n", b[i].lb_vendor, b[i].lb_part); else - printf("(none, board is autodetected)\n"); + print(MSG_NORMAL, "(none, board is autodetected)\n"); } print_supported_boards_helper(boards_ok, @@ -227,7 +227,7 @@ void print_supported(void) print_supported_chips(); print_supported_chipsets(); print_supported_boards(); - printf("\nSupported PCI devices flashrom can use " + print(MSG_NORMAL, "\nSupported PCI devices flashrom can use " "as programmer:\n\n"); #if NIC3COM_SUPPORT == 1 print_supported_pcidevs(nics_3com); diff --git a/print_wiki.c b/print_wiki.c index ce41ad4..64ee27c 100644 --- a/print_wiki.c +++ b/print_wiki.c @@ -346,7 +346,7 @@ void print_supported_chipsets_wiki(void) for (e = chipset_enables; e->vendor_name != NULL; e++) enablescount++; - printf("\n== Supported chipsets ==\n\nTotal amount of supported " + print(MSG_NORMAL, "\n== Supported chipsets ==\n\nTotal amount of supported " "chipsets: '''%d'''\n\n{| border=\"0\" valign=\"top\"\n| " "valign=\"top\"|\n\n%s", enablescount, chipset_th); @@ -356,7 +356,7 @@ void print_supported_chipsets_wiki(void) if (i > 0 && strcmp(e[i].vendor_name, e[i - 1].vendor_name)) color = !color; - printf("|- bgcolor=\"#%s\" valign=\"top\"\n| %s || %s " + print(MSG_NORMAL, "|- bgcolor=\"#%s\" valign=\"top\"\n| %s || %s " "|| %04x:%04x || %s\n", (color) ? "eeeeee" : "dddddd", e[i].vendor_name, e[i].device_name, e[i].vendor_id, e[i].device_id, @@ -364,12 +364,12 @@ void print_supported_chipsets_wiki(void) /* Split table in three columns. */ if (j >= (enablescount / 3 + 1)) { - printf("\n|}\n\n| valign=\"top\"|\n\n%s", chipset_th); + print(MSG_NORMAL, "\n|}\n\n| valign=\"top\"|\n\n%s", chipset_th); j = 0; } } - printf("\n|}\n\n|}\n"); + print(MSG_NORMAL, "\n|}\n\n|}\n"); } static void wiki_helper(const char *heading, const char *status, @@ -384,7 +384,7 @@ static void wiki_helper(const char *heading, const char *status, for (b = boards; b->vendor != NULL; b++) boardcount++; - printf("\n'''%s'''\n\nTotal amount of boards: '''%d'''\n\n" + print(MSG_NORMAL, "\n'''%s'''\n\nTotal amount of boards: '''%d'''\n\n" "{| border=\"0\" valign=\"top\"\n| valign=\"top\"|\n\n%s", heading, boardcount, board_th); @@ -396,32 +396,32 @@ static void wiki_helper(const char *heading, const char *status, k = url(b[i].vendor, b[i].name); c = note(b[i].vendor, b[i].name); - printf("|- bgcolor=\"#%s\" valign=\"top\"\n| %s || %s%s %s%s ||" + print(MSG_NORMAL, "|- bgcolor=\"#%s\" valign=\"top\"\n| %s || %s%s %s%s ||" " {{%s}}", (color) ? "eeeeee" : "dddddd", b[i].vendor, (k != -1 && u[k].url) ? "[" : "", (k != -1 && u[k].url) ? u[k].url : "", b[i].name, (k != -1 && u[k].url) ? "]" : "", status); if (c != -1) { - printf("%d\n", num_notes + 1); - snprintf((char *)&tmp, 900, "%d %s
\n", + print(MSG_NORMAL, "%d\n", num_notes + 1); + snprint(MSG_NORMAL, (char *)&tmp, 900, "%d %s
\n", 1 + num_notes++, boards_notes[c].note); notes = strcat_realloc(notes, (char *)&tmp); } else { - printf("\n"); + print(MSG_NORMAL, "\n"); } /* Split table in 'cols' columns. */ if (j >= (boardcount / cols + 1)) { - printf("\n|}\n\n| valign=\"top\"|\n\n%s", board_th); + print(MSG_NORMAL, "\n|}\n\n| valign=\"top\"|\n\n%s", board_th); j = 0; } } - printf("\n|}\n\n|}\n"); + print(MSG_NORMAL, "\n|}\n\n|}\n"); if (num_notes > 0) - printf("\n\n%s\n", notes); + print(MSG_NORMAL, "\n\n%s\n", notes); free(notes); } @@ -434,7 +434,7 @@ static void wiki_helper2(const char *heading, int cols) for (b = board_pciid_enables; b->vendor_name != NULL; b++) boardcount++; - printf("\n'''%s'''\n\nTotal amount of boards: '''%d'''\n\n" + print(MSG_NORMAL, "\n'''%s'''\n\nTotal amount of boards: '''%d'''\n\n" "{| border=\"0\" valign=\"top\"\n| valign=\"top\"|\n\n%s", heading, boardcount, board_th2); @@ -446,7 +446,7 @@ static void wiki_helper2(const char *heading, int cols) k = url(b[i].vendor_name, b[i].board_name); - printf("|- bgcolor=\"#%s\" valign=\"top\"\n| %s || %s%s %s%s " + print(MSG_NORMAL, "|- bgcolor=\"#%s\" valign=\"top\"\n| %s || %s%s %s%s " "|| %s%s%s%s || {{OK}}\n", (color) ? "eeeeee" : "dddddd", b[i].vendor_name, (k != -1 && u[k].url) ? "[" : "", (k != -1 && u[k].url) ? u[k].url : "", b[i].board_name, @@ -458,22 +458,22 @@ static void wiki_helper2(const char *heading, int cols) /* Split table in three columns. */ if (j >= (boardcount / cols + 1)) { - printf("\n|}\n\n| valign=\"top\"|\n\n%s", board_th2); + print(MSG_NORMAL, "\n|}\n\n| valign=\"top\"|\n\n%s", board_th2); j = 0; } } - printf("\n|}\n\n|}\n"); + print(MSG_NORMAL, "\n|}\n\n|}\n"); } void print_supported_boards_wiki(void) { - printf("%s", board_intro); + print(MSG_NORMAL, "%s", board_intro); wiki_helper("Known good (worked out of the box)", "OK", 3, boards_ok); wiki_helper2("Known good (with write-enable code in flashrom)", 3); wiki_helper("Not supported (yet)", "No", 3, boards_bad); - printf("%s", laptop_intro); + print(MSG_NORMAL, "%s", laptop_intro); wiki_helper("Known good (worked out of the box)", "OK", 1, laptops_ok); wiki_helper("Not supported (yet)", "No", 1, laptops_bad); } @@ -487,7 +487,7 @@ void print_supported_chips_wiki(void) for (f = flashchips; f->name != NULL; f++) chipcount++; - printf("\n== Supported chips ==\n\nTotal amount of supported " + print(MSG_NORMAL, "\n== Supported chips ==\n\nTotal amount of supported " "chips: '''%d'''\n\n{| border=\"0\" valign=\"top\"\n" "| valign=\"top\"|\n\n%s", chipcount, chip_th); @@ -501,7 +501,7 @@ void print_supported_chips_wiki(void) c = !c; t = f->tested; - printf("|- bgcolor=\"#%s\" valign=\"top\"\n| %s || %s || %d " + print(MSG_NORMAL, "|- bgcolor=\"#%s\" valign=\"top\"\n| %s || %s || %d " "|| %s || {{%s}} || {{%s}} || {{%s}} || {{%s}}\n", (c == 1) ? "eeeeee" : "dddddd", f->vendor, f->name, f->total_size, flashbuses_to_text(f->bustype), @@ -516,14 +516,14 @@ void print_supported_chips_wiki(void) /* Split table into three columns. */ if (i >= (chipcount / 3 + 1)) { - printf("\n|}\n\n| valign=\"top\"|\n\n%s", chip_th); + print(MSG_NORMAL, "\n|}\n\n| valign=\"top\"|\n\n%s", chip_th); i = 0; } old = f; } - printf("\n|}\n\n|}\n"); + print(MSG_NORMAL, "\n|}\n\n|}\n"); } void print_supported_pcidevs_wiki(struct pcidev_status *devs) @@ -535,7 +535,7 @@ void print_supported_pcidevs_wiki(struct pcidev_status *devs) c = !c; for (i = 0; devs[i].vendor_name != NULL; i++) { - printf("|- bgcolor=\"#%s\" valign=\"top\"\n| %s || %s || " + print(MSG_NORMAL, "|- bgcolor=\"#%s\" valign=\"top\"\n| %s || %s || " "%04x:%04x || {{%s}}\n", (c) ? "eeeeee" : "dddddd", devs[i].vendor_name, devs[i].device_name, devs[i].vendor_id, devs[i].device_id, @@ -547,11 +547,11 @@ void print_supported_wiki(void) { time_t t = time(NULL); - printf(wiki_header, ctime(&t), flashrom_version); + print(MSG_NORMAL, wiki_header, ctime(&t), flashrom_version); print_supported_chips_wiki(); print_supported_chipsets_wiki(); print_supported_boards_wiki(); - printf("%s", programmer_section); + print(MSG_NORMAL, "%s", programmer_section); #if NIC3COM_SUPPORT == 1 print_supported_pcidevs_wiki(nics_3com); #endif @@ -564,6 +564,6 @@ void print_supported_wiki(void) #if SATASII_SUPPORT == 1 print_supported_pcidevs_wiki(satas_sii); #endif - printf("\n|}\n"); + print(MSG_NORMAL, "\n|}\n"); } diff --git a/satasii.c b/satasii.c index 79d4325..074a89b 100644 --- a/satasii.c +++ b/satasii.c @@ -63,7 +63,7 @@ int satasii_init(void) /* Check if ROM cycle are OK. */ if ((id != 0x0680) && (!(mmio_readl(sii_bar) & (1 << 26)))) - printf("Warning: Flash seems unconnected.\n"); + print(MSG_NORMAL, "Warning: Flash seems unconnected.\n"); buses_supported = CHIP_BUSTYPE_PARALLEL; diff --git a/sb600spi.c b/sb600spi.c index 87f1cc1..0515a56 100644 --- a/sb600spi.c +++ b/sb600spi.c @@ -54,28 +54,28 @@ int sb600_spi_write_1(struct flashchip *flash, uint8_t *buf) spi_disable_blockprotect(); /* Erase first */ - printf("Erasing flash before programming... "); + print(MSG_NORMAL, "Erasing flash before programming... "); if (erase_flash(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } - printf("done.\n"); + print(MSG_NORMAL, "done.\n"); - printf("Programming flash"); + print(MSG_NORMAL, "Programming flash"); for (i = 0; i < total_size; i++, buf++) { result = spi_nbyte_program(i, buf, 1); if (result) { - fprintf(stderr, "Write error!\n"); + print(MSG_ERROR, "Write error!\n"); return result; } /* wait program complete. */ if (i % 0x8000 == 0) - printf("."); + print(MSG_NORMAL, "."); while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) ; } - printf(" done.\n"); + print(MSG_NORMAL, " done.\n"); return result; } @@ -84,7 +84,7 @@ static void reset_internal_fifo_pointer(void) mmio_writeb(mmio_readb(sb600_spibar + 2) | 0x10, sb600_spibar + 2); while (mmio_readb(sb600_spibar + 0xD) & 0x7) - printf("reset\n"); + print(MSG_NORMAL, "reset\n"); } static void execute_command(void) @@ -105,17 +105,17 @@ int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt, writecnt--; - printf_debug("%s, cmd=%x, writecnt=%x, readcnt=%x\n", + print(MSG_DEBUG, "%s, cmd=%x, writecnt=%x, readcnt=%x\n", __func__, cmd, writecnt, readcnt); if (readcnt > 8) { - printf("%s, SB600 SPI controller can not receive %d bytes, " + print(MSG_NORMAL, "%s, SB600 SPI controller can not receive %d bytes, " "it is limited to 8 bytes\n", __func__, readcnt); return SPI_INVALID_LENGTH; } if (writecnt > 8) { - printf("%s, SB600 SPI controller can not send %d bytes, " + print(MSG_NORMAL, "%s, SB600 SPI controller can not send %d bytes, " "it is limited to 8 bytes\n", __func__, writecnt); return SPI_INVALID_LENGTH; } @@ -135,10 +135,10 @@ int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt, /* Send the write byte to FIFO. */ for (count = 0; count < writecnt; count++, writearr++) { - printf_debug(" [%x]", *writearr); + print(MSG_DEBUG, " [%x]", *writearr); mmio_writeb(*writearr, sb600_spibar + 0xC); } - printf_debug("\n"); + print(MSG_DEBUG, "\n"); /* * We should send the data by sequence, which means we need to reset @@ -164,16 +164,16 @@ int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt, /* Skip the bytes we sent. */ for (count = 0; count < writecnt; count++) { cmd = mmio_readb(sb600_spibar + 0xC); - printf_debug("[ %2x]", cmd); + print(MSG_DEBUG, "[ %2x]", cmd); } - printf_debug("The FIFO pointer after skipping is %d.\n", + print(MSG_DEBUG, "The FIFO pointer after skipping is %d.\n", mmio_readb(sb600_spibar + 0xd) & 0x07); for (count = 0; count < readcnt; count++, readarr++) { *readarr = mmio_readb(sb600_spibar + 0xC); - printf_debug("[%02x]", *readarr); + print(MSG_DEBUG, "[%02x]", *readarr); } - printf_debug("\n"); + print(MSG_DEBUG, "\n"); return 0; } diff --git a/serial.c b/serial.c index e22a8fa..accf8c5 100644 --- a/serial.c +++ b/serial.c @@ -106,7 +106,7 @@ int sp_openserport(char *dev, unsigned int baud) for (i = 0;; i++) { if (sp_baudtable[i].baud == 0) { close(fd); - fprintf(stderr, + fprint(MSG_NORMAL, stderr, "Error: cannot configure for baudrate %d\n", baud); exit(1); diff --git a/serprog.c b/serprog.c index 6544245..e27288b 100644 --- a/serprog.c +++ b/serprog.c @@ -99,7 +99,7 @@ static int sp_opensocket(char *ip, unsigned int port) struct hostent *hostPtr = NULL; union { struct sockaddr_in si; struct sockaddr s; } sp = {}; int sock; - printf_debug(MSGHEADER "IP %s port %d\n", ip, port); + print(MSG_DEBUG, MSGHEADER "IP %s port %d\n", ip, port); sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock < 0) sp_die("Error: serprog cannot open socket"); @@ -170,7 +170,7 @@ static void sp_synchronize(void) unsigned char c = S_CMD_SYNCNOP; if (write(sp_fd, &c, 1) != 1) sp_die("sync write"); - printf_debug("."); + print(MSG_DEBUG, "."); fflush(stdout); for (n = 0; n < 10; n++) { c = sp_sync_read_timeout(5); /* wait upto 50ms */ @@ -191,11 +191,11 @@ static void sp_synchronize(void) /* Ok, synchronized; back to blocking reads and return. */ flags &= ~O_NONBLOCK; fcntl(sp_fd, F_SETFL, flags); - printf_debug("\n"); + print(MSG_DEBUG, "\n"); return; } } - fprintf(stderr, + fprint(MSG_NORMAL, stderr, "Error: cannot synchronize protocol\n" "- check communications and reset device?\n"); exit(1); @@ -239,7 +239,7 @@ static int sp_docommand(uint8_t command, uint32_t parmlen, sp_die("Error: cannot read from device"); if (c == S_NAK) return 1; if (c != S_ACK) { - fprintf(stderr, + fprint(MSG_NORMAL, stderr, "Error: invalid response 0x%02X from device\n",c); exit(1); } @@ -267,12 +267,12 @@ static void sp_flush_stream(void) ("Error: cannot read from device (flushing stream)"); } if (c == S_NAK) { - fprintf(stderr, + fprint(MSG_NORMAL, stderr, "Error: NAK to a stream buffer operation\n"); exit(1); } if (c != S_ACK) { - fprintf(stderr, + fprint(MSG_NORMAL, stderr, "Error: Invalid reply 0x%02X from device\n", c); exit(1); @@ -310,11 +310,11 @@ int serprog_init(void) unsigned char c; char *num; char *dev; - printf_debug("%s\n", __func__); + print(MSG_DEBUG, "%s\n", __func__); /* the parameter is either of format "/dev/device:baud" or "ip:port" */ if ((!programmer_param) || (!strlen(programmer_param))) { nodevice: - fprintf(stderr, + fprint(MSG_NORMAL, stderr, "Error: No device/host given for the serial programmer driver.\n" "Use flashrom -p serprog=/dev/device:baud or flashrom -p serprog=ip:port\n"); exit(1); @@ -323,7 +323,7 @@ int serprog_init(void) len = num - programmer_param; if (!len) goto nodevice; if (!num) { - fprintf(stderr, + fprint(MSG_NORMAL, stderr, "Error: No port or baudrate specified to serial programmer driver.\n" "Use flashrom -p serprog=/dev/device:baud or flashrom -p serprog=ip:port\n"); exit(1); @@ -344,28 +344,28 @@ int serprog_init(void) free(dev); dev = NULL; free(num); num = NULL; - printf_debug(MSGHEADER "connected - attempting to synchronize\n"); + print(MSG_DEBUG, MSGHEADER "connected - attempting to synchronize\n"); sp_check_avail_automatic = 0; sp_synchronize(); - printf_debug(MSGHEADER "Synchronized\n"); + print(MSG_DEBUG, MSGHEADER "Synchronized\n"); if (sp_docommand(S_CMD_Q_IFACE, 0, NULL, 2, &iface)) { - fprintf(stderr, "Error: NAK to Query Interface version\n"); + print(MSG_ERROR, "Error: NAK to Query Interface version\n"); exit(1); } if (iface != 1) { - fprintf(stderr, "Error: Unknown interface version %d\n", iface); + print(MSG_ERROR, "Error: Unknown interface version %d\n", iface); exit(1); } - printf_debug(MSGHEADER "Interface version ok.\n"); + print(MSG_DEBUG, MSGHEADER "Interface version ok.\n"); if (sp_docommand(S_CMD_Q_CMDMAP, 0, NULL, 32, sp_cmdmap)) { - fprintf(stderr, "Error: query command map not supported\n"); + print(MSG_ERROR, "Error: query command map not supported\n"); exit(1); } @@ -373,80 +373,80 @@ int serprog_init(void) /* Check for the minimum operational set of commands */ if (sp_check_commandavail(S_CMD_R_BYTE) == 0) { - fprintf(stderr, "Error: Single byte read not supported\n"); + print(MSG_ERROR, "Error: Single byte read not supported\n"); exit(1); } /* This could be translated to single byte reads (if missing), * * but now we dont support that. */ if (sp_check_commandavail(S_CMD_R_NBYTES) == 0) { - fprintf(stderr, "Error: Read n bytes not supported\n"); + print(MSG_ERROR, "Error: Read n bytes not supported\n"); exit(1); } /* In the future one could switch to read-only mode if these * * are not available. */ if (sp_check_commandavail(S_CMD_O_INIT) == 0) { - fprintf(stderr, + fprint(MSG_NORMAL, stderr, "Error: Initialize operation buffer not supported\n"); exit(1); } if (sp_check_commandavail(S_CMD_O_WRITEB) == 0) { - fprintf(stderr, + fprint(MSG_NORMAL, stderr, "Error: Write to opbuf: write byte not supported\n"); exit(1); } if (sp_check_commandavail(S_CMD_O_DELAY) == 0) { - fprintf(stderr, "Error: Write to opbuf: delay not supported\n"); + print(MSG_ERROR, "Error: Write to opbuf: delay not supported\n"); exit(1); } if (sp_check_commandavail(S_CMD_O_EXEC) == 0) { - fprintf(stderr, + fprint(MSG_NORMAL, stderr, "Error: Execute operation buffer not supported\n"); exit(1); } if (sp_docommand(S_CMD_Q_PGMNAME, 0, NULL, 16, pgmname)) { - fprintf(stderr, "Warning: NAK to query programmer name\n"); + print(MSG_ERROR, "Warning: NAK to query programmer name\n"); strcpy((char *)pgmname, "(unknown)"); } pgmname[16] = 0; - printf(MSGHEADER "Programmer name \"%s\"\n", pgmname); + print(MSG_NORMAL, MSGHEADER "Programmer name \"%s\"\n", pgmname); if (sp_docommand(S_CMD_Q_SERBUF, 0, NULL, 2, &sp_device_serbuf_size)) { - fprintf(stderr, "Warning: NAK to query serial buffer size\n"); + print(MSG_ERROR, "Warning: NAK to query serial buffer size\n"); } - printf_debug(MSGHEADER "serial buffer size %d\n", + print(MSG_DEBUG, MSGHEADER "serial buffer size %d\n", sp_device_serbuf_size); if (sp_docommand(S_CMD_Q_OPBUF, 0, NULL, 2, &sp_device_opbuf_size)) { - fprintf(stderr, + fprint(MSG_NORMAL, stderr, "Warning: NAK to query operation buffer size\n"); } - printf_debug(MSGHEADER "operation buffer size %d\n", + print(MSG_DEBUG, MSGHEADER "operation buffer size %d\n", sp_device_opbuf_size); if (sp_docommand(S_CMD_Q_BUSTYPE, 0, NULL, 1, &c)) { - fprintf(stderr, "Warning: NAK to query supported buses\n"); + print(MSG_ERROR, "Warning: NAK to query supported buses\n"); c = CHIP_BUSTYPE_NONSPI; /* A reasonable default for now. */ } buses_supported = c; if (sp_docommand(S_CMD_O_INIT, 0, NULL, 0, NULL)) { - fprintf(stderr, "Error: NAK to initialize operation buffer\n"); + print(MSG_ERROR, "Error: NAK to initialize operation buffer\n"); exit(1); } if (sp_docommand(S_CMD_Q_WRNMAXLEN, 0, NULL, 3, rbuf)) { - printf_debug(MSGHEADER "Write-n not supported"); + print(MSG_DEBUG, MSGHEADER "Write-n not supported"); sp_max_write_n = 0; } else { sp_max_write_n = ((unsigned int)(rbuf[0]) << 0); sp_max_write_n |= ((unsigned int)(rbuf[1]) << 8); sp_max_write_n |= ((unsigned int)(rbuf[2]) << 16); - printf_debug(MSGHEADER "Maximum write-n length %d\n", + print(MSG_DEBUG, MSGHEADER "Maximum write-n length %d\n", sp_max_write_n); sp_write_n_buf = malloc(sp_max_write_n); if (!sp_write_n_buf) { - fprintf(stderr, + fprint(MSG_NORMAL, stderr, "Error: cannot allocate memory for Write-n buffer\n"); exit(1); } @@ -458,10 +458,10 @@ int serprog_init(void) sp_max_read_n = ((unsigned int)(rbuf[0]) << 0); sp_max_read_n |= ((unsigned int)(rbuf[1]) << 8); sp_max_read_n |= ((unsigned int)(rbuf[2]) << 16); - printf_debug(MSGHEADER "Maximum read-n length %d\n", + print(MSG_DEBUG, MSGHEADER "Maximum read-n length %d\n", sp_max_read_n ? sp_max_read_n : (1<<24)); } else { - printf_debug(MSGHEADER "Maximum read-n length not reported\n"); + print(MSG_DEBUG, MSGHEADER "Maximum read-n length not reported\n"); sp_max_read_n = 0; } @@ -477,7 +477,7 @@ int serprog_init(void) static void sp_pass_writen(void) { unsigned char header[7]; - printf_debug(MSGHEADER "Passing write-n bytes=%d addr=0x%x\n", + print(MSG_DEBUG, MSGHEADER "Passing write-n bytes=%d addr=0x%x\n", sp_write_n_bytes, sp_write_n_addr); if (sp_streamed_transmit_bytes >= (7 + sp_write_n_bytes + sp_device_serbuf_size)) @@ -517,7 +517,7 @@ static void sp_execute_opbuf_noflush(void) if ((sp_max_write_n) && (sp_write_n_bytes)) sp_pass_writen(); sp_stream_buffer_op(S_CMD_O_EXEC, 0, 0); - printf_debug(MSGHEADER "Executed operation buffer of %d bytes\n", + print(MSG_DEBUG, MSGHEADER "Executed operation buffer of %d bytes\n", sp_opbuf_usage); sp_opbuf_usage = 0; sp_prev_was_write = 0; @@ -532,7 +532,7 @@ static void sp_execute_opbuf(void) int serprog_shutdown(void) { - printf_debug("%s\n", __func__); + print(MSG_DEBUG, "%s\n", __func__); if ((sp_opbuf_usage) || (sp_max_write_n && sp_write_n_bytes)) sp_execute_opbuf(); close(sp_fd); @@ -547,14 +547,14 @@ static void sp_check_opbuf_usage(int bytes_to_be_added) sp_execute_opbuf(); /* If this happens in the mid of an page load the page load * * will propably fail. */ - printf_debug(MSGHEADER + print(MSG_DEBUG, MSGHEADER "Warning: executed operation buffer due to size reasons\n"); } } void serprog_chip_writeb(uint8_t val, chipaddr addr) { - printf_debug("%s\n", __func__); + print(MSG_DEBUG, "%s\n", __func__); if (sp_max_write_n) { if ((sp_prev_was_write) && (addr == (sp_write_n_addr + sp_write_n_bytes))) { @@ -598,7 +598,7 @@ uint8_t serprog_chip_readb(const chipaddr addr) sp_flush_stream(); if (read(sp_fd, &c, 1) != 1) sp_die("readb byteread"); - printf_debug("%s addr=0x%lx returning 0x%02X\n", __func__, addr, c); + print(MSG_DEBUG, "%s addr=0x%lx returning 0x%02X\n", __func__, addr, c); return c; } @@ -607,7 +607,7 @@ static void sp_do_read_n(uint8_t * buf, const chipaddr addr, size_t len) { int rd_bytes = 0; unsigned char sbuf[6]; - printf_debug("%s: addr=0x%lx len=%lu\n", __func__, addr, (unsigned long)len); + print(MSG_DEBUG, "%s: addr=0x%lx len=%lu\n", __func__, addr, (unsigned long)len); /* Stream the read-n -- as above. */ if ((sp_opbuf_usage) || (sp_max_write_n && sp_write_n_bytes)) sp_execute_opbuf_noflush(); @@ -644,7 +644,7 @@ void serprog_chip_readn(uint8_t * buf, const chipaddr addr, size_t len) void serprog_delay(int delay) { unsigned char buf[4]; - printf_debug("%s\n", __func__); + print(MSG_DEBUG, "%s\n", __func__); if ((sp_max_write_n) && (sp_write_n_bytes)) sp_pass_writen(); sp_check_opbuf_usage(5); diff --git a/sharplhf00l04.c b/sharplhf00l04.c index 1234ae4..8136cde 100644 --- a/sharplhf00l04.c +++ b/sharplhf00l04.c @@ -24,13 +24,13 @@ // I need that Berkeley bit-map printer void print_lhf00l04_status(uint8_t status) { - printf("%s", status & 0x80 ? "Ready:" : "Busy:"); - printf("%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:"); - printf("%s", status & 0x20 ? "BE ERROR:" : "BE OK:"); - printf("%s", status & 0x10 ? "PROG ERR:" : "PROG OK:"); - printf("%s", status & 0x8 ? "VP ERR:" : "VPP OK:"); - printf("%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:"); - printf("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:"); + print(MSG_NORMAL, "%s", status & 0x80 ? "Ready:" : "Busy:"); + print(MSG_NORMAL, "%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:"); + print(MSG_NORMAL, "%s", status & 0x20 ? "BE ERROR:" : "BE OK:"); + print(MSG_NORMAL, "%s", status & 0x10 ? "PROG ERR:" : "PROG OK:"); + print(MSG_NORMAL, "%s", status & 0x8 ? "VP ERR:" : "VPP OK:"); + print(MSG_NORMAL, "%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:"); + print(MSG_NORMAL, "%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:"); } int probe_lhf00l04(struct flashchip *flash) @@ -60,7 +60,7 @@ int probe_lhf00l04(struct flashchip *flash) programmer_delay(10); - printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); + print(MSG_DEBUG, "%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); if (id1 != flash->manufacture_id || id2 != flash->model_id) return 0; @@ -105,14 +105,14 @@ int erase_lhf00l04_block(struct flashchip *flash, int offset) // clear status register chip_writeb(0x50, bios); - printf("Erase at 0x%lx\n", bios); + print(MSG_NORMAL, "Erase at 0x%lx\n", bios); status = wait_lhf00l04(flash->virtual_memory); print_lhf00l04_status(status); // clear write protect - printf("write protect is at 0x%lx\n", (wrprotect)); - printf("write protect is 0x%x\n", chip_readb(wrprotect)); + print(MSG_NORMAL, "write protect is at 0x%lx\n", (wrprotect)); + print(MSG_NORMAL, "write protect is 0x%x\n", chip_readb(wrprotect)); chip_writeb(0, wrprotect); - printf("write protect is 0x%x\n", chip_readb(wrprotect)); + print(MSG_NORMAL, "write protect is 0x%x\n", chip_readb(wrprotect)); // now start it chip_writeb(0x20, bios); @@ -121,10 +121,10 @@ int erase_lhf00l04_block(struct flashchip *flash, int offset) // now let's see what the register is status = wait_lhf00l04(flash->virtual_memory); print_lhf00l04_status(status); - printf("DONE BLOCK 0x%x\n", offset); + print(MSG_NORMAL, "DONE BLOCK 0x%x\n", offset); if (check_erased_range(flash, offset, flash->page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; @@ -135,14 +135,14 @@ int erase_lhf00l04(struct flashchip *flash) int i; unsigned int total_size = flash->total_size * 1024; - printf("total_size is %d; flash->page_size is %d\n", + print(MSG_NORMAL, "total_size is %d; flash->page_size is %d\n", total_size, flash->page_size); for (i = 0; i < total_size; i += flash->page_size) if (erase_lhf00l04_block(flash, i)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } - printf("DONE ERASE\n"); + print(MSG_NORMAL, "DONE ERASE\n"); return 0; } @@ -168,17 +168,17 @@ int write_lhf00l04(struct flashchip *flash, uint8_t *buf) chipaddr bios = flash->virtual_memory; if (erase_lhf00l04(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } - printf("Programming page: "); + print(MSG_NORMAL, "Programming page: "); for (i = 0; i < total_size / page_size; i++) { - printf("%04d at address: 0x%08x", i, i * page_size); + print(MSG_NORMAL, "%04d at address: 0x%08x", i, i * page_size); write_page_lhf00l04(bios, buf + i * page_size, bios + i * page_size, page_size); - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); } - printf("\n"); + print(MSG_NORMAL, "\n"); return 0; } diff --git a/spi.c b/spi.c index 14beed7..382e361 100644 --- a/spi.c +++ b/spi.c @@ -118,7 +118,7 @@ int spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr) { if (!spi_programmer[spi_controller].command) { - fprintf(stderr, "%s called, but SPI is unsupported on this " + print(MSG_ERROR, "%s called, but SPI is unsupported on this " "hardware. Please report a bug.\n", __func__); return 1; } @@ -130,7 +130,7 @@ int spi_send_command(unsigned int writecnt, unsigned int readcnt, int spi_send_multicommand(struct spi_command *cmds) { if (!spi_programmer[spi_controller].multicommand) { - fprintf(stderr, "%s called, but SPI is unsupported on this " + print(MSG_ERROR, "%s called, but SPI is unsupported on this " "hardware. Please report a bug.\n", __func__); return 1; } @@ -176,10 +176,10 @@ static int spi_rdid(unsigned char *readarr, int bytes) ret = spi_send_command(sizeof(cmd), bytes, cmd, readarr); if (ret) return ret; - printf_debug("RDID returned"); + print(MSG_DEBUG, "RDID returned"); for (i = 0; i < bytes; i++) - printf_debug(" 0x%02x", readarr[i]); - printf_debug(". "); + print(MSG_DEBUG, " 0x%02x", readarr[i]); + print(MSG_DEBUG, ". "); return 0; } @@ -200,7 +200,7 @@ static int spi_rems(unsigned char *readarr) } if (ret) return ret; - printf_debug("REMS returned %02x %02x. ", readarr[0], readarr[1]); + print(MSG_DEBUG, "REMS returned %02x %02x. ", readarr[0], readarr[1]); return 0; } @@ -221,7 +221,7 @@ static int spi_res(unsigned char *readarr) } if (ret) return ret; - printf_debug("RES returned %02x. ", readarr[0]); + print(MSG_DEBUG, "RES returned %02x. ", readarr[0]); return 0; } @@ -234,7 +234,7 @@ int spi_write_enable(void) result = spi_send_command(sizeof(cmd), 0, cmd, NULL); if (result) - fprintf(stderr, "%s failed\n", __func__); + print(MSG_ERROR, "%s failed\n", __func__); return result; } @@ -257,12 +257,12 @@ static int probe_spi_rdid_generic(struct flashchip *flash, int bytes) return 0; if (!oddparity(readarr[0])) - printf_debug("RDID byte 0 parity violation. "); + print(MSG_DEBUG, "RDID byte 0 parity violation. "); /* Check if this is a continuation vendor ID */ if (readarr[0] == 0x7f) { if (!oddparity(readarr[1])) - printf_debug("RDID byte 1 parity violation. "); + print(MSG_DEBUG, "RDID byte 1 parity violation. "); id1 = (readarr[0] << 8) | readarr[1]; id2 = readarr[2]; if (bytes > 3) { @@ -274,7 +274,7 @@ static int probe_spi_rdid_generic(struct flashchip *flash, int bytes) id2 = (readarr[1] << 8) | readarr[2]; } - printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); + print(MSG_DEBUG, "%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); if (id1 == flash->manufacture_id && id2 == flash->model_id) { /* Print the status register to tell the @@ -324,7 +324,7 @@ int probe_spi_rdid4(struct flashchip *flash) #endif return probe_spi_rdid_generic(flash, 4); default: - printf_debug("4b ID not supported on this SPI controller\n"); + print(MSG_DEBUG, "4b ID not supported on this SPI controller\n"); } return 0; @@ -341,7 +341,7 @@ int probe_spi_rems(struct flashchip *flash) id1 = readarr[0]; id2 = readarr[1]; - printf_debug("%s: id1 0x%x, id2 0x%x\n", __func__, id1, id2); + print(MSG_DEBUG, "%s: id1 0x%x, id2 0x%x\n", __func__, id1, id2); if (id1 == flash->manufacture_id && id2 == flash->model_id) { /* Print the status register to tell the @@ -381,7 +381,7 @@ int probe_spi_res(struct flashchip *flash) return 0; id2 = readarr[0]; - printf_debug("%s: id 0x%x\n", __func__, id2); + print(MSG_DEBUG, "%s: id 0x%x\n", __func__, id2); if (id2 != flash->model_id) return 0; @@ -402,7 +402,7 @@ uint8_t spi_read_status_register(void) /* Read Status Register */ ret = spi_send_command(sizeof(cmd), sizeof(readarr), cmd, readarr); if (ret) - fprintf(stderr, "RDSR failed!\n"); + print(MSG_ERROR, "RDSR failed!\n"); return readarr[0]; } @@ -410,17 +410,17 @@ uint8_t spi_read_status_register(void) /* Prettyprint the status register. Common definitions. */ void spi_prettyprint_status_register_common(uint8_t status) { - printf_debug("Chip status register: Bit 5 / Block Protect 3 (BP3) is " + print(MSG_DEBUG, "Chip status register: Bit 5 / Block Protect 3 (BP3) is " "%sset\n", (status & (1 << 5)) ? "" : "not "); - printf_debug("Chip status register: Bit 4 / Block Protect 2 (BP2) is " + print(MSG_DEBUG, "Chip status register: Bit 4 / Block Protect 2 (BP2) is " "%sset\n", (status & (1 << 4)) ? "" : "not "); - printf_debug("Chip status register: Bit 3 / Block Protect 1 (BP1) is " + print(MSG_DEBUG, "Chip status register: Bit 3 / Block Protect 1 (BP1) is " "%sset\n", (status & (1 << 3)) ? "" : "not "); - printf_debug("Chip status register: Bit 2 / Block Protect 0 (BP0) is " + print(MSG_DEBUG, "Chip status register: Bit 2 / Block Protect 0 (BP0) is " "%sset\n", (status & (1 << 2)) ? "" : "not "); - printf_debug("Chip status register: Write Enable Latch (WEL) is " + print(MSG_DEBUG, "Chip status register: Write Enable Latch (WEL) is " "%sset\n", (status & (1 << 1)) ? "" : "not "); - printf_debug("Chip status register: Write In Progress (WIP/BUSY) is " + print(MSG_DEBUG, "Chip status register: Write In Progress (WIP/BUSY) is " "%sset\n", (status & (1 << 0)) ? "" : "not "); } @@ -430,18 +430,18 @@ void spi_prettyprint_status_register_common(uint8_t status) */ void spi_prettyprint_status_register_st_m25p(uint8_t status) { - printf_debug("Chip status register: Status Register Write Disable " + print(MSG_DEBUG, "Chip status register: Status Register Write Disable " "(SRWD) is %sset\n", (status & (1 << 7)) ? "" : "not "); - printf_debug("Chip status register: Bit 6 is " + print(MSG_DEBUG, "Chip status register: Bit 6 is " "%sset\n", (status & (1 << 6)) ? "" : "not "); spi_prettyprint_status_register_common(status); } void spi_prettyprint_status_register_sst25(uint8_t status) { - printf_debug("Chip status register: Block Protect Write Disable " + print(MSG_DEBUG, "Chip status register: Block Protect Write Disable " "(BPL) is %sset\n", (status & (1 << 7)) ? "" : "not "); - printf_debug("Chip status register: Auto Address Increment Programming " + print(MSG_DEBUG, "Chip status register: Auto Address Increment Programming " "(AAI) is %sset\n", (status & (1 << 6)) ? "" : "not "); spi_prettyprint_status_register_common(status); } @@ -461,7 +461,7 @@ void spi_prettyprint_status_register_sst25vf016(uint8_t status) "all", "all" }; spi_prettyprint_status_register_sst25(status); - printf_debug("Resulting block protection : %s\n", + print(MSG_DEBUG, "Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]); } @@ -475,7 +475,7 @@ void spi_prettyprint_status_register_sst25vf040b(uint8_t status) "all blocks", "all blocks", "all blocks", "all blocks" }; spi_prettyprint_status_register_sst25(status); - printf_debug("Resulting block protection : %s\n", + print(MSG_DEBUG, "Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]); } @@ -484,7 +484,7 @@ void spi_prettyprint_status_register(struct flashchip *flash) uint8_t status; status = spi_read_status_register(); - printf_debug("Chip status register is %02x\n", status); + print(MSG_DEBUG, "Chip status register is %02x\n", status); switch (flash->manufacture_id) { case ST_ID: if (((flash->model_id & 0xff00) == 0x2000) || @@ -535,13 +535,13 @@ int spi_chip_erase_60(struct flashchip *flash) result = spi_disable_blockprotect(); if (result) { - fprintf(stderr, "spi_disable_blockprotect failed\n"); + print(MSG_ERROR, "spi_disable_blockprotect failed\n"); return result; } result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution\n", + print(MSG_ERROR, "%s failed during command execution\n", __func__); return result; } @@ -552,7 +552,7 @@ int spi_chip_erase_60(struct flashchip *flash) while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(1000 * 1000); if (check_erased_range(flash, 0, flash->total_size * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; @@ -581,13 +581,13 @@ int spi_chip_erase_c7(struct flashchip *flash) result = spi_disable_blockprotect(); if (result) { - fprintf(stderr, "spi_disable_blockprotect failed\n"); + print(MSG_ERROR, "spi_disable_blockprotect failed\n"); return result; } result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution\n", __func__); + print(MSG_ERROR, "%s failed during command execution\n", __func__); return result; } /* Wait until the Write-In-Progress bit is cleared. @@ -597,7 +597,7 @@ int spi_chip_erase_c7(struct flashchip *flash) while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(1000 * 1000); if (check_erased_range(flash, 0, flash->total_size * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; @@ -608,7 +608,7 @@ int spi_chip_erase_60_c7(struct flashchip *flash) int result; result = spi_chip_erase_60(flash); if (result) { - printf_debug("spi_chip_erase_60 failed, trying c7\n"); + print(MSG_DEBUG, "spi_chip_erase_60 failed, trying c7\n"); result = spi_chip_erase_c7(flash); } return result; @@ -637,7 +637,7 @@ int spi_block_erase_52(struct flashchip *flash, unsigned int addr, unsigned int result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution at address 0x%x\n", + print(MSG_ERROR, "%s failed during command execution at address 0x%x\n", __func__, addr); return result; } @@ -647,7 +647,7 @@ int spi_block_erase_52(struct flashchip *flash, unsigned int addr, unsigned int while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(100 * 1000); if (check_erased_range(flash, addr, blocklen)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; @@ -681,7 +681,7 @@ int spi_block_erase_d8(struct flashchip *flash, unsigned int addr, unsigned int result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution at address 0x%x\n", + print(MSG_ERROR, "%s failed during command execution at address 0x%x\n", __func__, addr); return result; } @@ -691,7 +691,7 @@ int spi_block_erase_d8(struct flashchip *flash, unsigned int addr, unsigned int while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(100 * 1000); if (check_erased_range(flash, addr, blocklen)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; @@ -705,17 +705,17 @@ int spi_chip_erase_d8(struct flashchip *flash) spi_disable_blockprotect(); - printf("Erasing chip: \n"); + print(MSG_NORMAL, "Erasing chip: \n"); for (i = 0; i < total_size / erase_size; i++) { rc = spi_block_erase_d8(flash, i * erase_size, erase_size); if (rc) { - fprintf(stderr, "Error erasing block at 0x%x\n", i); + print(MSG_ERROR, "Error erasing block at 0x%x\n", i); break; } } - printf("\n"); + print(MSG_NORMAL, "\n"); return rc; } @@ -744,7 +744,7 @@ int spi_block_erase_20(struct flashchip *flash, unsigned int addr, unsigned int result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution at address 0x%x\n", + print(MSG_ERROR, "%s failed during command execution at address 0x%x\n", __func__, addr); return result; } @@ -754,7 +754,7 @@ int spi_block_erase_20(struct flashchip *flash, unsigned int addr, unsigned int while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(10 * 1000); if (check_erased_range(flash, addr, blocklen)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; @@ -763,7 +763,7 @@ int spi_block_erase_20(struct flashchip *flash, unsigned int addr, unsigned int int spi_block_erase_60(struct flashchip *flash, unsigned int addr, unsigned int blocklen) { if ((addr != 0) || (blocklen != flash->total_size * 1024)) { - fprintf(stderr, "%s called with incorrect arguments\n", + print(MSG_ERROR, "%s called with incorrect arguments\n", __func__); return -1; } @@ -773,7 +773,7 @@ int spi_block_erase_60(struct flashchip *flash, unsigned int addr, unsigned int int spi_block_erase_c7(struct flashchip *flash, unsigned int addr, unsigned int blocklen) { if ((addr != 0) || (blocklen != flash->total_size * 1024)) { - fprintf(stderr, "%s called with incorrect arguments\n", + print(MSG_ERROR, "%s called with incorrect arguments\n", __func__); return -1; } @@ -789,7 +789,7 @@ int spi_write_status_enable(void) result = spi_send_command(sizeof(cmd), JEDEC_EWSR_INSIZE, cmd, NULL); if (result) - fprintf(stderr, "%s failed\n", __func__); + print(MSG_ERROR, "%s failed\n", __func__); return result; } @@ -821,7 +821,7 @@ int spi_write_status_register(int status) result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution\n", + print(MSG_ERROR, "%s failed during command execution\n", __func__); } return result; @@ -850,7 +850,7 @@ int spi_byte_program(int addr, uint8_t byte) result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution at address 0x%x\n", + print(MSG_ERROR, "%s failed during command execution at address 0x%x\n", __func__, addr); } return result; @@ -885,11 +885,11 @@ int spi_nbyte_program(int addr, uint8_t *bytes, int len) }}; if (!len) { - fprintf(stderr, "%s called for zero-length write\n", __func__); + print(MSG_ERROR, "%s called for zero-length write\n", __func__); return 1; } if (len > 256) { - fprintf(stderr, "%s called for too long a write\n", __func__); + print(MSG_ERROR, "%s called for too long a write\n", __func__); return 1; } @@ -897,7 +897,7 @@ int spi_nbyte_program(int addr, uint8_t *bytes, int len) result = spi_send_multicommand(cmds); if (result) { - fprintf(stderr, "%s failed during command execution at address 0x%x\n", + print(MSG_ERROR, "%s failed during command execution at address 0x%x\n", __func__, addr); } return result; @@ -911,10 +911,10 @@ int spi_disable_blockprotect(void) status = spi_read_status_register(); /* If there is block protection in effect, unprotect it first. */ if ((status & 0x3c) != 0) { - printf_debug("Some block protection in effect, disabling\n"); + print(MSG_DEBUG, "Some block protection in effect, disabling\n"); result = spi_write_status_register(status & ~0x3c); if (result) { - fprintf(stderr, "spi_write_status_register failed\n"); + print(MSG_ERROR, "spi_write_status_register failed\n"); return result; } } @@ -976,7 +976,7 @@ int spi_read_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, int spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len) { if (!spi_programmer[spi_controller].read) { - fprintf(stderr, "%s called, but SPI read is unsupported on this" + print(MSG_ERROR, "%s called, but SPI read is unsupported on this" " hardware. Please report a bug.\n", __func__); return 1; } @@ -997,12 +997,12 @@ int spi_chip_write_1(struct flashchip *flash, uint8_t *buf) spi_disable_blockprotect(); /* Erase first */ - printf("Erasing flash before programming... "); + print(MSG_NORMAL, "Erasing flash before programming... "); if (erase_flash(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } - printf("done.\n"); + print(MSG_NORMAL, "done.\n"); for (i = 0; i < total_size; i++) { result = spi_byte_program(i, buf[i]); if (result) @@ -1021,7 +1021,7 @@ int spi_chip_write_1(struct flashchip *flash, uint8_t *buf) int spi_chip_write_256(struct flashchip *flash, uint8_t *buf) { if (!spi_programmer[spi_controller].write_256) { - fprintf(stderr, "%s called, but SPI page write is unsupported " + print(MSG_ERROR, "%s called, but SPI page write is unsupported " " on this hardware. Please report a bug.\n", __func__); return 1; } @@ -1043,14 +1043,14 @@ int spi_aai_write(struct flashchip *flash, uint8_t *buf) switch (spi_controller) { case SPI_CONTROLLER_WBSIO: - fprintf(stderr, "%s: impossible with Winbond SPI masters," + print(MSG_ERROR, "%s: impossible with Winbond SPI masters," " degrading to byte program\n", __func__); return spi_chip_write_1(flash, buf); default: break; } if (erase_flash(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } result = spi_write_enable(); diff --git a/sst28sf040.c b/sst28sf040.c index 930ad5b..7f65b90 100644 --- a/sst28sf040.c +++ b/sst28sf040.c @@ -61,7 +61,7 @@ static int erase_sector_28sf040(struct flashchip *flash, unsigned long address, toggle_ready_jedec(bios); if (check_erased_range(flash, address, sector_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; @@ -107,7 +107,7 @@ int probe_28sf040(struct flashchip *flash) chip_writeb(RESET, bios); programmer_delay(10); - printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); + print(MSG_DEBUG, "%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); if (id1 == flash->manufacture_id && id2 == flash->model_id) return 1; @@ -127,7 +127,7 @@ int erase_28sf040(struct flashchip *flash) toggle_ready_jedec(bios); if (check_erased_range(flash, 0, flash->total_size * 1024)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; @@ -142,21 +142,21 @@ int write_28sf040(struct flashchip *flash, uint8_t *buf) unprotect_28sf040(bios); - printf("Programming page: "); + print(MSG_NORMAL, "Programming page: "); for (i = 0; i < total_size / page_size; i++) { /* erase the page before programming */ if (erase_sector_28sf040(flash, i * page_size, page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } /* write to the sector */ - printf("%04d at address: 0x%08x", i, i * page_size); + print(MSG_NORMAL, "%04d at address: 0x%08x", i, i * page_size); write_sector_28sf040(bios, buf + i * page_size, bios + i * page_size, page_size); - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); } - printf("\n"); + print(MSG_NORMAL, "\n"); protect_28sf040(bios); diff --git a/sst49lf040.c b/sst49lf040.c index ab1c918..8d0bdfb 100644 --- a/sst49lf040.c +++ b/sst49lf040.c @@ -30,7 +30,7 @@ int erase_49lf040(struct flashchip *flash) /* Chip erase only works in parallel programming mode * for the 49lf040. Use sector-erase instead */ if (erase_sector_jedec(flash, i * page_size, page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } } @@ -45,28 +45,28 @@ int write_49lf040(struct flashchip *flash, uint8_t *buf) int page_size = flash->page_size; chipaddr bios = flash->virtual_memory; - printf("Programming page: "); + print(MSG_NORMAL, "Programming page: "); for (i = 0; i < total_size / page_size; i++) { /* erase the page before programming * Chip erase only works in parallel programming mode * for the 49lf040. Use sector-erase instead */ if (erase_sector_jedec(flash, i * page_size, page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } /* write to the sector */ if (i % 10 == 0) - printf("%04d at address: 0x%08x ", i, i * page_size); + print(MSG_NORMAL, "%04d at address: 0x%08x ", i, i * page_size); write_sector_jedec(bios, buf + i * page_size, bios + i * page_size, page_size); if (i % 10 == 0) - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } - printf("\n"); + print(MSG_NORMAL, "\n"); return 0; } diff --git a/sst49lfxxxc.c b/sst49lfxxxc.c index a421acf..69cbb6d 100644 --- a/sst49lfxxxc.c +++ b/sst49lfxxxc.c @@ -41,30 +41,30 @@ static int write_lockbits_49lfxxxc(struct flashchip *flash, unsigned char bits) int i, left = flash->total_size * 1024; unsigned long address; - printf_debug("\nbios=0x%08lx\n", registers); + print(MSG_DEBUG, "\nbios=0x%08lx\n", registers); for (i = 0; left > 65536; i++, left -= 65536) { - printf_debug("lockbits at address=0x%08lx is 0x%01x\n", + print(MSG_DEBUG, "lockbits at address=0x%08lx is 0x%01x\n", registers + (i * 65536) + 2, chip_readb(registers + (i * 65536) + 2)); chip_writeb(bits, registers + (i * 65536) + 2); } address = i * 65536; - printf_debug("lockbits at address=0x%08lx is 0x%01x\n", + print(MSG_DEBUG, "lockbits at address=0x%08lx is 0x%01x\n", registers + address + 2, chip_readb(registers + address + 2)); chip_writeb(bits, registers + address + 2); address += 32768; - printf_debug("lockbits at address=0x%08lx is 0x%01x\n", + print(MSG_DEBUG, "lockbits at address=0x%08lx is 0x%01x\n", registers + address + 2, chip_readb(registers + address + 2)); chip_writeb(bits, registers + address + 2); address += 8192; - printf_debug("lockbits at address=0x%08lx is 0x%01x\n", + print(MSG_DEBUG, "lockbits at address=0x%08lx is 0x%01x\n", registers + address + 2, chip_readb(registers + address + 2)); chip_writeb(bits, registers + address + 2); address += 8192; - printf_debug("lockbits at address=0x%08lx is 0x%01x\n", + print(MSG_DEBUG, "lockbits at address=0x%08lx is 0x%01x\n", registers + address + 2, chip_readb(registers + address + 2)); chip_writeb(bits, registers + address + 2); @@ -83,7 +83,7 @@ static int erase_sector_49lfxxxc(struct flashchip *flash, unsigned long address, do { status = chip_readb(bios); if (status & (STATUS_ESS | STATUS_BPS)) { - printf("sector erase FAILED at address=0x%08lx status=0x%01x\n", bios + address, status); + print(MSG_NORMAL, "sector erase FAILED at address=0x%08lx status=0x%01x\n", bios + address, status); chip_writeb(CLEAR_STATUS, bios); return (-1); } @@ -91,7 +91,7 @@ static int erase_sector_49lfxxxc(struct flashchip *flash, unsigned long address, chip_writeb(RESET, bios); if (check_erased_range(flash, address, sector_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; @@ -118,7 +118,7 @@ static int write_sector_49lfxxxc(chipaddr bios, uint8_t *src, chipaddr dst, do { status = chip_readb(bios); if (status & (STATUS_ESS | STATUS_BPS)) { - printf("sector write FAILED at address=0x%08lx status=0x%01x\n", dst, status); + print(MSG_NORMAL, "sector write FAILED at address=0x%08lx status=0x%01x\n", dst, status); chip_writeb(CLEAR_STATUS, bios); return (-1); } @@ -141,7 +141,7 @@ int probe_49lfxxxc(struct flashchip *flash) chip_writeb(RESET, bios); - printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); + print(MSG_DEBUG, "%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); if (!(id1 == flash->manufacture_id && id2 == flash->model_id)) return 0; @@ -175,21 +175,21 @@ int write_49lfxxxc(struct flashchip *flash, uint8_t *buf) chipaddr bios = flash->virtual_memory; write_lockbits_49lfxxxc(flash, 0); - printf("Programming page: "); + print(MSG_NORMAL, "Programming page: "); for (i = 0; i < total_size / page_size; i++) { /* erase the page before programming */ if (erase_sector_49lfxxxc(flash, i * page_size, flash->page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } /* write to the sector */ - printf("%04d at address: 0x%08x", i, i * page_size); + print(MSG_NORMAL, "%04d at address: 0x%08x", i, i * page_size); write_sector_49lfxxxc(bios, buf + i * page_size, bios + i * page_size, page_size); - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); } - printf("\n"); + print(MSG_NORMAL, "\n"); chip_writeb(RESET, bios); diff --git a/sst_fwhub.c b/sst_fwhub.c index f09aa54..d6f9fb0 100644 --- a/sst_fwhub.c +++ b/sst_fwhub.c @@ -28,13 +28,13 @@ // I need that Berkeley bit-map printer void print_sst_fwhub_status(uint8_t status) { - printf("%s", status & 0x80 ? "Ready:" : "Busy:"); - printf("%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:"); - printf("%s", status & 0x20 ? "BE ERROR:" : "BE OK:"); - printf("%s", status & 0x10 ? "PROG ERR:" : "PROG OK:"); - printf("%s", status & 0x8 ? "VP ERR:" : "VPP OK:"); - printf("%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:"); - printf("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:"); + print(MSG_NORMAL, "%s", status & 0x80 ? "Ready:" : "Busy:"); + print(MSG_NORMAL, "%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:"); + print(MSG_NORMAL, "%s", status & 0x20 ? "BE ERROR:" : "BE OK:"); + print(MSG_NORMAL, "%s", status & 0x10 ? "PROG ERR:" : "PROG OK:"); + print(MSG_NORMAL, "%s", status & 0x8 ? "VP ERR:" : "VPP OK:"); + print(MSG_NORMAL, "%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:"); + print(MSG_NORMAL, "%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:"); } int check_sst_fwhub_block_lock(struct flashchip *flash, int offset) @@ -43,20 +43,20 @@ int check_sst_fwhub_block_lock(struct flashchip *flash, int offset) uint8_t blockstatus; blockstatus = chip_readb(registers + offset + 2); - printf_debug("Lock status for 0x%06x (size 0x%06x) is %02x, ", + print(MSG_DEBUG, "Lock status for 0x%06x (size 0x%06x) is %02x, ", offset, flash->page_size, blockstatus); switch (blockstatus & 0x3) { case 0x0: - printf_debug("full access\n"); + print(MSG_DEBUG, "full access\n"); break; case 0x1: - printf_debug("write locked\n"); + print(MSG_DEBUG, "write locked\n"); break; case 0x2: - printf_debug("locked open\n"); + print(MSG_DEBUG, "locked open\n"); break; case 0x3: - printf_debug("write locked down\n"); + print(MSG_DEBUG, "write locked down\n"); break; } /* Return content of the write_locked bit */ @@ -71,11 +71,11 @@ int clear_sst_fwhub_block_lock(struct flashchip *flash, int offset) blockstatus = check_sst_fwhub_block_lock(flash, offset); if (blockstatus) { - printf_debug("Trying to clear lock for 0x%06x... ", offset) + print(MSG_DEBUG, "Trying to clear lock for 0x%06x... ", offset) chip_writeb(0, registers + offset + 2); blockstatus = check_sst_fwhub_block_lock(flash, offset); - printf_debug("%s\n", (blockstatus) ? "failed" : "OK"); + print(MSG_DEBUG, "%s\n", (blockstatus) ? "failed" : "OK"); } return blockstatus; @@ -102,13 +102,13 @@ int erase_sst_fwhub_block(struct flashchip *flash, unsigned int offset, unsigned uint8_t blockstatus = clear_sst_fwhub_block_lock(flash, offset); if (blockstatus) { - printf("Block lock clearing failed, not erasing block " + print(MSG_NORMAL, "Block lock clearing failed, not erasing block " "at 0x%06x\n", offset); return 1; } if (erase_block_jedec(flash, offset, page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } toggle_ready_jedec(flash->virtual_memory); @@ -123,7 +123,7 @@ int erase_sst_fwhub(struct flashchip *flash) for (i = 0; i < total_size; i += flash->page_size) { if (erase_sst_fwhub_block(flash, i, flash->page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } } @@ -139,9 +139,9 @@ int write_sst_fwhub(struct flashchip *flash, uint8_t *buf) chipaddr bios = flash->virtual_memory; uint8_t *readbuf = malloc(page_size); - printf("Programming page: "); + print(MSG_NORMAL, "Programming page: "); for (i = 0; i < total_size / page_size; i++) { - printf("%04d at address: 0x%08x", i, i * page_size); + print(MSG_NORMAL, "%04d at address: 0x%08x", i, i * page_size); /* Auto Skip Blocks, which already contain the desired data: * Faster, because we only write, what has changed @@ -160,9 +160,9 @@ int write_sst_fwhub(struct flashchip *flash, uint8_t *buf) write_sector_jedec(bios, buf + i * page_size, bios + i * page_size, page_size); } - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); } - printf("\n"); + print(MSG_NORMAL, "\n"); return 0; } diff --git a/stm50flw0x0x.c b/stm50flw0x0x.c index 0ae6eb8..91fdeb5 100644 --- a/stm50flw0x0x.c +++ b/stm50flw0x0x.c @@ -91,19 +91,19 @@ int unlock_block_stm50flw0x0x(struct flashchip *flash, int offset) // unlock each 4k-sector for (j = 0; j < 0x10000; j += 0x1000) { - printf_debug("unlocking at 0x%x\n", offset + j); + print(MSG_DEBUG, "unlocking at 0x%x\n", offset + j); chip_writeb(unlock_sector, wrprotect + offset + j); if (chip_readb(wrprotect + offset + j) != unlock_sector) { - printf("Cannot unlock sector @ 0x%x\n", + print(MSG_NORMAL, "Cannot unlock sector @ 0x%x\n", offset + j); return -1; } } } else { - printf_debug("unlocking at 0x%x\n", offset); + print(MSG_DEBUG, "unlocking at 0x%x\n", offset); chip_writeb(unlock_sector, wrprotect + offset); if (chip_readb(wrprotect + offset) != unlock_sector) { - printf("Cannot unlock sector @ 0x%x\n", offset); + print(MSG_NORMAL, "Cannot unlock sector @ 0x%x\n", offset); return -1; } } @@ -117,7 +117,7 @@ int erase_block_stm50flw0x0x(struct flashchip *flash, int offset) // clear status register chip_writeb(0x50, bios); - printf_debug("Erase at 0x%lx\n", bios); + print(MSG_DEBUG, "Erase at 0x%lx\n", bios); // now start it chip_writeb(0x20, bios); chip_writeb(0xd0, bios); @@ -126,10 +126,10 @@ int erase_block_stm50flw0x0x(struct flashchip *flash, int offset) wait_stm50flw0x0x(flash->virtual_memory); if (check_erased_range(flash, offset, flash->page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } - printf("DONE BLOCK 0x%x\n", offset); + print(MSG_NORMAL, "DONE BLOCK 0x%x\n", offset); return 0; } @@ -165,7 +165,7 @@ int write_page_stm50flw0x0x(chipaddr bios, uint8_t *src, } if (rc) { - fprintf(stderr, " page 0x%lx failed!\n", + print(MSG_ERROR, " page 0x%lx failed!\n", (d - bios) / page_size); } @@ -181,21 +181,21 @@ int erase_stm50flw0x0x(struct flashchip *flash) int total_size = flash->total_size * 1024; int page_size = flash->page_size; - printf("Erasing page:\n"); + print(MSG_NORMAL, "Erasing page:\n"); for (i = 0; i < total_size / page_size; i++) { printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); - printf("%04d at address: 0x%08x ", i, i * page_size); + print(MSG_NORMAL, "%04d at address: 0x%08x ", i, i * page_size); if (unlock_block_stm50flw0x0x(flash, i * page_size)) { - fprintf(stderr, "UNLOCK FAILED!\n"); + print(MSG_ERROR, "UNLOCK FAILED!\n"); return -1; } if (erase_block_stm50flw0x0x(flash, i * page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } } - printf("\n"); + print(MSG_NORMAL, "\n"); return 0; } @@ -209,14 +209,14 @@ int write_stm50flw0x0x(struct flashchip *flash, uint8_t * buf) uint8_t *tmpbuf = malloc(page_size); if (!tmpbuf) { - printf("Could not allocate memory!\n"); + print(MSG_NORMAL, "Could not allocate memory!\n"); exit(1); } - printf("Programming page: \n"); + print(MSG_NORMAL, "Programming page: \n"); for (i = 0; (i < total_size / page_size) && (rc == 0); i++) { printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); - printf("%04d at address: 0x%08x ", i, i * page_size); + print(MSG_NORMAL, "%04d at address: 0x%08x ", i, i * page_size); /* Auto Skip Blocks, which already contain the desired data * Faster, because we only write, what has changed @@ -227,7 +227,7 @@ int write_stm50flw0x0x(struct flashchip *flash, uint8_t * buf) */ chip_readn(tmpbuf, bios + i * page_size, page_size); if (!memcmp((void *)(buf + i * page_size), tmpbuf, page_size)) { - printf("SKIPPED\n"); + print(MSG_NORMAL, "SKIPPED\n"); continue; } @@ -238,7 +238,7 @@ int write_stm50flw0x0x(struct flashchip *flash, uint8_t * buf) write_page_stm50flw0x0x(bios, buf + i * page_size, bios + i * page_size, page_size); } - printf("\n"); + print(MSG_NORMAL, "\n"); free(tmpbuf); return rc; diff --git a/udelay.c b/udelay.c index 9a0ab36..0b4436c 100644 --- a/udelay.c +++ b/udelay.c @@ -37,7 +37,7 @@ void myusec_calibrate_delay(void) struct timeval start, end; int ok = 0; - printf("Calibrating delay loop... "); + print(MSG_NORMAL, "Calibrating delay loop... "); while (!ok) { gettimeofday(&start, 0); @@ -59,7 +59,7 @@ void myusec_calibrate_delay(void) gettimeofday(&end, 0); timeusec = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec); - printf_debug("%ldM loops per second, 100 myus = %ld us. ", + print(MSG_DEBUG, "%ldM loops per second, 100 myus = %ld us. ", (unsigned long)micro, timeusec); - printf("OK.\n"); + print(MSG_NORMAL, "OK.\n"); } diff --git a/w29ee011.c b/w29ee011.c index de9a547..6872c12 100644 --- a/w29ee011.c +++ b/w29ee011.c @@ -28,7 +28,7 @@ int probe_w29ee011(struct flashchip *flash) extern char *chip_to_probe; if (!chip_to_probe || strcmp(chip_to_probe, "W29EE011")) { - printf_debug("Probing disabled for Winbond W29EE011 because " + print(MSG_DEBUG, "Probing disabled for Winbond W29EE011 because " "the probing sequence puts the AMIC A49LF040A in " "a funky state. Use 'flashrom -c W29EE011' if you " "have a board with this chip.\n"); @@ -61,7 +61,7 @@ int probe_w29ee011(struct flashchip *flash) chip_writeb(0xF0, bios + 0x5555); programmer_delay(10); - printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); + print(MSG_DEBUG, "%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); if (id1 == flash->manufacture_id && id2 == flash->model_id) return 1; diff --git a/w39v040c.c b/w39v040c.c index 722ae29..3b67e2e 100644 --- a/w39v040c.c +++ b/w39v040c.c @@ -45,7 +45,7 @@ int probe_w39v040c(struct flashchip *flash) chip_writeb(0xF0, bios + 0x5555); programmer_delay(40); - printf("%s: Boot block #TBL is %slocked, rest of chip #WP is %slocked.\n", + print(MSG_NORMAL, "%s: Boot block #TBL is %slocked, rest of chip #WP is %slocked.\n", __func__, lock & 0x4 ? "" : "un", lock & 0x8 ? "" : "un"); return 1; } @@ -57,7 +57,7 @@ int erase_w39v040c(struct flashchip *flash) for (i = 0; i < total_size; i += flash->page_size) { if (erase_sector_jedec(flash, i, flash->page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } } @@ -73,18 +73,18 @@ int write_w39v040c(struct flashchip *flash, uint8_t *buf) chipaddr bios = flash->virtual_memory; if (erase_flash(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } - printf("Programming page: "); + print(MSG_NORMAL, "Programming page: "); for (i = 0; i < total_size / page_size; i++) { - printf("%04d at address: 0x%08x", i, i * page_size); + print(MSG_NORMAL, "%04d at address: 0x%08x", i, i * page_size); write_sector_jedec(bios, buf + i * page_size, bios + i * page_size, page_size); - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); } - printf("\n"); + print(MSG_NORMAL, "\n"); return 0; } diff --git a/w39v080fa.c b/w39v080fa.c index 580657f..4dd77fa 100644 --- a/w39v080fa.c +++ b/w39v080fa.c @@ -37,37 +37,37 @@ static int unlock_block_winbond_fwhub(struct flashchip *flash, int offset) chipaddr wrprotect = flash->virtual_registers + offset + 2; uint8_t locking; - printf_debug("Trying to unlock block @0x%08x = 0x%02x\n", offset, + print(MSG_DEBUG, "Trying to unlock block @0x%08x = 0x%02x\n", offset, chip_readb(wrprotect)); locking = chip_readb(wrprotect); switch (locking & 0x7) { case 0: - printf_debug("Full Access.\n"); + print(MSG_DEBUG, "Full Access.\n"); return 0; case 1: - printf_debug("Write Lock (Default State).\n"); + print(MSG_DEBUG, "Write Lock (Default State).\n"); chip_writeb(0, wrprotect); return 0; case 2: - printf_debug("Locked Open (Full Access, Lock Down).\n"); + print(MSG_DEBUG, "Locked Open (Full Access, Lock Down).\n"); return 0; case 3: - fprintf(stderr, "Error: Write Lock, Locked Down.\n"); + print(MSG_ERROR, "Error: Write Lock, Locked Down.\n"); return -1; case 4: - printf_debug("Read Lock.\n"); + print(MSG_DEBUG, "Read Lock.\n"); chip_writeb(0, wrprotect); return 0; case 5: - printf_debug("Read/Write Lock.\n"); + print(MSG_DEBUG, "Read/Write Lock.\n"); chip_writeb(0, wrprotect); return 0; case 6: - fprintf(stderr, "Error: Read Lock, Locked Down.\n"); + print(MSG_ERROR, "Error: Read Lock, Locked Down.\n"); return -1; case 7: - fprintf(stderr, "Error: Read/Write Lock, Locked Down.\n"); + print(MSG_ERROR, "Error: Read/Write Lock, Locked Down.\n"); return -1; } @@ -100,17 +100,17 @@ int unlock_winbond_fwhub(struct flashchip *flash) chip_writeb(0xF0, bios + 0x5555); programmer_delay(10); - printf_debug("Lockout bits:\n"); + print(MSG_DEBUG, "Lockout bits:\n"); if (locking & (1 << 2)) - fprintf(stderr, "Error: hardware bootblock locking (#TBL).\n"); + print(MSG_ERROR, "Error: hardware bootblock locking (#TBL).\n"); else - printf_debug("No hardware bootblock locking (good!)\n"); + print(MSG_DEBUG, "No hardware bootblock locking (good!)\n"); if (locking & (1 << 3)) - fprintf(stderr, "Error: hardware block locking (#WP).\n"); + print(MSG_ERROR, "Error: hardware block locking (#WP).\n"); else - printf_debug("No hardware block locking (good!)\n"); + print(MSG_DEBUG, "No hardware block locking (good!)\n"); if (locking & ((1 << 2) | (1 << 3))) return -1; @@ -129,7 +129,7 @@ static int erase_sector_winbond_fwhub(struct flashchip *flash, chipaddr bios = flash->virtual_memory; /* Remember: too much sleep can waste your day. */ - printf("0x%08x\b\b\b\b\b\b\b\b\b\b", sector); + print(MSG_NORMAL, "0x%08x\b\b\b\b\b\b\b\b\b\b", sector); /* Sector Erase */ chip_writeb(0xAA, bios + 0x5555); @@ -144,7 +144,7 @@ static int erase_sector_winbond_fwhub(struct flashchip *flash, toggle_ready_jedec(bios); if (check_erased_range(flash, sector, flash->page_size)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } return 0; @@ -156,16 +156,16 @@ int erase_winbond_fwhub(struct flashchip *flash) unlock_winbond_fwhub(flash); - printf("Erasing: "); + print(MSG_NORMAL, "Erasing: "); for (i = 0; i < total_size; i += flash->page_size) { if (erase_sector_winbond_fwhub(flash, i)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } } - printf("\n"); + print(MSG_NORMAL, "\n"); return 0; } @@ -179,12 +179,12 @@ int write_winbond_fwhub(struct flashchip *flash, uint8_t *buf) if (erase_winbond_fwhub(flash)) return -1; - printf("Programming: "); + print(MSG_NORMAL, "Programming: "); for (i = 0; i < total_size; i += flash->page_size) { - printf("0x%08x\b\b\b\b\b\b\b\b\b\b", i); + print(MSG_NORMAL, "0x%08x\b\b\b\b\b\b\b\b\b\b", i); write_sector_jedec(bios, buf + i, bios + i, flash->page_size); } - printf("\n"); + print(MSG_NORMAL, "\n"); return 0; } diff --git a/w49f002u.c b/w49f002u.c index d12bc72..4f78ba9 100644 --- a/w49f002u.c +++ b/w49f002u.c @@ -28,20 +28,20 @@ int write_49f002(struct flashchip *flash, uint8_t *buf) chipaddr bios = flash->virtual_memory; if (erase_chip_jedec(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + print(MSG_ERROR, "ERASE FAILED!\n"); return -1; } - printf("Programming page: "); + print(MSG_NORMAL, "Programming page: "); for (i = 0; i < total_size / page_size; i++) { - printf("%04d at address: 0x%08x ", i, i * page_size); + print(MSG_NORMAL, "%04d at address: 0x%08x ", i, i * page_size); /* Byte-wise writing of 'page_size' bytes. */ write_sector_jedec(bios, buf + i * page_size, bios + i * page_size, page_size); - printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + print(MSG_NORMAL, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } - printf("\n"); + print(MSG_NORMAL, "\n"); return 0; } diff --git a/wbsio_spi.c b/wbsio_spi.c index 6b9425f..6754fd8 100644 --- a/wbsio_spi.c +++ b/wbsio_spi.c @@ -34,18 +34,18 @@ static uint16_t wbsio_get_spibase(uint16_t port) w836xx_ext_enter(port); id = sio_read(port, 0x20); if (id != 0xa0) { - fprintf(stderr, "\nW83627 not found at 0x%x, id=0x%02x want=0xa0.\n", port, id); + print(MSG_ERROR, "\nW83627 not found at 0x%x, id=0x%02x want=0xa0.\n", port, id); goto done; } if (0 == (sio_read(port, 0x24) & 2)) { - fprintf(stderr, "\nW83627 found at 0x%x, but SPI pins are not enabled. (CR[0x24] bit 1=0)\n", port); + print(MSG_ERROR, "\nW83627 found at 0x%x, but SPI pins are not enabled. (CR[0x24] bit 1=0)\n", port); goto done; } sio_write(port, 0x07, 0x06); if (0 == (sio_read(port, 0x30) & 1)) { - fprintf(stderr, "\nW83627 found at 0x%x, but SPI is not enabled. (LDN6[0x30] bit 0=0)\n", port); + print(MSG_ERROR, "\nW83627 found at 0x%x, but SPI is not enabled. (LDN6[0x30] bit 0=0)\n", port); goto done; } @@ -62,7 +62,7 @@ int wbsio_check_for_spi(const char *name) if (0 == (wbsio_spibase = wbsio_get_spibase(WBSIO_PORT2))) return 1; - printf_debug("\nwbsio_spibase = 0x%x\n", wbsio_spibase); + print(MSG_DEBUG, "\nwbsio_spibase = 0x%x\n", wbsio_spibase); buses_supported |= CHIP_BUSTYPE_SPI; spi_controller = SPI_CONTROLLER_WBSIO; @@ -96,42 +96,42 @@ int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt, int i; uint8_t mode = 0; - printf_debug("%s:", __func__); + print(MSG_DEBUG, "%s:", __func__); if (1 == writecnt && 0 == readcnt) { mode = 0x10; } else if (2 == writecnt && 0 == readcnt) { OUTB(writearr[1], wbsio_spibase + 4); - printf_debug(" data=0x%02x", writearr[1]); + print(MSG_DEBUG, " data=0x%02x", writearr[1]); mode = 0x20; } else if (1 == writecnt && 2 == readcnt) { mode = 0x30; } else if (4 == writecnt && 0 == readcnt) { - printf_debug(" addr=0x%02x", (writearr[1] & 0x0f)); + print(MSG_DEBUG, " addr=0x%02x", (writearr[1] & 0x0f)); for (i = 2; i < writecnt; i++) { OUTB(writearr[i], wbsio_spibase + i); - printf_debug("%02x", writearr[i]); + print(MSG_DEBUG, "%02x", writearr[i]); } mode = 0x40 | (writearr[1] & 0x0f); } else if (5 == writecnt && 0 == readcnt) { - printf_debug(" addr=0x%02x", (writearr[1] & 0x0f)); + print(MSG_DEBUG, " addr=0x%02x", (writearr[1] & 0x0f)); for (i = 2; i < 4; i++) { OUTB(writearr[i], wbsio_spibase + i); - printf_debug("%02x", writearr[i]); + print(MSG_DEBUG, "%02x", writearr[i]); } OUTB(writearr[i], wbsio_spibase + i); - printf_debug(" data=0x%02x", writearr[i]); + print(MSG_DEBUG, " data=0x%02x", writearr[i]); mode = 0x50 | (writearr[1] & 0x0f); } else if (8 == writecnt && 0 == readcnt) { - printf_debug(" addr=0x%02x", (writearr[1] & 0x0f)); + print(MSG_DEBUG, " addr=0x%02x", (writearr[1] & 0x0f)); for (i = 2; i < 4; i++) { OUTB(writearr[i], wbsio_spibase + i); - printf_debug("%02x", writearr[i]); + print(MSG_DEBUG, "%02x", writearr[i]); } - printf_debug(" data=0x"); + print(MSG_DEBUG, " data=0x"); for (; i < writecnt; i++) { OUTB(writearr[i], wbsio_spibase + i); - printf_debug("%02x", writearr[i]); + print(MSG_DEBUG, "%02x", writearr[i]); } mode = 0x60 | (writearr[1] & 0x0f); } else if (5 == writecnt && 4 == readcnt) { @@ -142,17 +142,17 @@ int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt, */ ; } else if (4 == writecnt && readcnt >= 1 && readcnt <= 4) { - printf_debug(" addr=0x%02x", (writearr[1] & 0x0f)); + print(MSG_DEBUG, " addr=0x%02x", (writearr[1] & 0x0f)); for (i = 2; i < writecnt; i++) { OUTB(writearr[i], wbsio_spibase + i); - printf_debug("%02x", writearr[i]); + print(MSG_DEBUG, "%02x", writearr[i]); } mode = ((7 + readcnt) << 4) | (writearr[1] & 0x0f); } - printf_debug(" cmd=%02x mode=%02x\n", writearr[0], mode); + print(MSG_DEBUG, " cmd=%02x mode=%02x\n", writearr[0], mode); if (!mode) { - fprintf(stderr, "%s: unsupported command type wr=%d rd=%d\n", + print(MSG_ERROR, "%s: unsupported command type wr=%d rd=%d\n", __func__, writecnt, readcnt); /* Command type refers to the number of bytes read/written. */ return SPI_INVALID_LENGTH; @@ -165,12 +165,12 @@ int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt, if (!readcnt) return 0; - printf_debug("%s: returning data =", __func__); + print(MSG_DEBUG, "%s: returning data =", __func__); for (i = 0; i < readcnt; i++) { readarr[i] = INB(wbsio_spibase + 4 + i); - printf_debug(" 0x%02x", readarr[i]); + print(MSG_DEBUG, " 0x%02x", readarr[i]); } - printf_debug("\n"); + print(MSG_DEBUG, "\n"); return 0; } @@ -179,7 +179,7 @@ int wbsio_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len) int size = flash->total_size * 1024; if (size > 1024 * 1024) { - fprintf(stderr, "%s: Winbond saved on 4 register bits so max chip size is 1024 KB!\n", __func__); + print(MSG_ERROR, "%s: Winbond saved on 4 register bits so max chip size is 1024 KB!\n", __func__); return 1; } @@ -191,7 +191,7 @@ int wbsio_spi_write_1(struct flashchip *flash, uint8_t *buf) int size = flash->total_size * 1024; if (size > 1024 * 1024) { - fprintf(stderr, "%s: Winbond saved on 4 register bits so max chip size is 1024 KB!\n", __func__); + print(MSG_ERROR, "%s: Winbond saved on 4 register bits so max chip size is 1024 KB!\n", __func__); return 1; }