On Thu, 2009-04-16 at 22:16 -0700, Zach Welch wrote:
> Hi all,
> 
> I have attached two patches to help clean up OpenOCD's flash drivers.
> 
> The first patch changes most of the driver routines to static where
> possible, removing unused data and functions from the build with
> preprocessor #if 0 blocks.  While the patch is large, this should be
> fairly easy to review as the changes are all uniformly the same.

I accidentally included two additional files in my large patch.  My bad.
Only files inside src/flash should have been included.  I can resend a
new patch, but the following command can be used to generate one:

 filterdiff -x configure.in -x 'src/target/*' \
        < openocd-flash-static-keyword.patch \
        > openocd-flash-static-keyword-v2.patch

Incidentally, the configure.in change could be committed separately;
it's a one-liner that I meant to submit a long time ago.  The str91x
changes are for a project and indicate other refactoring requirements.

Finally, I have attached a third patch that gives two overlooked flash
drivers the same treatment as the others (at91sam7_old and ecos, the
later of which has dead code).

Cheers,

Zach
only in patch2:
unchanged:
--- src/flash/at91sam7_old.c	(revision 1461)
+++ src/flash/at91sam7_old.c	(working copy)
@@ -51,22 +51,22 @@
 #include <string.h>
 #include <unistd.h>
 
-int at91sam7_old_register_commands(struct command_context_s *cmd_ctx);
-int at91sam7_old_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
-int at91sam7_old_erase(struct flash_bank_s *bank, int first, int last);
-int at91sam7_old_protect(struct flash_bank_s *bank, int set, int first, int last);
-int at91sam7_old_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count);
-int at91sam7_old_probe(struct flash_bank_s *bank);
-int at91sam7_old_auto_probe(struct flash_bank_s *bank);
-int at91sam7_old_erase_check(struct flash_bank_s *bank);
-int at91sam7_old_protect_check(struct flash_bank_s *bank);
-int at91sam7_old_info(struct flash_bank_s *bank, char *buf, int buf_size);
+static int at91sam7_old_register_commands(struct command_context_s *cmd_ctx);
+static int at91sam7_old_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
+static int at91sam7_old_erase(struct flash_bank_s *bank, int first, int last);
+static int at91sam7_old_protect(struct flash_bank_s *bank, int set, int first, int last);
+static int at91sam7_old_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count);
+static int at91sam7_old_probe(struct flash_bank_s *bank);
+//static int at91sam7_old_auto_probe(struct flash_bank_s *bank);
+static int at91sam7_old_erase_check(struct flash_bank_s *bank);
+static int at91sam7_old_protect_check(struct flash_bank_s *bank);
+static int at91sam7_old_info(struct flash_bank_s *bank, char *buf, int buf_size);
 
-u32 at91sam7_old_get_flash_status(flash_bank_t *bank, u8 flashplane);
-void at91sam7_old_set_flash_mode(flash_bank_t *bank, u8 flashplane, int mode);
-u32 at91sam7_old_wait_status_busy(flash_bank_t *bank, u8 flashplane, u32 waitbits, int timeout);
-int at91sam7_old_flash_command(struct flash_bank_s *bank, u8 flashplane, u8 cmd, u16 pagen); 
-int at91sam7_old_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
+static u32 at91sam7_old_get_flash_status(flash_bank_t *bank, u8 flashplane);
+static void at91sam7_old_set_flash_mode(flash_bank_t *bank, u8 flashplane, int mode);
+static u32 at91sam7_old_wait_status_busy(flash_bank_t *bank, u8 flashplane, u32 waitbits, int timeout);
+static int at91sam7_old_flash_command(struct flash_bank_s *bank, u8 flashplane, u8 cmd, u16 pagen); 
+static int at91sam7_old_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 
 flash_driver_t at91sam7_old_flash =
 {
@@ -83,12 +83,12 @@
 	.info = at91sam7_old_info
 };
 
-u32 MC_FMR_old[4] =	{ 0xFFFFFF60, 0xFFFFFF70, 0xFFFFFF80, 0xFFFFFF90 };
-u32 MC_FCR_old[4] =	{ 0xFFFFFF64, 0xFFFFFF74, 0xFFFFFF84, 0xFFFFFF94 };
-u32 MC_FSR_old[4] =	{ 0xFFFFFF68, 0xFFFFFF78, 0xFFFFFF88, 0xFFFFFF98 };
+static u32 MC_FMR_old[4] =	{ 0xFFFFFF60, 0xFFFFFF70, 0xFFFFFF80, 0xFFFFFF90 };
+static u32 MC_FCR_old[4] =	{ 0xFFFFFF64, 0xFFFFFF74, 0xFFFFFF84, 0xFFFFFF94 };
+static u32 MC_FSR_old[4] =	{ 0xFFFFFF68, 0xFFFFFF78, 0xFFFFFF88, 0xFFFFFF98 };
 
-char * EPROC_old[8]= {"Unknown","ARM946-E","ARM7TDMI","Unknown","ARM920T","ARM926EJ-S","Unknown","Unknown"};
-long NVPSIZ_old[16] = {
+static char * EPROC_old[8]= {"Unknown","ARM946-E","ARM7TDMI","Unknown","ARM920T","ARM926EJ-S","Unknown","Unknown"};
+static long NVPSIZ_old[16] = {
    0,
    0x2000, /*  8K */
    0x4000, /* 16K */ 
@@ -107,7 +107,8 @@
    -1
 };
 
-long SRAMSIZ_old[16] = {
+#if 0
+static long SRAMSIZ_old[16] = {
    -1,
    0x0400, /*  1K */
    0x0800, /*  2K */ 
@@ -125,8 +126,9 @@
    0x18000, /* 96K */
    0x80000, /* 512K */
 };
+#endif
 
-int at91sam7_old_register_commands(struct command_context_s *cmd_ctx)
+static int at91sam7_old_register_commands(struct command_context_s *cmd_ctx)
 {
 	command_t *at91sam7_old_cmd = register_command(cmd_ctx, NULL, "at91sam7", NULL, COMMAND_ANY, NULL);
 	register_command(cmd_ctx, at91sam7_old_cmd, "gpnvm", at91sam7_old_handle_gpnvm_command, COMMAND_EXEC,
@@ -135,7 +137,7 @@
 	return ERROR_OK;
 }
 
-u32 at91sam7_old_get_flash_status(flash_bank_t *bank, u8 flashplane)
+static u32 at91sam7_old_get_flash_status(flash_bank_t *bank, u8 flashplane)
 {
 	target_t *target = bank->target;
 	u32 fsr;
@@ -146,7 +148,7 @@
 }
 
 /* Read clock configuration and set at91sam7_old_info->usec_clocks*/
-void at91sam7_old_read_clock_info(flash_bank_t *bank)
+static void at91sam7_old_read_clock_info(flash_bank_t *bank)
 {
 	at91sam7_old_flash_bank_t *at91sam7_old_info = bank->driver_priv;
 	target_t *target = bank->target;
@@ -210,7 +212,7 @@
 }
 
 /* Setup the timimg registers for nvbits or normal flash */
-void at91sam7_old_set_flash_mode(flash_bank_t *bank, u8 flashplane, int mode)
+static void at91sam7_old_set_flash_mode(flash_bank_t *bank, u8 flashplane, int mode)
 {
 	u32 fmr, fmcn = 0, fws = 0;
 	at91sam7_old_flash_bank_t *at91sam7_old_info = bank->driver_priv;
@@ -251,7 +253,7 @@
 	at91sam7_old_info->flashmode[flashplane] = mode;		
 }
 
-u32 at91sam7_old_wait_status_busy(flash_bank_t *bank, u8 flashplane, u32 waitbits, int timeout)
+static u32 at91sam7_old_wait_status_busy(flash_bank_t *bank, u8 flashplane, u32 waitbits, int timeout)
 {
 	u32 status;
 	
@@ -279,7 +281,7 @@
 
 
 /* Send one command to the AT91SAM flash controller */
-int at91sam7_old_flash_command(struct flash_bank_s *bank, u8 flashplane, u8 cmd, u16 pagen) 
+static int at91sam7_old_flash_command(struct flash_bank_s *bank, u8 flashplane, u8 cmd, u16 pagen) 
 {
 	u32 fcr;
 	at91sam7_old_flash_bank_t *at91sam7_old_info = bank->driver_priv;
@@ -307,7 +309,7 @@
 }
 
 /* Read device id register, main clock frequency register and fill in driver info structure */
-int at91sam7_old_read_part_info(struct flash_bank_s *bank)
+static int at91sam7_old_read_part_info(struct flash_bank_s *bank)
 {
 	at91sam7_old_flash_bank_t *at91sam7_old_info = bank->driver_priv;
 	target_t *target = bank->target;
@@ -574,7 +576,7 @@
 	return ERROR_OK;
 }
 
-int at91sam7_old_protect_check(struct flash_bank_s *bank)
+static int at91sam7_old_protect_check(struct flash_bank_s *bank)
 {
 	u32 status;
 	int flashplane;
@@ -625,7 +627,7 @@
 	return ERROR_OK;
 }
 
-int at91sam7_old_erase(struct flash_bank_s *bank, int first, int last)
+static int at91sam7_old_erase(struct flash_bank_s *bank, int first, int last)
 {
 	at91sam7_old_flash_bank_t *at91sam7_old_info = bank->driver_priv;
 	u8 flashplane;
@@ -716,7 +718,7 @@
 }
 
 
-int at91sam7_old_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
+static int at91sam7_old_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
 {
 	at91sam7_old_flash_bank_t *at91sam7_old_info = bank->driver_priv;
 	target_t *target = bank->target;
@@ -784,7 +786,7 @@
 }
 
 
-int at91sam7_old_probe(struct flash_bank_s *bank)
+static int at91sam7_old_probe(struct flash_bank_s *bank)
 {
 	/* we can't probe on an at91sam7_old
 	 * if this is an at91sam7_old, it has the configured flash
@@ -811,7 +813,7 @@
 }
 
 
-int at91sam7_old_info(struct flash_bank_s *bank, char *buf, int buf_size)
+static int at91sam7_old_info(struct flash_bank_s *bank, char *buf, int buf_size)
 {
 	int printed, flashplane;
 	at91sam7_old_flash_bank_t *at91sam7_old_info = bank->driver_priv;
@@ -871,7 +873,7 @@
 * 	The maximum number of write/erase cycles for Non Volatile Memory bits is 100. This includes
 *	Lock Bits (LOCKx), General Purpose NVM bits (GPNVMx) and the Security Bit.
 */
-int at91sam7_old_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+static int at91sam7_old_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
 	flash_bank_t *bank;
 	int bit;
only in patch2:
unchanged:
--- src/flash/ecos.c	(revision 1461)
+++ src/flash/ecos.c	(working copy)
@@ -36,19 +36,21 @@
 #include "../target/embeddedice.h"
 #include "types.h"
 
-int ecosflash_register_commands(struct command_context_s *cmd_ctx);
-int ecosflash_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
-int ecosflash_erase(struct flash_bank_s *bank, int first, int last);
-int ecosflash_protect(struct flash_bank_s *bank, int set, int first, int last);
-int ecosflash_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count);
-int ecosflash_probe(struct flash_bank_s *bank);
-int ecosflash_protect_check(struct flash_bank_s *bank);
-int ecosflash_info(struct flash_bank_s *bank, char *buf, int buf_size);
+static int ecosflash_register_commands(struct command_context_s *cmd_ctx);
+static int ecosflash_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
+static int ecosflash_erase(struct flash_bank_s *bank, int first, int last);
+static int ecosflash_protect(struct flash_bank_s *bank, int set, int first, int last);
+static int ecosflash_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count);
+static int ecosflash_probe(struct flash_bank_s *bank);
+static int ecosflash_protect_check(struct flash_bank_s *bank);
+static int ecosflash_info(struct flash_bank_s *bank, char *buf, int buf_size);
 
-u32 ecosflash_get_flash_status(flash_bank_t *bank);
-void ecosflash_set_flash_mode(flash_bank_t *bank,int mode);
-u32 ecosflash_wait_status_busy(flash_bank_t *bank, u32 waitbits, int timeout);
-int ecosflash_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
+#if 0
+static u32 ecosflash_get_flash_status(flash_bank_t *bank);
+static void ecosflash_set_flash_mode(flash_bank_t *bank,int mode);
+static u32 ecosflash_wait_status_busy(flash_bank_t *bank, u32 waitbits, int timeout);
+static int ecosflash_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
+#endif
 
 flash_driver_t ecosflash_flash =
 {
@@ -136,7 +138,7 @@
 
 /* flash bank ecosflash <base> <size> <chip_width> <bus_width> <target#> <driverPath>
  */
-int ecosflash_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
+static int ecosflash_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
 {
 	ecosflash_flash_bank_t *info;
 
@@ -181,7 +183,7 @@
 	return ERROR_OK;
 }
 
-int loadDriver(ecosflash_flash_bank_t *info)
+static int loadDriver(ecosflash_flash_bank_t *info)
 {
 	u32 buf_cnt;
 	u32 image_size;
@@ -230,7 +232,7 @@
 static int const OFFSET_GET_WORKAREA=0x18;
 static int const OFFSET_GET_WORKAREA_SIZE=0x4;
 
-int runCode(ecosflash_flash_bank_t *info,
+static int runCode(ecosflash_flash_bank_t *info,
 		u32 codeStart, u32 codeStop, u32 r0, u32 r1, u32 r2,
 		u32 *result,
 		/* timeout in ms */
@@ -271,7 +273,7 @@
 	return ERROR_OK;
 }
 
-int eCosBoard_erase(ecosflash_flash_bank_t *info, u32 address, u32 len)
+static int eCosBoard_erase(ecosflash_flash_bank_t *info, u32 address, u32 len)
 {
 	int retval;
 	int timeout = (len / 20480 + 1) * 1000; /*asume 20 KB/s*/
@@ -302,7 +304,7 @@
 	return ERROR_OK;
 }
 
-int eCosBoard_flash(ecosflash_flash_bank_t *info, void *data, u32 address, u32 len)
+static int eCosBoard_flash(ecosflash_flash_bank_t *info, void *data, u32 address, u32 len)
 {
 	target_t *target=info->target;
 	const int chunk=8192;
@@ -361,12 +363,12 @@
 	return ERROR_OK;
 }
 
-int ecosflash_probe(struct flash_bank_s *bank)
+static int ecosflash_probe(struct flash_bank_s *bank)
 {
 	return ERROR_OK;
 }
 
-int ecosflash_register_commands(struct command_context_s *cmd_ctx)
+static int ecosflash_register_commands(struct command_context_s *cmd_ctx)
 {
 	register_command(cmd_ctx, NULL, "ecosflash", NULL, COMMAND_ANY, NULL);
 
@@ -396,7 +398,8 @@
 }
 #endif
 
-u32 ecosflash_address(struct flash_bank_s *bank, u32 address)
+#if 0
+static u32 ecosflash_address(struct flash_bank_s *bank, u32 address)
 {
 	u32 retval = 0;
 	switch(bank->bus_width)
@@ -411,54 +414,57 @@
 
 	return retval + bank->base;
 }
+#endif
 
-int ecosflash_erase(struct flash_bank_s *bank, int first, int last)
+static int ecosflash_erase(struct flash_bank_s *bank, int first, int last)
 {
 	struct flash_bank_s *c=bank;
 	ecosflash_flash_bank_t *info = bank->driver_priv;
 	return eCosBoard_erase(info, c->base+first*sectorSize, sectorSize*(last-first+1));
 }
 
-int ecosflash_protect(struct flash_bank_s *bank, int set, int first, int last)
+static int ecosflash_protect(struct flash_bank_s *bank, int set, int first, int last)
 {
 	return ERROR_OK;
 }
 
-int ecosflash_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
+static int ecosflash_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
 {
 	ecosflash_flash_bank_t *info = bank->driver_priv;
 	struct flash_bank_s *c=bank;
 	return eCosBoard_flash(info, buffer, c->base+offset, count);
 }
 
-int ecosflash_protect_check(struct flash_bank_s *bank)
+static int ecosflash_protect_check(struct flash_bank_s *bank)
 {
 	return ERROR_OK;
 }
 
-int ecosflash_info(struct flash_bank_s *bank, char *buf, int buf_size)
+static int ecosflash_info(struct flash_bank_s *bank, char *buf, int buf_size)
 {
 	ecosflash_flash_bank_t *info = bank->driver_priv;
 	snprintf(buf, buf_size, "eCos flash driver: %s", info->driverPath);
 	return ERROR_OK;
 }
 
-u32 ecosflash_get_flash_status(flash_bank_t *bank)
+#if 0
+static u32 ecosflash_get_flash_status(flash_bank_t *bank)
 {
 	return ERROR_OK;
 }
 
-void ecosflash_set_flash_mode(flash_bank_t *bank,int mode)
+static void ecosflash_set_flash_mode(flash_bank_t *bank,int mode)
 {
 
 }
 
-u32 ecosflash_wait_status_busy(flash_bank_t *bank, u32 waitbits, int timeout)
+static u32 ecosflash_wait_status_busy(flash_bank_t *bank, u32 waitbits, int timeout)
 {
 	return ERROR_OK;
 }
 
-int ecosflash_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+static int ecosflash_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
 	return ERROR_OK;
 }
+#endif
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to