From 3a5ee0b1d6437da1b45e7475ef761cff2d296467 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 20 Oct 2010 01:06:48 -0400 Subject: cmd_mii: localize & constify local funcs/data No need for these structures to be writable or global. While we're here, also drop local versions of the ARRAY_SIZE macro. Signed-off-by: Mike Frysinger --- common/cmd_mii.c | 68 +++++++++++++++++++++++++------------------------------- 1 file changed, 30 insertions(+), 38 deletions(-) (limited to 'common') diff --git a/common/cmd_mii.c b/common/cmd_mii.c index 3ea493b..3fb0795 100644 --- a/common/cmd_mii.c +++ b/common/cmd_mii.c @@ -34,7 +34,7 @@ typedef struct _MII_reg_desc_t { char * name; } MII_reg_desc_t; -MII_reg_desc_t reg_0_5_desc_tbl[] = { +static const MII_reg_desc_t reg_0_5_desc_tbl[] = { { 0, "PHY control register" }, { 1, "PHY status register" }, { 2, "PHY ID 1 register" }, @@ -50,7 +50,7 @@ typedef struct _MII_field_desc_t { char * name; } MII_field_desc_t; -MII_field_desc_t reg_0_desc_tbl[] = { +static const MII_field_desc_t reg_0_desc_tbl[] = { { 15, 15, 0x01, "reset" }, { 14, 14, 0x01, "loopback" }, { 13, 6, 0x81, "speed selection" }, /* special */ @@ -63,7 +63,7 @@ MII_field_desc_t reg_0_desc_tbl[] = { { 5, 0, 0x3f, "(reserved)" } }; -MII_field_desc_t reg_1_desc_tbl[] = { +static const MII_field_desc_t reg_1_desc_tbl[] = { { 15, 15, 0x01, "100BASE-T4 able" }, { 14, 14, 0x01, "100BASE-X full duplex able" }, { 13, 13, 0x01, "100BASE-X half duplex able" }, @@ -82,17 +82,17 @@ MII_field_desc_t reg_1_desc_tbl[] = { { 0, 0, 0x01, "extended capabilities" }, }; -MII_field_desc_t reg_2_desc_tbl[] = { +static const MII_field_desc_t reg_2_desc_tbl[] = { { 15, 0, 0xffff, "OUI portion" }, }; -MII_field_desc_t reg_3_desc_tbl[] = { +static const MII_field_desc_t reg_3_desc_tbl[] = { { 15, 10, 0x3f, "OUI portion" }, { 9, 4, 0x3f, "manufacturer part number" }, { 3, 0, 0x0f, "manufacturer rev. number" }, }; -MII_field_desc_t reg_4_desc_tbl[] = { +static const MII_field_desc_t reg_4_desc_tbl[] = { { 15, 15, 0x01, "next page able" }, { 14, 14, 0x01, "reserved" }, { 13, 13, 0x01, "remote fault" }, @@ -107,7 +107,7 @@ MII_field_desc_t reg_4_desc_tbl[] = { { 4, 0, 0x1f, "xxx to do" }, }; -MII_field_desc_t reg_5_desc_tbl[] = { +static const MII_field_desc_t reg_5_desc_tbl[] = { { 15, 15, 0x01, "next page able" }, { 14, 14, 0x01, "acknowledge" }, { 13, 13, 0x01, "remote fault" }, @@ -121,39 +121,31 @@ MII_field_desc_t reg_5_desc_tbl[] = { { 5, 5, 0x01, "10BASE-T able" }, { 4, 0, 0x1f, "xxx to do" }, }; - -#define DESC0LEN (sizeof(reg_0_desc_tbl)/sizeof(reg_0_desc_tbl[0])) -#define DESC1LEN (sizeof(reg_1_desc_tbl)/sizeof(reg_1_desc_tbl[0])) -#define DESC2LEN (sizeof(reg_2_desc_tbl)/sizeof(reg_2_desc_tbl[0])) -#define DESC3LEN (sizeof(reg_3_desc_tbl)/sizeof(reg_3_desc_tbl[0])) -#define DESC4LEN (sizeof(reg_4_desc_tbl)/sizeof(reg_4_desc_tbl[0])) -#define DESC5LEN (sizeof(reg_5_desc_tbl)/sizeof(reg_5_desc_tbl[0])) - typedef struct _MII_field_desc_and_len_t { - MII_field_desc_t * pdesc; + const MII_field_desc_t *pdesc; ushort len; } MII_field_desc_and_len_t; -MII_field_desc_and_len_t desc_and_len_tbl[] = { - { reg_0_desc_tbl, DESC0LEN }, - { reg_1_desc_tbl, DESC1LEN }, - { reg_2_desc_tbl, DESC2LEN }, - { reg_3_desc_tbl, DESC3LEN }, - { reg_4_desc_tbl, DESC4LEN }, - { reg_5_desc_tbl, DESC5LEN }, +static const MII_field_desc_and_len_t desc_and_len_tbl[] = { + { reg_0_desc_tbl, ARRAY_SIZE(reg_0_desc_tbl) }, + { reg_1_desc_tbl, ARRAY_SIZE(reg_1_desc_tbl) }, + { reg_2_desc_tbl, ARRAY_SIZE(reg_2_desc_tbl) }, + { reg_3_desc_tbl, ARRAY_SIZE(reg_3_desc_tbl) }, + { reg_4_desc_tbl, ARRAY_SIZE(reg_4_desc_tbl) }, + { reg_5_desc_tbl, ARRAY_SIZE(reg_5_desc_tbl) }, }; static void dump_reg( ushort regval, - MII_reg_desc_t * prd, - MII_field_desc_and_len_t * pdl); + const MII_reg_desc_t *prd, + const MII_field_desc_and_len_t *pdl); static int special_field( ushort regno, - MII_field_desc_t * pdesc, + const MII_field_desc_t *pdesc, ushort regval); -void MII_dump_0_to_5( +static void MII_dump_0_to_5( ushort regvals[6], uchar reglo, uchar reghi) @@ -169,12 +161,12 @@ void MII_dump_0_to_5( static void dump_reg( ushort regval, - MII_reg_desc_t * prd, - MII_field_desc_and_len_t * pdl) + const MII_reg_desc_t *prd, + const MII_field_desc_and_len_t *pdl) { ulong i; ushort mask_in_place; - MII_field_desc_t * pdesc; + const MII_field_desc_t *pdesc; printf("%u. (%04hx) -- %s --\n", prd->regno, regval, prd->name); @@ -217,7 +209,7 @@ static void dump_reg( static int special_field( ushort regno, - MII_field_desc_t * pdesc, + const MII_field_desc_t *pdesc, ushort regval) { if ((regno == 0) && (pdesc->lo == 6)) { @@ -268,12 +260,12 @@ static int special_field( return 0; } -char last_op[2]; -uint last_data; -uint last_addr_lo; -uint last_addr_hi; -uint last_reg_lo; -uint last_reg_hi; +static char last_op[2]; +static uint last_data; +static uint last_addr_lo; +static uint last_addr_hi; +static uint last_reg_lo; +static uint last_reg_hi; static void extract_range( char * input, @@ -292,7 +284,7 @@ static void extract_range( } /* ---------------------------------------------------------------- */ -int do_mii (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) +static int do_mii(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { char op[2]; unsigned char addrlo, addrhi, reglo, reghi; -- cgit v1.1 From 36ebb78779cb08b48672e0fa5cd891199cc0ee23 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 20 Oct 2010 03:35:39 -0400 Subject: do_bootm: unify duplicate prototypes The duplication of the do_bootm prototype has gotten out of hand, and they're pretty much all outdated (wrt constness). Unify them all in command.h. Signed-off-by: Mike Frysinger --- common/cmd_fdc.c | 1 - common/cmd_fdos.c | 1 - common/cmd_ide.c | 1 - common/cmd_nand.c | 1 - common/cmd_net.c | 2 -- common/cmd_scsi.c | 1 - common/cmd_usb.c | 1 - 7 files changed, 8 deletions(-) (limited to 'common') diff --git a/common/cmd_fdc.c b/common/cmd_fdc.c index 831a07f..cdb050c 100644 --- a/common/cmd_fdc.c +++ b/common/cmd_fdc.c @@ -826,7 +826,6 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { char *local_args[2]; - extern int do_bootm (cmd_tbl_t *, int, int, char *[]); local_args[0] = argv[0]; local_args[1] = NULL; diff --git a/common/cmd_fdos.c b/common/cmd_fdos.c index a8822d9..2af4ca0 100644 --- a/common/cmd_fdos.c +++ b/common/cmd_fdos.c @@ -101,7 +101,6 @@ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { char *local_args[2]; - extern int do_bootm (cmd_tbl_t *, int, int, char *[]); local_args[0] = argv[0]; local_args[1] = NULL; printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr); diff --git a/common/cmd_ide.c b/common/cmd_ide.c index ea0f4a7..df7bdf5 100644 --- a/common/cmd_ide.c +++ b/common/cmd_ide.c @@ -498,7 +498,6 @@ int do_diskboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { char *local_args[2]; - extern int do_bootm (cmd_tbl_t *, int, int, char *[]); local_args[0] = argv[0]; local_args[1] = NULL; diff --git a/common/cmd_nand.c b/common/cmd_nand.c index 634d036..6783645 100644 --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -789,7 +789,6 @@ static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand, /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep, "yes") == 0)) { char *local_args[2]; - extern int do_bootm(cmd_tbl_t *, int, int, char *[]); local_args[0] = cmd; local_args[1] = NULL; diff --git a/common/cmd_net.c b/common/cmd_net.c index 44d17db..c657b03 100644 --- a/common/cmd_net.c +++ b/common/cmd_net.c @@ -28,8 +28,6 @@ #include #include -extern int do_bootm (cmd_tbl_t *, int, int, char * const []); - static int netboot_common (proto_t, cmd_tbl_t *, int , char * const []); int do_bootp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) diff --git a/common/cmd_scsi.c b/common/cmd_scsi.c index 6b937f9..be4fe74 100644 --- a/common/cmd_scsi.c +++ b/common/cmd_scsi.c @@ -329,7 +329,6 @@ int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { char *local_args[2]; - extern int do_bootm (cmd_tbl_t *, int, int, char *[]); local_args[0] = argv[0]; local_args[1] = NULL; printf ("Automatic boot of image at addr 0x%08lX ...\n", addr); diff --git a/common/cmd_usb.c b/common/cmd_usb.c index 226ea0d..b04a8df 100644 --- a/common/cmd_usb.c +++ b/common/cmd_usb.c @@ -490,7 +490,6 @@ int do_usbboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep, "yes") == 0)) { char *local_args[2]; - extern int do_bootm(cmd_tbl_t *, int, int, char *[]); local_args[0] = argv[0]; local_args[1] = NULL; printf("Automatic boot of image at addr 0x%08lX ...\n", addr); -- cgit v1.1 From 7842fb7c4f5be961c7aa9091dc8c760683b1377c Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 20 Oct 2010 03:36:26 -0400 Subject: do_bootd: unify duplicate prototypes Signed-off-by: Mike Frysinger --- common/hush.c | 4 ---- common/main.c | 2 -- 2 files changed, 6 deletions(-) (limited to 'common') diff --git a/common/hush.c b/common/hush.c index 2188fd4..0f101bf 100644 --- a/common/hush.c +++ b/common/hush.c @@ -93,8 +93,6 @@ #include /* readline */ #include #include /* find_cmd */ -/*cmd_boot.c*/ -extern int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); /* do_bootd */ #endif #ifndef __U_BOOT__ #include /* isalpha, isdigit */ @@ -1681,8 +1679,6 @@ static int run_pipe_real(struct pipe *pi) } else { int rcode; #if defined(CONFIG_CMD_BOOTD) - extern int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); - /* avoid "bootd" recursion */ if (cmdtp->cmd == do_bootd) { if (flag & CMD_FLAG_BOOTD) { diff --git a/common/main.c b/common/main.c index d97ccd7..bbb208b 100644 --- a/common/main.c +++ b/common/main.c @@ -54,8 +54,6 @@ void show_boot_progress (int val) __attribute__((weak, alias("__show_boot_progre extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); /* for do_reset() prototype */ #endif -extern int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); - #if defined(CONFIG_UPDATE_TFTP) void update_tftp (void); #endif /* CONFIG_UPDATE_TFTP */ -- cgit v1.1 From 882b7d726febe65579d6502c271412ecb05821d7 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 20 Oct 2010 03:41:17 -0400 Subject: do_reset: unify duplicate prototypes The duplication of the do_reset prototype has gotten out of hand, and they're not all in sync. Unify them all in command.h. Signed-off-by: Mike Frysinger --- common/cmd_boot.c | 2 -- common/cmd_bootm.c | 1 - common/hush.c | 4 +--- common/main.c | 4 ---- 4 files changed, 1 insertion(+), 10 deletions(-) (limited to 'common') diff --git a/common/cmd_boot.c b/common/cmd_boot.c index 72dacaa..7b603d3 100644 --- a/common/cmd_boot.c +++ b/common/cmd_boot.c @@ -67,8 +67,6 @@ U_BOOT_CMD( " passing 'arg' as arguments" ); -extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); - U_BOOT_CMD( reset, 1, 0, do_reset, "Perform RESET of the CPU", diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 1a024f1..9873ee7 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -93,7 +93,6 @@ static int fit_check_kernel (const void *fit, int os_noffset, int verify); static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char * const argv[], bootm_headers_t *images, ulong *os_data, ulong *os_len); -extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); /* * Continue booting an OS image; caller already has: diff --git a/common/hush.c b/common/hush.c index 0f101bf..8021a68 100644 --- a/common/hush.c +++ b/common/hush.c @@ -1021,9 +1021,7 @@ static void get_user_input(struct in_str *i) static char the_command[CONFIG_SYS_CBSIZE]; #ifdef CONFIG_BOOT_RETRY_TIME -# ifdef CONFIG_RESET_TO_RETRY - extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); -# else +# ifndef CONFIG_RESET_TO_RETRY # error "This currently only works with CONFIG_RESET_TO_RETRY enabled" # endif reset_cmd_timeout(); diff --git a/common/main.c b/common/main.c index bbb208b..878cffd 100644 --- a/common/main.c +++ b/common/main.c @@ -50,10 +50,6 @@ DECLARE_GLOBAL_DATA_PTR; void inline __show_boot_progress (int val) {} void show_boot_progress (int val) __attribute__((weak, alias("__show_boot_progress"))); -#if defined(CONFIG_BOOT_RETRY_TIME) && defined(CONFIG_RESET_TO_RETRY) -extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); /* for do_reset() prototype */ -#endif - #if defined(CONFIG_UPDATE_TFTP) void update_tftp (void); #endif /* CONFIG_UPDATE_TFTP */ -- cgit v1.1 From 722b061b6f6f3405118f2969272511e7e19990e3 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 20 Oct 2010 03:52:39 -0400 Subject: autocomplete: remove runtime handler install Rather than add runtime overhead of installing completion handlers, do it statically at build time. This requires a new build time helper macro to declare a command and the completion handler at the same time. Then we convert the env related funcs over to this. This gives an opportunity to also unify the U_BOOT_CMD macros. Signed-off-by: Mike Frysinger --- common/cmd_nvedit.c | 20 ++++++++++++-------- common/command.c | 24 ------------------------ common/main.c | 4 ---- 3 files changed, 12 insertions(+), 36 deletions(-) (limited to 'common') diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index dcc93c1..c3b57f2 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -883,29 +883,32 @@ U_BOOT_CMD( */ #if defined(CONFIG_CMD_EDITENV) -U_BOOT_CMD( +U_BOOT_CMD_COMPLETE( editenv, 2, 0, do_env_edit, "edit environment variable", "name\n" - " - edit environment variable 'name'" + " - edit environment variable 'name'", + var_complete ); #endif -U_BOOT_CMD( +U_BOOT_CMD_COMPLETE( printenv, CONFIG_SYS_MAXARGS, 1, do_env_print, "print environment variables", "\n - print values of all environment variables\n" "printenv name ...\n" - " - print value of environment variable 'name'" + " - print value of environment variable 'name'", + var_complete ); -U_BOOT_CMD( +U_BOOT_CMD_COMPLETE( setenv, CONFIG_SYS_MAXARGS, 0, do_env_set, "set environment variables", "name value ...\n" " - set environment variable 'name' to 'value ...'\n" "setenv name\n" - " - delete environment variable 'name'" + " - delete environment variable 'name'", + var_complete ); #if defined(CONFIG_CMD_ASKENV) @@ -926,10 +929,11 @@ U_BOOT_CMD( #endif #if defined(CONFIG_CMD_RUN) -U_BOOT_CMD( +U_BOOT_CMD_COMPLETE( run, CONFIG_SYS_MAXARGS, 1, do_run, "run commands in an environment variable", "var [...]\n" - " - run the commands in the environment variable(s) 'var'" + " - run the commands in the environment variable(s) 'var'", + var_complete ); #endif diff --git a/common/command.c b/common/command.c index 0b1a3fb..ef4a081 100644 --- a/common/command.c +++ b/common/command.c @@ -177,30 +177,6 @@ int var_complete(int argc, char * const argv[], char last_char, int maxv, char * return 0; } -static void install_auto_complete_handler(const char *cmd, - int (*complete)(int argc, char * const argv[], char last_char, int maxv, char *cmdv[])) -{ - cmd_tbl_t *cmdtp; - - cmdtp = find_cmd(cmd); - if (cmdtp == NULL) - return; - - cmdtp->complete = complete; -} - -void install_auto_complete(void) -{ -#if defined(CONFIG_CMD_EDITENV) - install_auto_complete_handler("editenv", var_complete); -#endif - install_auto_complete_handler("printenv", var_complete); - install_auto_complete_handler("setenv", var_complete); -#if defined(CONFIG_CMD_RUN) - install_auto_complete_handler("run", var_complete); -#endif -} - /*************************************************************************************/ static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]) diff --git a/common/main.c b/common/main.c index 878cffd..42f4d02 100644 --- a/common/main.c +++ b/common/main.c @@ -336,10 +336,6 @@ void main_loop (void) hush_init_var (); #endif -#ifdef CONFIG_AUTO_COMPLETE - install_auto_complete(); -#endif - #ifdef CONFIG_PREBOOT if ((p = getenv ("preboot")) != NULL) { # ifdef CONFIG_AUTOBOOT_KEYED -- cgit v1.1 From bdbc1303cb6a3ddbbf7a4f6a546f8aa85775a13e Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 20 Oct 2010 07:17:23 -0400 Subject: cmd_date: constify Many strings in this file need not be writable. Signed-off-by: Mike Frysinger --- common/cmd_date.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/cmd_date.c b/common/cmd_date.c index 8dbf16d..f0fa02a 100644 --- a/common/cmd_date.c +++ b/common/cmd_date.c @@ -31,7 +31,7 @@ DECLARE_GLOBAL_DATA_PTR; -const char *weekdays[] = { +static const char * const weekdays[] = { "Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur", }; @@ -41,7 +41,7 @@ const char *weekdays[] = { #define RELOC(a) a #endif -int mk_date (char *, struct rtc_time *); +int mk_date (const char *, struct rtc_time *); int do_date (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -106,7 +106,7 @@ int do_date (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) /* * simple conversion of two-digit string with error checking */ -static int cnvrt2 (char *str, int *valp) +static int cnvrt2 (const char *str, int *valp) { int val; @@ -131,7 +131,7 @@ static int cnvrt2 (char *str, int *valp) * Some basic checking for valid values is done, but this will not catch * all possible error conditions. */ -int mk_date (char *datestr, struct rtc_time *tmp) +int mk_date (const char *datestr, struct rtc_time *tmp) { int len, val; char *ptr; -- cgit v1.1 From fc9903f38d53024e28261eb14230bf6fc02d879e Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 20 Oct 2010 07:17:33 -0400 Subject: cmd_itest: constify & localize op table No one else needs this table. While we're here, use the standard ARRAY_SIZE helper macro. Signed-off-by: Mike Frysinger --- common/cmd_itest.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'common') diff --git a/common/cmd_itest.c b/common/cmd_itest.c index 8dd8927..fa6a0c3 100644 --- a/common/cmd_itest.c +++ b/common/cmd_itest.c @@ -46,7 +46,7 @@ struct op_tbl_s { typedef struct op_tbl_s op_tbl_t; -op_tbl_t op_table [] = { +static const op_tbl_t op_table [] = { { "-lt", LT }, { "<" , LT }, { "-gt", GT }, @@ -62,8 +62,6 @@ op_tbl_t op_table [] = { { "<=" , LE }, }; -#define op_tbl_size (sizeof(op_table)/sizeof(op_table[0])) - static long evalexp(char *s, int w) { long l = 0; @@ -138,12 +136,12 @@ static int arithcomp (char *s, char *t, int op, int w) int binary_test (char *op, char *arg1, char *arg2, int w) { int len, i; - op_tbl_t *optp; + const op_tbl_t *optp; len = strlen(op); for (optp = (op_tbl_t *)&op_table, i = 0; - i < op_tbl_size; + i < ARRAY_SIZE(op_table); optp++, i++) { if ((strncmp (op, optp->op, len) == 0) && (len == strlen (optp->op))) { -- cgit v1.1 From 7edb186fcf96bd52aadf0529aa135bb393732060 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 20 Oct 2010 07:17:39 -0400 Subject: image: constify lookup tables These are pure lookup tables -- no need to be writable. Signed-off-by: Mike Frysinger --- common/image.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'common') diff --git a/common/image.c b/common/image.c index 42f5b79..f63a2ff 100644 --- a/common/image.c +++ b/common/image.c @@ -74,7 +74,7 @@ static const image_header_t* image_get_ramdisk (ulong rd_addr, uint8_t arch, #include #endif /* !USE_HOSTCC*/ -static table_entry_t uimage_arch[] = { +static const table_entry_t uimage_arch[] = { { IH_ARCH_INVALID, NULL, "Invalid ARCH", }, { IH_ARCH_ALPHA, "alpha", "Alpha", }, { IH_ARCH_ARM, "arm", "ARM", }, @@ -96,7 +96,7 @@ static table_entry_t uimage_arch[] = { { -1, "", "", }, }; -static table_entry_t uimage_os[] = { +static const table_entry_t uimage_os[] = { { IH_OS_INVALID, NULL, "Invalid OS", }, { IH_OS_LINUX, "linux", "Linux", }, #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC) @@ -129,7 +129,7 @@ static table_entry_t uimage_os[] = { { -1, "", "", }, }; -static table_entry_t uimage_type[] = { +static const table_entry_t uimage_type[] = { { IH_TYPE_INVALID, NULL, "Invalid Image", }, { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", }, { IH_TYPE_FIRMWARE, "firmware", "Firmware", }, @@ -144,7 +144,7 @@ static table_entry_t uimage_type[] = { { -1, "", "", }, }; -static table_entry_t uimage_comp[] = { +static const table_entry_t uimage_comp[] = { { IH_COMP_NONE, "none", "uncompressed", }, { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", }, { IH_COMP_GZIP, "gzip", "gzip compressed", }, @@ -516,7 +516,7 @@ static void genimg_print_time (time_t timestamp) * long entry name if translation succeeds * msg otherwise */ -char *get_table_entry_name (table_entry_t *table, char *msg, int id) +char *get_table_entry_name(const table_entry_t *table, char *msg, int id) { for (; table->id >= 0; ++table) { if (table->id == id) @@ -563,10 +563,10 @@ const char *genimg_get_comp_name (uint8_t comp) * entry id if translation succeeds * -1 otherwise */ -int get_table_entry_id (table_entry_t *table, +int get_table_entry_id(const table_entry_t *table, const char *table_name, const char *name) { - table_entry_t *t; + const table_entry_t *t; #ifdef USE_HOSTCC int first = 1; -- cgit v1.1 From 5a442c0addc69d0c4b58e98e5aec1cf07576debb Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 20 Oct 2010 07:17:55 -0400 Subject: boot cmds: convert to getenv_yesno() with autostart Use the new helper func to clean up duplicate logic handling of the autostart env var. Signed-off-by: Mike Frysinger --- common/cmd_fdc.c | 3 +-- common/cmd_fdos.c | 2 +- common/cmd_ide.c | 2 +- common/cmd_nand.c | 4 ++-- common/cmd_net.c | 2 +- common/cmd_scsi.c | 2 +- common/cmd_usb.c | 2 +- 7 files changed, 8 insertions(+), 9 deletions(-) (limited to 'common') diff --git a/common/cmd_fdc.c b/common/cmd_fdc.c index cdb050c..d373480 100644 --- a/common/cmd_fdc.c +++ b/common/cmd_fdc.c @@ -721,7 +721,6 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) image_header_t *hdr; /* used for fdc boot */ unsigned char boot_drive; int i,nrofblk; - char *ep; int rcode = 0; #if defined(CONFIG_FIT) const void *fit_hdr = NULL; @@ -824,7 +823,7 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) load_addr = addr; /* Check if we should attempt an auto-start */ - if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { + if (getenv_yesno("autostart")) { char *local_args[2]; local_args[0] = argv[0]; diff --git a/common/cmd_fdos.c b/common/cmd_fdos.c index 2af4ca0..238abdd 100644 --- a/common/cmd_fdos.c +++ b/common/cmd_fdos.c @@ -99,7 +99,7 @@ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) size, load_addr); /* Check if we should attempt an auto-start */ - if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { + if (getenv_yesno("autostart")) { char *local_args[2]; local_args[0] = argv[0]; local_args[1] = NULL; diff --git a/common/cmd_ide.c b/common/cmd_ide.c index df7bdf5..f627881 100644 --- a/common/cmd_ide.c +++ b/common/cmd_ide.c @@ -496,7 +496,7 @@ int do_diskboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) load_addr = addr; /* Check if we should attempt an auto-start */ - if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { + if (getenv_yesno("autostart")) { char *local_args[2]; local_args[0] = argv[0]; diff --git a/common/cmd_nand.c b/common/cmd_nand.c index 6783645..c547a68 100644 --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -711,7 +711,7 @@ static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand, ulong offset, ulong addr, char *cmd) { int r; - char *ep, *s; + char *s; size_t cnt; image_header_t *hdr; #if defined(CONFIG_FIT) @@ -787,7 +787,7 @@ static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand, load_addr = addr; /* Check if we should attempt an auto-start */ - if (((ep = getenv("autostart")) != NULL) && (strcmp(ep, "yes") == 0)) { + if (getenv_yesno("autostart")) { char *local_args[2]; local_args[0] = cmd; diff --git a/common/cmd_net.c b/common/cmd_net.c index c657b03..973fa21 100644 --- a/common/cmd_net.c +++ b/common/cmd_net.c @@ -211,7 +211,7 @@ netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char * const argv[]) flush_cache(load_addr, size); /* Loading ok, check if we should attempt an auto-start */ - if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) { + if (getenv_yesno("autostart")) { char *local_args[2]; local_args[0] = argv[0]; local_args[1] = NULL; diff --git a/common/cmd_scsi.c b/common/cmd_scsi.c index be4fe74..63a46de 100644 --- a/common/cmd_scsi.c +++ b/common/cmd_scsi.c @@ -327,7 +327,7 @@ int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) flush_cache (addr, (cnt+1)*info.blksz); /* Check if we should attempt an auto-start */ - if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { + if (getenv_yesno("autostart")) { char *local_args[2]; local_args[0] = argv[0]; local_args[1] = NULL; diff --git a/common/cmd_usb.c b/common/cmd_usb.c index b04a8df..8439198 100644 --- a/common/cmd_usb.c +++ b/common/cmd_usb.c @@ -488,7 +488,7 @@ int do_usbboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) flush_cache(addr, (cnt+1)*info.blksz); /* Check if we should attempt an auto-start */ - if (((ep = getenv("autostart")) != NULL) && (strcmp(ep, "yes") == 0)) { + if (getenv_yesno("autostart")) { char *local_args[2]; local_args[0] = argv[0]; local_args[1] = NULL; -- cgit v1.1 From d7be3056def73c0ab53b3907f9a70a73253a5ae9 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 20 Oct 2010 07:18:03 -0400 Subject: stdio: constify "name" arg in public api Signed-off-by: Mike Frysinger --- common/console.c | 4 ++-- common/stdio.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/console.c b/common/console.c index 7e01886..8c650e0 100644 --- a/common/console.c +++ b/common/console.c @@ -479,7 +479,7 @@ inline void dbg(const char *fmt, ...) /** U-Boot INIT FUNCTIONS *************************************************/ -struct stdio_dev *search_device(int flags, char *name) +struct stdio_dev *search_device(int flags, const char *name) { struct stdio_dev *dev; @@ -491,7 +491,7 @@ struct stdio_dev *search_device(int flags, char *name) return NULL; } -int console_assign(int file, char *devname) +int console_assign(int file, const char *devname) { int flag; struct stdio_dev *dev; diff --git a/common/stdio.c b/common/stdio.c index ab7c5ab..b20772c 100644 --- a/common/stdio.c +++ b/common/stdio.c @@ -105,7 +105,7 @@ struct list_head* stdio_get_list(void) return &(devs.list); } -struct stdio_dev* stdio_get_by_name(char* name) +struct stdio_dev* stdio_get_by_name(const char *name) { struct list_head *pos; struct stdio_dev *dev; @@ -155,7 +155,7 @@ int stdio_register (struct stdio_dev * dev) * returns 0 if success, -1 if device is assigned and 1 if devname not found */ #ifdef CONFIG_SYS_STDIO_DEREGISTER -int stdio_deregister(char *devname) +int stdio_deregister(const char *devname) { int l; struct list_head *pos; -- cgit v1.1 From 2eb1573f01710832bbe60a4ece89cb301727612a Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 8 Dec 2010 06:26:04 -0500 Subject: hashtable: drop all non-reentrant versions The non-reentrant versions of the hashtable functions operate on a single shared hashtable. So if two different people try using these funcs for two different purposes, they'll cause problems for the other. Avoid this by converting all existing hashtable consumers over to the reentrant versions and then punting the non-reentrant ones. Signed-off-by: Mike Frysinger --- common/cmd_nvedit.c | 18 +++++++++--------- common/env_common.c | 6 ++++-- common/env_dataflash.c | 2 +- common/env_eeprom.c | 2 +- common/env_flash.c | 4 ++-- common/env_mmc.c | 2 +- common/env_nand.c | 4 ++-- common/env_nvram.c | 2 +- common/env_onenand.c | 2 +- common/env_sf.c | 4 ++-- 10 files changed, 24 insertions(+), 22 deletions(-) (limited to 'common') diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index c3b57f2..f8c7976 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -111,7 +111,7 @@ static int env_print(char *name) e.key = name; e.data = NULL; - ep = hsearch (e, FIND); + hsearch_r(e, FIND, &ep, &env_htab); if (ep == NULL) return 0; len = printf ("%s=%s\n", ep->key, ep->data); @@ -119,7 +119,7 @@ static int env_print(char *name) } /* print whole list */ - len = hexport('\n', &res, 0); + len = hexport_r(&env_htab, '\n', &res, 0); if (len > 0) { puts(res); @@ -184,7 +184,7 @@ int _do_env_set (int flag, int argc, char * const argv[]) */ e.key = name; e.data = NULL; - ep = hsearch (e, FIND); + hsearch_r(e, FIND, &ep, &env_htab); /* Check for console redirection */ if (strcmp(name,"stdin") == 0) { @@ -267,7 +267,7 @@ int _do_env_set (int flag, int argc, char * const argv[]) /* Delete only ? */ if ((argc < 3) || argv[2] == NULL) { - int rc = hdelete(name); + int rc = hdelete_r(name, &env_htab); return !rc; } @@ -293,7 +293,7 @@ int _do_env_set (int flag, int argc, char * const argv[]) e.key = name; e.data = value; - ep = hsearch(e, ENTER); + hsearch_r(e, ENTER, &ep, &env_htab); free(value); if (!ep) { printf("## Error inserting \"%s\" variable, errno=%d\n", @@ -456,7 +456,7 @@ char *getenv (char *name) e.key = name; e.data = NULL; - ep = hsearch (e, FIND); + hsearch_r(e, FIND, &ep, &env_htab); return (ep ? ep->data : NULL); } @@ -651,7 +651,7 @@ static int do_env_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv } if (sep) { /* export as text file */ - len = hexport(sep, &addr, size); + len = hexport_r(&env_htab, sep, &addr, size); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); @@ -670,7 +670,7 @@ static int do_env_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv else /* export as raw binary data */ res = addr; - len = hexport('\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); @@ -790,7 +790,7 @@ static int do_env_import(cmd_tbl_t * cmdtp, int flag, int argc, char * const arg addr = (char *)ep->data; } - if (himport(addr, size, sep, del ? 0 : H_NOCLEAR) == 0) { + if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR) == 0) { error("Environment import failed: errno = %d\n", errno); return 1; } diff --git a/common/env_common.c b/common/env_common.c index a276efc..ae710e5 100644 --- a/common/env_common.c +++ b/common/env_common.c @@ -129,6 +129,8 @@ uchar default_environment[] = { "\0" }; +struct hsearch_data env_htab; + static uchar env_get_char_init (int index) { uchar c; @@ -187,7 +189,7 @@ void set_default_env(const char *s) puts("Using default environment\n\n"); } - if (himport((char *)default_environment, + if (himport_r(&env_htab, (char *)default_environment, sizeof(default_environment), '\0', 0) == 0) { error("Environment import failed: errno = %d\n", errno); } @@ -213,7 +215,7 @@ int env_import(const char *buf, int check) } } - if (himport((char *)ep->data, ENV_SIZE, '\0', 0)) { + if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0)) { gd->flags |= GD_FLG_ENV_READY; return 1; } diff --git a/common/env_dataflash.c b/common/env_dataflash.c index 270f2b3..1d57079 100644 --- a/common/env_dataflash.c +++ b/common/env_dataflash.c @@ -68,7 +68,7 @@ int saveenv(void) char *res; res = (char *)&env_new.data; - len = hexport('\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; diff --git a/common/env_eeprom.c b/common/env_eeprom.c index 792b44f..0a179ad 100644 --- a/common/env_eeprom.c +++ b/common/env_eeprom.c @@ -143,7 +143,7 @@ int saveenv(void) BUG_ON(env_ptr != NULL); res = (char *)&env_new.data; - len = hexport('\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; diff --git a/common/env_flash.c b/common/env_flash.c index 54c0bfe..456f2e8 100644 --- a/common/env_flash.c +++ b/common/env_flash.c @@ -155,7 +155,7 @@ int saveenv(void) } res = (char *)&env_new.data; - len = hexport('\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); goto done; @@ -289,7 +289,7 @@ int saveenv(void) goto done; res = (char *)&env_new.data; - len = hexport('\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); goto done; diff --git a/common/env_mmc.c b/common/env_mmc.c index 7c9392c..71dcc4c 100644 --- a/common/env_mmc.c +++ b/common/env_mmc.c @@ -107,7 +107,7 @@ int saveenv(void) return 1; res = (char *)&env_new.data; - len = hexport('\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; diff --git a/common/env_nand.c b/common/env_nand.c index 7f6c917..2682f07 100644 --- a/common/env_nand.c +++ b/common/env_nand.c @@ -199,7 +199,7 @@ int saveenv(void) return 1; res = (char *)&env_new.data; - len = hexport('\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; @@ -256,7 +256,7 @@ int saveenv(void) return 1; res = (char *)&env_new.data; - len = hexport('\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; diff --git a/common/env_nvram.c b/common/env_nvram.c index 6e90f2b..544ce47 100644 --- a/common/env_nvram.c +++ b/common/env_nvram.c @@ -94,7 +94,7 @@ int saveenv(void) int rcode = 0; res = (char *)&env_new.data; - len = hexport('\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; diff --git a/common/env_onenand.c b/common/env_onenand.c index 02cb535..5e04a06 100644 --- a/common/env_onenand.c +++ b/common/env_onenand.c @@ -109,7 +109,7 @@ int saveenv(void) }; res = (char *)&env_new.data; - len = hexport('\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; diff --git a/common/env_sf.c b/common/env_sf.c index 47c6a70..41cc00a 100644 --- a/common/env_sf.c +++ b/common/env_sf.c @@ -92,7 +92,7 @@ int saveenv(void) } res = (char *)&env_new.data; - len = hexport('\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; @@ -308,7 +308,7 @@ int saveenv(void) } res = (char *)&env_new.data; - len = hexport('\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); goto done; -- cgit v1.1 From 41c86240567307655ad837be17e6f5fa2a06452f Mon Sep 17 00:00:00 2001 From: Lei Wen Date: Thu, 2 Dec 2010 05:17:55 +0000 Subject: onenand: add yaffs write command Yaffs image require to use the oob to store some info, so when we burn the yaffs image, we need to also write the image's oob part into flash. This patch add addition suffix to onenand write to give the uboot the power to directly burn the yaffs image to onenand. Signed-off-by: Lei Wen --- common/cmd_onenand.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'common') diff --git a/common/cmd_onenand.c b/common/cmd_onenand.c index cb2ba70..a27adaa 100644 --- a/common/cmd_onenand.c +++ b/common/cmd_onenand.c @@ -112,8 +112,32 @@ static int onenand_block_read(loff_t from, size_t len, return 0; } +static int onenand_write_oneblock_withoob(loff_t to, const u_char * buf, + size_t *retlen) +{ + struct mtd_oob_ops ops = { + .len = mtd->writesize, + .ooblen = mtd->oobsize, + .mode = MTD_OOB_AUTO, + }; + int page, ret = 0; + for (page = 0; page < (mtd->erasesize / mtd->writesize); page ++) { + ops.datbuf = (u_char *)buf; + buf += mtd->writesize; + ops.oobbuf = (u_char *)buf; + buf += mtd->oobsize; + ret = mtd->write_oob(mtd, to, &ops); + if (ret) + break; + to += mtd->writesize; + } + + *retlen = (ret) ? 0 : mtd->erasesize; + return ret; +} + static int onenand_block_write(loff_t to, size_t len, - size_t *retlen, const u_char * buf) + size_t *retlen, const u_char * buf, int withoob) { struct onenand_chip *this = mtd->priv; int blocks = len >> this->erase_shift; @@ -140,7 +164,10 @@ static int onenand_block_write(loff_t to, size_t len, goto next; } - ret = mtd->write(mtd, ofs, blocksize, &_retlen, buf); + if (!withoob) + ret = mtd->write(mtd, ofs, blocksize, &_retlen, buf); + else + ret = onenand_write_oneblock_withoob(ofs, buf, &_retlen); if (ret) { printk("Write failed 0x%x, %d", (u32)ofs, ret); skip_ofs += blocksize; @@ -386,19 +413,22 @@ static int do_onenand_write(cmd_tbl_t * cmdtp, int flag, int argc, char * const { ulong addr, ofs; size_t len; - int ret = 0; + int ret = 0, withoob = 0; size_t retlen = 0; if (argc < 3) return cmd_usage(cmdtp); + if (strncmp(argv[0] + 6, "yaffs", 5) == 0) + withoob = 1; + addr = (ulong)simple_strtoul(argv[1], NULL, 16); printf("\nOneNAND write: "); if (arg_off_size(argc - 2, argv + 2, &ofs, &len) != 0) return 1; - ret = onenand_block_write(ofs, len, &retlen, (u8 *)addr); + ret = onenand_block_write(ofs, len, &retlen, (u8 *)addr, withoob); printf(" %d bytes written: %s\n", retlen, ret ? "ERROR" : "OK"); @@ -521,6 +551,7 @@ static cmd_tbl_t cmd_onenand_sub[] = { U_BOOT_CMD_MKENT(bad, 1, 0, do_onenand_bad, "", ""), U_BOOT_CMD_MKENT(read, 4, 0, do_onenand_read, "", ""), U_BOOT_CMD_MKENT(write, 4, 0, do_onenand_write, "", ""), + U_BOOT_CMD_MKENT(write.yaffs, 4, 0, do_onenand_write, "", ""), U_BOOT_CMD_MKENT(erase, 3, 0, do_onenand_erase, "", ""), U_BOOT_CMD_MKENT(test, 3, 0, do_onenand_test, "", ""), U_BOOT_CMD_MKENT(dump, 2, 0, do_onenand_dump, "", ""), @@ -560,7 +591,7 @@ U_BOOT_CMD( "info - show available OneNAND devices\n" "onenand bad - show bad blocks\n" "onenand read[.oob] addr off size\n" - "onenand write addr off size\n" + "onenand write[.yaffs] addr off size\n" " read/write 'size' bytes starting at offset 'off'\n" " to/from memory address 'addr', skipping bad blocks.\n" "onenand erase [force] [off size] - erase 'size' bytes from\n" -- cgit v1.1