]> git.sur5r.net Git - u-boot/blobdiff - common/cmd_flash.c
Automatic software update from TFTP server
[u-boot] / common / cmd_flash.c
index 11c8857313b42d2e0c95fb8b2b7d82ab4be6511a..29e5b6d9aa6ea52cf05b4afb4b5d4d7f6fbe95d0 100644 (file)
@@ -31,8 +31,6 @@
 #include <dataflash.h>
 #endif
 
-#if defined(CONFIG_CMD_FLASH)
-
 #if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
 #include <jffs2/jffs2.h>
 
@@ -43,6 +41,7 @@ int find_dev_and_part(const char *id, struct mtd_device **dev,
                u8 *part_num, struct part_info **part);
 #endif
 
+#ifndef CFG_NO_FLASH
 extern flash_info_t flash_info[];      /* info for FLASH chips */
 
 /*
@@ -105,6 +104,47 @@ abbrev_spec (char *str, flash_info_t ** pinfo, int *psf, int *psl)
        return 1;
 }
 
+/*
+ * Take *addr in Flash and adjust it to fall on the end of its sector
+ */
+int flash_sect_roundb (ulong *addr)
+{
+       flash_info_t *info;
+       ulong bank, sector_end_addr;
+       char found;
+       int i;
+
+       /* find the end addr of the sector where the *addr is */
+       found = 0;
+       for (bank = 0; bank < CFG_MAX_FLASH_BANKS && !found; ++bank) {
+               info = &flash_info[bank];
+               for (i = 0; i < info->sector_count && !found; ++i) {
+                       /* get the end address of the sector */
+                       if (i == info->sector_count - 1) {
+                               sector_end_addr = info->start[0] +
+                                                               info->size - 1;
+                       } else {
+                               sector_end_addr = info->start[i+1] - 1;
+                       }
+
+                       if (*addr <= sector_end_addr &&
+                                               *addr >= info->start[i]) {
+                               found = 1;
+                               /* adjust *addr if necessary */
+                               if (*addr < sector_end_addr)
+                                       *addr = sector_end_addr;
+                       } /* sector */
+               } /* bank */
+       }
+       if (!found) {
+               /* error, addres not in flash */
+               printf("Error: end address (0x%08lx) not in flash!\n", *addr);
+               return 1;
+       }
+
+       return 0;
+}
+
 /*
  * This function computes the start and end addresses for both
  * erase and protect commands. The range of the addresses on which
@@ -127,8 +167,6 @@ addr_spec(char *arg1, char *arg2, ulong *addr_first, ulong *addr_last)
 {
        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')
@@ -158,38 +196,8 @@ addr_spec(char *arg1, char *arg2, ulong *addr_first, ulong *addr_last)
                 * sector boundary, so that the commands don't fail later on.
                 */
 
-               /* 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];
-                       for (i = 0; i < info->sector_count && !found; ++i){
-                               /* get the end address of the sector */
-                               ulong sector_end_addr;
-                               if (i == info->sector_count - 1){
-                                       sector_end_addr =
-                                               info->start[0] + info->size - 1;
-                               } else {
-                                       sector_end_addr =
-                                               info->start[i+1] - 1;
-                               }
-                               if (*addr_last <= sector_end_addr &&
-                                               *addr_last >= info->start[i]){
-                                       /* sector found */
-                                       found = 1;
-                                       /* adjust *addr_last if necessary */
-                                       if (*addr_last < sector_end_addr){
-                                               *addr_last = sector_end_addr;
-                                       }
-                               }
-                       } /* sector */
-               } /* bank */
-               if (!found){
-                       /* error, addres not in flash */
-                       printf("Error: end address (0x%08lx) not in flash!\n",
-                                                               *addr_last);
+               if (flash_sect_roundb(addr_last) > 0)
                        return -1;
-               }
        } /* "start +length" from used */
 
        return 1;
@@ -211,7 +219,7 @@ flash_fill_sect_ranges (ulong addr_first, ulong addr_last,
                s_last [bank] = -1;     /* last  sector to erase        */
        }
 
-       for (bank=0,info=&flash_info[0];
+       for (bank=0,info = &flash_info[0];
             (bank < CFG_MAX_FLASH_BANKS) && (addr_first <= addr_last);
             ++bank, ++info) {
                ulong b_end;
@@ -277,15 +285,19 @@ flash_fill_sect_ranges (ulong addr_first, ulong addr_last,
 
        return rcode;
 }
+#endif /* CFG_NO_FLASH */
 
 int do_flinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
+#ifndef CFG_NO_FLASH
        ulong bank;
+#endif
 
 #ifdef CONFIG_HAS_DATAFLASH
        dataflash_print_info();
 #endif
 
+#ifndef CFG_NO_FLASH
        if (argc == 1) {        /* print info for all FLASH banks */
                for (bank=0; bank <CFG_MAX_FLASH_BANKS; ++bank) {
                        printf ("\nBank # %ld: ", bank+1);
@@ -303,11 +315,13 @@ int do_flinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        }
        printf ("\nBank # %ld: ", bank);
        flash_print_info (&flash_info[bank-1]);
+#endif /* CFG_NO_FLASH */
        return 0;
 }
 
 int do_flerase (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
+#ifndef CFG_NO_FLASH
        flash_info_t *info;
        ulong bank, addr_first, addr_last;
        int n, sect_first, sect_last;
@@ -337,7 +351,7 @@ int do_flerase (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                        puts ("Bad sector specification\n");
                        return 1;
                }
-               printf ("Erase Flash Sectors %d-%d in Bank # %d ",
+               printf ("Erase Flash Sectors %d-%d in Bank # %zu ",
                        sect_first, sect_last, (info-flash_info)+1);
                rcode = flash_erase(info, sect_first, sect_last);
                return rcode;
@@ -355,7 +369,7 @@ int do_flerase (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                                addr_last = addr_first + part->size - 1;
 
                                printf ("Erase Flash Parition %s, "
-                                               "bank %d, 0x%08lx - 0x%08lx ",
+                                               "bank %ld, 0x%08lx - 0x%08lx ",
                                                argv[1], bank, addr_first,
                                                addr_last);
 
@@ -399,8 +413,12 @@ int do_flerase (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
        rcode = flash_sect_erase(addr_first, addr_last);
        return rcode;
+#else
+       return 0;
+#endif /* CFG_NO_FLASH */
 }
 
+#ifndef CFG_NO_FLASH
 int flash_sect_erase (ulong addr_first, ulong addr_last)
 {
        flash_info_t *info;
@@ -418,7 +436,7 @@ int flash_sect_erase (ulong addr_first, ulong addr_last)
                                        s_first, s_last, &planned );
 
        if (planned && (rcode == 0)) {
-               for (bank=0,info=&flash_info[0];
+               for (bank=0,info = &flash_info[0];
                     (bank < CFG_MAX_FLASH_BANKS) && (rcode == 0);
                     ++bank, ++info) {
                        if (s_first[bank]>=0) {
@@ -441,12 +459,17 @@ int flash_sect_erase (ulong addr_first, ulong addr_last)
        }
        return rcode;
 }
+#endif /* CFG_NO_FLASH */
 
 int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
+#ifndef CFG_NO_FLASH
        flash_info_t *info;
-       ulong bank, addr_first, addr_last;
-       int i, p, n, sect_first, sect_last;
+       ulong bank;
+       int i, n, sect_first, sect_last;
+#endif /* CFG_NO_FLASH */
+       ulong addr_first, addr_last;
+       int p;
 #if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
        struct mtd_device *dev;
        struct part_info *part;
@@ -489,6 +512,7 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        }
 #endif
 
+#ifndef CFG_NO_FLASH
        if (strcmp(argv[2], "all") == 0) {
                for (bank=1; bank<=CFG_MAX_FLASH_BANKS; ++bank) {
                        info = &flash_info[bank-1];
@@ -519,7 +543,7 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                        puts ("Bad sector specification\n");
                        return 1;
                }
-               printf("%sProtect Flash Sectors %d-%d in Bank # %d\n",
+               printf("%sProtect Flash Sectors %d-%d in Bank # %zu\n",
                        p ? "" : "Un-", sect_first, sect_last,
                        (info-flash_info)+1);
                for (i = sect_first; i <= sect_last; i++) {
@@ -551,7 +575,7 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                                addr_last = addr_first + part->size - 1;
 
                                printf ("%sProtect Flash Parition %s, "
-                                               "bank %d, 0x%08lx - 0x%08lx\n",
+                                               "bank %ld, 0x%08lx - 0x%08lx\n",
                                                p ? "" : "Un", argv[1],
                                                bank, addr_first, addr_last);
 
@@ -613,10 +637,11 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                return 1;
        }
        rcode = flash_sect_protect (p, addr_first, addr_last);
+#endif /* CFG_NO_FLASH */
        return rcode;
 }
 
-
+#ifndef CFG_NO_FLASH
 int flash_sect_protect (int p, ulong addr_first, ulong addr_last)
 {
        flash_info_t *info;
@@ -635,7 +660,7 @@ int flash_sect_protect (int p, ulong addr_first, ulong addr_last)
        protected = 0;
 
        if (planned && (rcode == 0)) {
-               for (bank=0,info=&flash_info[0]; bank < CFG_MAX_FLASH_BANKS; ++bank, ++info) {
+               for (bank=0,info = &flash_info[0]; bank < CFG_MAX_FLASH_BANKS; ++bank, ++info) {
                        if (info->flash_id == FLASH_UNKNOWN) {
                                continue;
                        }
@@ -669,6 +694,7 @@ int flash_sect_protect (int p, ulong addr_first, ulong addr_last)
        }
        return rcode;
 }
+#endif /* CFG_NO_FLASH */
 
 
 /**************************************************/
@@ -731,5 +757,3 @@ U_BOOT_CMD(
 #undef TMP_ERASE
 #undef TMP_PROT_ON
 #undef TMP_PROT_OFF
-
-#endif