Fix OneNAND erase command
authorKyungmin Park <kmpark@infradead.org>
Mon, 31 Mar 2008 01:40:19 +0000 (10:40 +0900)
committerWolfgang Denk <wd@denx.de>
Mon, 14 Apr 2008 06:10:39 +0000 (23:10 -0700)
It mis-calculates the block address.
Also fix DECLARE_GLOBAL_DATA_PTR in env_onenand.

Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
common/cmd_onenand.c
common/env_onenand.c

index dcda099c84182e7d2da67d1eafb55fdda075fa1b..aff11d15c904d2944e77d7210d3fb1e1c1256fe1 100644 (file)
@@ -44,14 +44,28 @@ int do_onenand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
        default:
                /* At least 4 args */
                if (strncmp(argv[1], "erase", 5) == 0) {
-                       struct erase_info instr;
+                       struct erase_info instr = {
+                               .callback       = NULL,
+                       };
                        ulong start, end;
                        ulong block;
-
-                       start = simple_strtoul(argv[2], NULL, 10);
-                       end = simple_strtoul(argv[3], NULL, 10);
-                       start -= (unsigned long)onenand_chip.base;
-                       end -= (unsigned long)onenand_chip.base;
+                       char *endtail;
+
+                       if (strncmp(argv[2], "block", 5) == 0) {
+                               start = simple_strtoul(argv[3], NULL, 10);
+                               endtail = strchr(argv[3], '-');
+                               end = simple_strtoul(endtail + 1, NULL, 10);
+                       } else {
+                               start = simple_strtoul(argv[2], NULL, 10);
+                               end = simple_strtoul(argv[3], NULL, 10);
+                               start -= (unsigned long)onenand_chip.base;
+                               end -= (unsigned long)onenand_chip.base;
+
+                               start >>= onenand_chip.erase_shift;
+                               end >>= onenand_chip.erase_shift;
+                               /* Don't include the end block */
+                               end--;
+                       }
 
                        if (!end || end < 0)
                                end = start;
index 5888f75d895ec43b71fc3596380d69b75616feff..ac8a8c15e79fa85b81c33781722cc25a521e4271 100644 (file)
@@ -52,22 +52,21 @@ static unsigned char onenand_env[MAX_ONENAND_PAGESIZE];
 env_t *env_ptr = (env_t *) onenand_env;
 #endif /* ENV_IS_EMBEDDED */
 
+DECLARE_GLOBAL_DATA_PTR;
+
 uchar env_get_char_spec(int index)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
        return (*((uchar *) (gd->env_addr + index)));
 }
 
 void env_relocate_spec(void)
 {
-       DECLARE_GLOBAL_DATA_PTR;
        unsigned long env_addr;
        int use_default = 0;
        size_t retlen;
 
        env_addr = CFG_ENV_ADDR;
-       env_addr -= (unsigned long)onenand_chip.base;
+       env_addr -= (unsigned long) onenand_chip.base;
 
        /* Check OneNAND exist */
        if (onenand_mtd.oobblock)
@@ -95,7 +94,9 @@ void env_relocate_spec(void)
 int saveenv(void)
 {
        unsigned long env_addr = CFG_ENV_ADDR;
-       struct erase_info instr;
+       struct erase_info instr = {
+               .callback       = NULL,
+       };
        size_t retlen;
 
        instr.len = CFG_ENV_SIZE;
@@ -108,7 +109,7 @@ int saveenv(void)
 
        /* update crc */
        env_ptr->crc =
-           crc32(0, env_ptr->data, onenand_mtd.oobblock - ENV_HEADER_SIZE);
+           crc32(0, env_ptr->data, ONENAND_ENV_SIZE(onenand_mtd));
 
        env_addr -= (unsigned long)onenand_chip.base;
        if (onenand_write(&onenand_mtd, env_addr, onenand_mtd.oobblock, &retlen,
@@ -122,8 +123,6 @@ int saveenv(void)
 
 int env_init(void)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
        /* use default */
        gd->env_addr = (ulong) & default_environment[0];
        gd->env_valid = 1;