From 9b32de94f5104cb7fa12816b7fa561b804df6ed8 Mon Sep 17 00:00:00 2001 From: Stefan Tauner Date: Fri, 8 Aug 2014 23:52:33 +0000 Subject: Refactor some CLI-relevant parts Begin to move functions that clearly belong to the (command line) user interface out of flashrom's core files like flashrom.c. - Refine messages within check_chip_supported(), rename it to print_chip_support_status() and move it to newly created cli_common.c. - Move flashbuses_to_text() to cli_common.c as well. - Move global verbosity variables to cli_output.c. Corresponding to flashrom svn r1841. Signed-off-by: Stefan Tauner Acked-by: Carl-Daniel Hailfinger --- Makefile | 2 +- cli_classic.c | 2 +- cli_common.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ cli_output.c | 3 ++ flash.h | 9 +++-- flashrom.c | 70 ----------------------------------- print.c | 33 ----------------- programmer.h | 1 - 8 files changed, 128 insertions(+), 109 deletions(-) create mode 100644 cli_common.c diff --git a/Makefile b/Makefile index d0d64543b..98230a504 100644 --- a/Makefile +++ b/Makefile @@ -363,7 +363,7 @@ LIB_OBJS = layout.o flashrom.o udelay.o programmer.o helpers.o ############################################################################### # Frontend related stuff. -CLI_OBJS = cli_classic.o cli_output.o print.o +CLI_OBJS = cli_classic.o cli_output.o cli_common.o print.o # Set the flashrom version string from the highest revision number of the checked out flashrom files. # Note to packagers: Any tree exported with "make export" or "make tarball" diff --git a/cli_classic.c b/cli_classic.c index 60b8b886f..73ab57a4b 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -499,7 +499,7 @@ int main(int argc, char *argv[]) fill_flash = &flashes[0]; - check_chip_supported(fill_flash->chip); + print_chip_support_status(fill_flash->chip); size = fill_flash->chip->total_size * 1024; if (check_max_decode(fill_flash->mst->buses_supported & fill_flash->chip->bustype, size) && (!force)) { diff --git a/cli_common.c b/cli_common.c new file mode 100644 index 000000000..71cc2dd72 --- /dev/null +++ b/cli_common.c @@ -0,0 +1,117 @@ +/* + * This file is part of the flashrom project. + * + * Copyright (C) 2009 Uwe Hermann + * Copyright (C) 2009 Carl-Daniel Hailfinger + * Copyright (C) 2011-2014 Stefan Tauner + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include "flash.h" + +/* + * Return a string corresponding to the bustype parameter. + * Memory is obtained with malloc() and must be freed with free() by the caller. + */ +char *flashbuses_to_text(enum chipbustype bustype) +{ + char *ret = calloc(1, 1); + /* + * FIXME: Once all chipsets and flash chips have been updated, NONSPI + * will cease to exist and should be eliminated here as well. + */ + if (bustype == BUS_NONSPI) { + ret = strcat_realloc(ret, "Non-SPI, "); + } else { + if (bustype & BUS_PARALLEL) + ret = strcat_realloc(ret, "Parallel, "); + if (bustype & BUS_LPC) + ret = strcat_realloc(ret, "LPC, "); + if (bustype & BUS_FWH) + ret = strcat_realloc(ret, "FWH, "); + if (bustype & BUS_SPI) + ret = strcat_realloc(ret, "SPI, "); + if (bustype & BUS_PROG) + ret = strcat_realloc(ret, "Programmer-specific, "); + if (bustype == BUS_NONE) + ret = strcat_realloc(ret, "None, "); + } + /* Kill last comma. */ + ret[strlen(ret) - 2] = '\0'; + ret = realloc(ret, strlen(ret) + 1); + return ret; +} + + +void print_chip_support_status(const struct flashchip *chip) +{ + if (chip->feature_bits & FEATURE_OTP) { + msg_cdbg("This chip may contain one-time programmable memory. flashrom cannot read\n" + "and may never be able to write it, hence it may not be able to completely\n" + "clone the contents of this chip (see man page for details).\n"); + } + + if ((chip->tested.erase == NA) && (chip->tested.write == NA)) { + msg_cdbg("This chip's main memory can not be erased/written by design.\n"); + } + + if ((chip->tested.probe == BAD) || (chip->tested.probe == NT) || + (chip->tested.read == BAD) || (chip->tested.read == NT) || + (chip->tested.erase == BAD) || (chip->tested.erase == NT) || + (chip->tested.write == BAD) || (chip->tested.write == NT)){ + msg_cinfo("===\n"); + if ((chip->tested.probe == BAD) || + (chip->tested.read == BAD) || + (chip->tested.erase == BAD) || + (chip->tested.write == BAD)) { + msg_cinfo("This flash part has status NOT WORKING for operations:"); + if (chip->tested.probe == BAD) + msg_cinfo(" PROBE"); + if (chip->tested.read == BAD) + msg_cinfo(" READ"); + if (chip->tested.erase == BAD) + msg_cinfo(" ERASE"); + if (chip->tested.write == BAD) + msg_cinfo(" WRITE"); + msg_cinfo("\n"); + } + if ((chip->tested.probe == NT) || + (chip->tested.read == NT) || + (chip->tested.erase == NT) || + (chip->tested.write == NT)) { + msg_cinfo("This flash part has status UNTESTED for operations:"); + if (chip->tested.probe == NT) + msg_cinfo(" PROBE"); + if (chip->tested.read == NT) + msg_cinfo(" READ"); + if (chip->tested.erase == NT) + msg_cinfo(" ERASE"); + if (chip->tested.write == NT) + msg_cinfo(" WRITE"); + msg_cinfo("\n"); + } + msg_cinfo("The test status of this chip may have been updated in the latest development\n" + "version of flashrom. If you are running the latest development version,\n" + "please email a report to flashrom@flashrom.org if any of the above operations\n" + "work correctly for you with this flash chip. Please include the flashrom log\n" + "file for all operations you tested (see the man page for details), and mention\n" + "which mainboard or programmer you tested in the subject line.\n" + "Thanks for your help!\n"); + } +} + diff --git a/cli_output.c b/cli_output.c index 5eff1c056..feafbd201 100644 --- a/cli_output.c +++ b/cli_output.c @@ -25,6 +25,9 @@ #include #include "flash.h" +int verbose_screen = MSG_INFO; +int verbose_logfile = MSG_DEBUG2; + #ifndef STANDALONE static FILE *logfile = NULL; diff --git a/flash.h b/flash.h index 8271da9d1..301eb7adc 100644 --- a/flash.h +++ b/flash.h @@ -238,7 +238,6 @@ uint32_t chip_readl(const struct flashctx *flash, const chipaddr addr); void chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len); /* print.c */ -char *flashbuses_to_text(enum chipbustype bustype); int print_supported(void); void print_supported_wiki(void); @@ -251,8 +250,6 @@ char *strcat_realloc(char *dest, const char *src); void tolower_string(char *str); /* flashrom.c */ -extern int verbose_screen; -extern int verbose_logfile; extern const char flashrom_version[]; extern const char *chip_to_probe; void map_flash_registers(struct flashctx *flash); @@ -285,7 +282,13 @@ int write_buf_to_file(const unsigned char *buf, unsigned long size, const char * */ #define ERROR_FLASHROM_LIMIT -201 +/* cli_common.c */ +char *flashbuses_to_text(enum chipbustype bustype); +void print_chip_support_status(const struct flashchip *chip); + /* cli_output.c */ +extern int verbose_screen; +extern int verbose_logfile; #ifndef STANDALONE int open_logfile(const char * const filename); int close_logfile(void); diff --git a/flashrom.c b/flashrom.c index 3f29e6db9..eeed90b9a 100644 --- a/flashrom.c +++ b/flashrom.c @@ -42,11 +42,8 @@ const char flashrom_version[] = FLASHROM_VERSION; const char *chip_to_probe = NULL; -int verbose_screen = MSG_INFO; -int verbose_logfile = MSG_DEBUG2; static enum programmer programmer = PROGRAMMER_INVALID; - static const char *programmer_param = NULL; /* @@ -1783,73 +1780,6 @@ int selfcheck(void) return ret; } -void check_chip_supported(const struct flashchip *chip) -{ - if (chip->feature_bits & FEATURE_OTP) { - msg_cdbg("This chip may contain one-time programmable memory. " - "flashrom cannot read\nand may never be able to write " - "it, hence it may not be able to completely\n" - "clone the contents of this chip (see man page for " - "details).\n"); - } - - if ((chip->tested.erase == NA) && (chip->tested.write == NA)) { - msg_cdbg("This chip's main memory can not be erased/written by design.\n"); - } - - if ((chip->tested.probe == BAD) || (chip->tested.probe == NT) || - (chip->tested.read == BAD) || (chip->tested.read == NT) || - (chip->tested.erase == BAD) || (chip->tested.erase == NT) || - (chip->tested.write == BAD) || (chip->tested.write == NT)){ - msg_cinfo("===\n"); - if ((chip->tested.probe == BAD) || - (chip->tested.read == BAD) || - (chip->tested.erase == BAD) || - (chip->tested.write == BAD)) { - msg_cinfo("This flash part has status NOT WORKING for operations:"); - if (chip->tested.probe == BAD) - msg_cinfo(" PROBE"); - if (chip->tested.read == BAD) - msg_cinfo(" READ"); - if (chip->tested.erase == BAD) - msg_cinfo(" ERASE"); - if (chip->tested.write == BAD) - msg_cinfo(" WRITE"); - msg_cinfo("\n"); - } - if ((chip->tested.probe == NT) || - (chip->tested.read == NT) || - (chip->tested.erase == NT) || - (chip->tested.write == NT)) { - msg_cinfo("This flash part has status UNTESTED for operations:"); - if (chip->tested.probe == NT) - msg_cinfo(" PROBE"); - if (chip->tested.read == NT) - msg_cinfo(" READ"); - if (chip->tested.erase == NT) - msg_cinfo(" ERASE"); - if (chip->tested.write == NT) - msg_cinfo(" WRITE"); - msg_cinfo("\n"); - } - /* FIXME: This message is designed towards CLI users. */ - msg_cinfo("The test status of this chip may have been updated " - "in the latest development\n" - "version of flashrom. If you are running the latest " - "development version,\n" - "please email a report to flashrom@flashrom.org if " - "any of the above operations\n" - "work correctly for you with this flash part. Please " - "include the flashrom\n" - "output with the additional -V option for all " - "operations you tested (-V, -Vr,\n" - "-VE, -Vw), and mention which mainboard or " - "programmer you tested.\n" - "Please mention your board in the subject line. " - "Thanks for your help!\n"); - } -} - /* FIXME: This function signature needs to be improved once doit() has a better * function signature. */ diff --git a/print.c b/print.c index b1faea7a9..243aa49a4 100644 --- a/print.c +++ b/print.c @@ -59,39 +59,6 @@ static const char *test_state_to_text(enum test_state test_state) } } -/* - * Return a string corresponding to the bustype parameter. - * Memory is obtained with malloc() and must be freed with free() by the caller. - */ -char *flashbuses_to_text(enum chipbustype bustype) -{ - char *ret = calloc(1, 1); - /* - * FIXME: Once all chipsets and flash chips have been updated, NONSPI - * will cease to exist and should be eliminated here as well. - */ - if (bustype == BUS_NONSPI) { - ret = strcat_realloc(ret, "Non-SPI, "); - } else { - if (bustype & BUS_PARALLEL) - ret = strcat_realloc(ret, "Parallel, "); - if (bustype & BUS_LPC) - ret = strcat_realloc(ret, "LPC, "); - if (bustype & BUS_FWH) - ret = strcat_realloc(ret, "FWH, "); - if (bustype & BUS_SPI) - ret = strcat_realloc(ret, "SPI, "); - if (bustype & BUS_PROG) - ret = strcat_realloc(ret, "Programmer-specific, "); - if (bustype == BUS_NONE) - ret = strcat_realloc(ret, "None, "); - } - /* Kill last comma. */ - ret[strlen(ret) - 2] = '\0'; - ret = realloc(ret, strlen(ret) + 1); - return ret; -} - static int print_supported_chips(void) { const char *delim = "/"; diff --git a/programmer.h b/programmer.h index 3ad553aba..62acfeb5a 100644 --- a/programmer.h +++ b/programmer.h @@ -513,7 +513,6 @@ struct decode_sizes { extern struct decode_sizes max_rom_decode; extern int programmer_may_write; extern unsigned long flashbase; -void check_chip_supported(const struct flashchip *chip); int check_max_decode(enum chipbustype buses, uint32_t size); char *extract_programmer_param(const char *param_name); -- cgit v1.2.3