summaryrefslogtreecommitdiffstats
path: root/flashrom.c
diff options
context:
space:
mode:
authorCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2010-07-03 11:02:10 +0000
committerCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2010-07-03 11:02:10 +0000
commitad3cc55e139b2e239325815464fe5f7d828aa794 (patch)
tree46568cf766d19740418be5ca8eaa494c7e69cc36 /flashrom.c
parentb63b067ae22803689592db482611093b33a29eef (diff)
downloadast2050-flashrom-ad3cc55e139b2e239325815464fe5f7d828aa794.zip
ast2050-flashrom-ad3cc55e139b2e239325815464fe5f7d828aa794.tar.gz
Kill global variables, constants and functions if local scope suffices
Constify variables where possible. Initialize programmer-related variables explicitly in programmer_init to allow running programmer_init from a clean state after programmer_shutdown. Prohibit registering programmer shutdown functions before init or after shutdown. Kill some dead code. Rename global variables with namespace-polluting names. Use a previously unused locking helper function in sst49lfxxxc.c. This is needed for libflashrom. Effects on the binary size of flashrom are minimal (300 bytes shrinkage), but the data section shrinks by 4384 bytes, and that's a good thing if flashrom is operating in constrained envionments. Corresponding to flashrom svn r1068. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de>
Diffstat (limited to 'flashrom.c')
-rw-r--r--flashrom.c65
1 files changed, 44 insertions, 21 deletions
diff --git a/flashrom.c b/flashrom.c
index 0f51979..9f5ab57 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -34,7 +34,7 @@
#include "flash.h"
#include "flashchips.h"
-const char *flashrom_version = FLASHROM_VERSION;
+const char * const flashrom_version = FLASHROM_VERSION;
char *chip_to_probe = NULL;
int verbose = 0;
@@ -91,23 +91,17 @@ enum programmer programmer =
char *programmer_param = NULL;
-/**
- * flashrom defaults to Parallel/LPC/FWH flash devices. If a known host
- * controller is found, the init routine sets the buses_supported bitfield to
- * contain the supported buses for that controller.
- */
-enum chipbustype buses_supported = CHIP_BUSTYPE_NONSPI;
+/* Supported buses for the current programmer. */
+enum chipbustype buses_supported;
/**
* Programmers supporting multiple buses can have differing size limits on
* each bus. Store the limits for each bus in a common struct.
*/
-struct decode_sizes max_rom_decode = {
- .parallel = 0xffffffff,
- .lpc = 0xffffffff,
- .fwh = 0xffffffff,
- .spi = 0xffffffff
-};
+struct decode_sizes max_rom_decode;
+
+/* If nonzero, used as the start address of bottom-aligned flash. */
+unsigned long flashbase;
const struct programmer_entry programmer_table[] = {
#if CONFIG_INTERNAL == 1
@@ -402,7 +396,11 @@ static int shutdown_fn_count = 0;
struct shutdown_func_data {
void (*func) (void *data);
void *data;
-} shutdown_fn[SHUTDOWN_MAXFN];
+} static shutdown_fn[SHUTDOWN_MAXFN];
+/* Initialize to 0 to make sure nobody registers a shutdown function before
+ * programmer init.
+ */
+static int may_register_shutdown = 0;
/* Register a function to be executed on programmer shutdown.
* The advantage over atexit() is that you can supply a void pointer which will
@@ -419,6 +417,11 @@ int register_shutdown(void (*function) (void *data), void *data)
SHUTDOWN_MAXFN);
return 1;
}
+ if (!may_register_shutdown) {
+ msg_perr("Tried to register a shutdown function before "
+ "programmer init.\n");
+ return 1;
+ }
shutdown_fn[shutdown_fn_count].func = function;
shutdown_fn[shutdown_fn_count].data = data;
shutdown_fn_count++;
@@ -426,17 +429,39 @@ int register_shutdown(void (*function) (void *data), void *data)
return 0;
}
-int programmer_init(void)
+int programmer_init(char *param)
{
+ /* Initialize all programmer specific data. */
+ /* Default to unlimited decode sizes. */
+ max_rom_decode = (const struct decode_sizes) {
+ .parallel = 0xffffffff,
+ .lpc = 0xffffffff,
+ .fwh = 0xffffffff,
+ .spi = 0xffffffff
+ };
+ /* Default to Parallel/LPC/FWH flash devices. If a known host controller
+ * is found, the init routine sets the buses_supported bitfield.
+ */
+ buses_supported = CHIP_BUSTYPE_NONSPI;
+ /* Default to top aligned flash at 4 GB. */
+ flashbase = 0;
+ /* Registering shutdown functions is now allowed. */
+ may_register_shutdown = 1;
+
+ programmer_param = param;
+ msg_pdbg("Initializing %s programmer\n",
+ programmer_table[programmer].name);
return programmer_table[programmer].init();
}
int programmer_shutdown(void)
{
- int i;
-
- for (i = shutdown_fn_count - 1; i >= 0; i--)
+ /* Registering shutdown functions is no longer allowed. */
+ may_register_shutdown = 0;
+ while (shutdown_fn_count > 0) {
+ int i = --shutdown_fn_count;
shutdown_fn[i].func(shutdown_fn[i].data);
+ }
return programmer_table[programmer].shutdown();
}
@@ -512,8 +537,6 @@ int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len)
return 0;
}
-unsigned long flashbase = 0;
-
int min(int a, int b)
{
return (a < b) ? a : b;
@@ -1059,7 +1082,7 @@ int read_flash(struct flashchip *flash, char *filename)
/* This function shares a lot of its structure with erase_flash().
* Even if an error is found, the function will keep going and check the rest.
*/
-int selfcheck_eraseblocks(struct flashchip *flash)
+static int selfcheck_eraseblocks(struct flashchip *flash)
{
int i, j, k;
int ret = 0;
OpenPOWER on IntegriCloud