]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_flash.c
Add MACH_TYPE records for several AT91 boards.
[karo-tx-uboot.git] / common / cmd_flash.c
index d5be30c54dd0d00791e56a1fba2a36ba13966c25..11c8857313b42d2e0c95fb8b2b7d82ab4be6511a 100644 (file)
@@ -31,9 +31,9 @@
 #include <dataflash.h>
 #endif
 
-#if (CONFIG_COMMANDS & CFG_CMD_FLASH)
+#if defined(CONFIG_CMD_FLASH)
 
-#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
+#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
 #include <jffs2/jffs2.h>
 
 /* parition handling routines */
@@ -125,13 +125,16 @@ abbrev_spec (char *str, flash_info_t ** pinfo, int *psf, int *psl)
 static int
 addr_spec(char *arg1, char *arg2, ulong *addr_first, ulong *addr_last)
 {
-       char len_used = 0; /* indicates if the "start +length" form used */
        char *ep;
+       char len_used; /* indicates if the "start +length" form used */
+       char found;
+       ulong bank;
 
        *addr_first = simple_strtoul(arg1, &ep, 16);
        if (ep == arg1 || *ep != '\0')
                return -1;
 
+       len_used = 0;
        if (arg2 && *arg2 == '+'){
                len_used = 1;
                ++arg2;
@@ -142,9 +145,6 @@ addr_spec(char *arg1, char *arg2, ulong *addr_first, ulong *addr_last)
                return -1;
 
        if (len_used){
-               char found = 0;
-               ulong bank;
-
                /*
                 * *addr_last has the length, compute correct *addr_last
                 * XXX watch out for the integer overflow! Right now it is
@@ -159,6 +159,7 @@ addr_spec(char *arg1, char *arg2, ulong *addr_first, ulong *addr_last)
                 */
 
                /* find the end addr of the sector where the *addr_last is */
+               found = 0;
                for (bank = 0; bank < CFG_MAX_FLASH_BANKS && !found; ++bank){
                        int i;
                        flash_info_t *info = &flash_info[bank];
@@ -310,7 +311,7 @@ int do_flerase (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        flash_info_t *info;
        ulong bank, addr_first, addr_last;
        int n, sect_first, sect_last;
-#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
+#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
        struct mtd_device *dev;
        struct part_info *part;
        u8 dev_type, dev_num, pnum;
@@ -342,7 +343,7 @@ int do_flerase (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                return rcode;
        }
 
-#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
+#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
        /* erase <part-id> - erase partition */
        if ((argc == 2) && (id_parse(argv[1], NULL, &dev_type, &dev_num) == 0)) {
                mtdparts_init();
@@ -404,7 +405,11 @@ int flash_sect_erase (ulong addr_first, ulong addr_last)
 {
        flash_info_t *info;
        ulong bank;
+#ifdef CFG_MAX_FLASH_BANKS_DETECT
+       int s_first[CFG_MAX_FLASH_BANKS_DETECT], s_last[CFG_MAX_FLASH_BANKS_DETECT];
+#else
        int s_first[CFG_MAX_FLASH_BANKS], s_last[CFG_MAX_FLASH_BANKS];
+#endif
        int erased = 0;
        int planned;
        int rcode = 0;
@@ -442,7 +447,7 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        flash_info_t *info;
        ulong bank, addr_first, addr_last;
        int i, p, n, sect_first, sect_last;
-#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
+#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
        struct mtd_device *dev;
        struct part_info *part;
        u8 dev_type, dev_num, pnum;
@@ -451,6 +456,7 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 #ifdef CONFIG_HAS_DATAFLASH
        int status;
 #endif
+
        if (argc < 3) {
                printf ("Usage:\n%s\n", cmdtp->usage);
                return 1;
@@ -501,12 +507,10 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                                info->protect[i] = p;
 #endif /* CFG_FLASH_PROTECTION */
                        }
-               }
-
 #if defined(CFG_FLASH_PROTECTION)
-               if (!rcode) puts (" done\n");
+                       if (!rcode) puts (" done\n");
 #endif /* CFG_FLASH_PROTECTION */
-
+               }
                return rcode;
        }
 
@@ -535,7 +539,7 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                return rcode;
        }
 
-#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
+#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
        /* protect on/off <part-id> */
        if ((argc == 3) && (id_parse(argv[2], NULL, &dev_type, &dev_num) == 0)) {
                mtdparts_init();
@@ -617,7 +621,11 @@ int flash_sect_protect (int p, ulong addr_first, ulong addr_last)
 {
        flash_info_t *info;
        ulong bank;
+#ifdef CFG_MAX_FLASH_BANKS_DETECT
+       int s_first[CFG_MAX_FLASH_BANKS_DETECT], s_last[CFG_MAX_FLASH_BANKS_DETECT];
+#else
        int s_first[CFG_MAX_FLASH_BANKS], s_last[CFG_MAX_FLASH_BANKS];
+#endif
        int protected, i;
        int planned;
        int rcode;
@@ -647,10 +655,10 @@ int flash_sect_protect (int p, ulong addr_first, ulong addr_last)
 #endif /* CFG_FLASH_PROTECTION */
                                }
                        }
+               }
 #if defined(CFG_FLASH_PROTECTION)
-                       if (!rcode) putc ('\n');
+               puts (" done\n");
 #endif /* CFG_FLASH_PROTECTION */
-               }
 
                printf ("%sProtected %d sectors\n",
                        p ? "" : "Un-", protected);
@@ -664,7 +672,7 @@ int flash_sect_protect (int p, ulong addr_first, ulong addr_last)
 
 
 /**************************************************/
-#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
+#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
 # define TMP_ERASE     "erase <part-id>\n    - erase partition\n"
 # define TMP_PROT_ON   "protect on <part-id>\n    - protect partition\n"
 # define TMP_PROT_OFF  "protect off <part-id>\n    - make partition writable\n"
@@ -682,7 +690,7 @@ U_BOOT_CMD(
 );
 
 U_BOOT_CMD(
-       erase,   3,   1,  do_flerase,
+       erase,   3,   0,  do_flerase,
        "erase   - erase FLASH memory\n",
        "start end\n"
        "    - erase FLASH from addr 'start' to addr 'end'\n"
@@ -696,7 +704,7 @@ U_BOOT_CMD(
 );
 
 U_BOOT_CMD(
-       protect,  4,  1,   do_protect,
+       protect,  4,  0,   do_protect,
        "protect - enable or disable FLASH write protection\n",
        "on  start end\n"
        "    - protect FLASH from addr 'start' to addr 'end'\n"
@@ -724,4 +732,4 @@ U_BOOT_CMD(
 #undef TMP_PROT_ON
 #undef TMP_PROT_OFF
 
-#endif /* CFG_CMD_FLASH */
+#endif