Skip to contentSkip to conversation

NAND: cmd_nand.c: fix invalid pointers to static relocated chip names

PATCH Superseded Valeriy Glushkov 3 participants 4 messages Jan 19, 2009 – Feb 6, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NAND: cmd_nand.c: fix invalid pointers to static relocated chip names

When U-boot starting from NAND the pointers to chip names are set before relocation. If the original memory block is overwritten after relocation that led to invalid string data in the nand utility.

---

common/cmd_nand.c +6 -5
index b94a2bf..14925cd 100644
@@ -10,6 +10,7 @@
 
 #include <common.h>
 
+DECLARE_GLOBAL_DATA_PTR;
 
 #ifndef CONFIG_NAND_LEGACY
 /*
@@ -193,7 +194,7 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 		for (i = 0; i < CFG_MAX_NAND_DEVICE; i++) {
 			if (nand_info[i].name)
 				printf("Device %d: %s, sector size %u KiB\n",
-				       i, nand_info[i].name,
+				       i, nand_info[i].name + gd->reloc_off,
 				       nand_info[i].erasesize >> 10);
 		}
 		return 0;
@@ -207,7 +208,7 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 				puts("\nno devices available\n");
 			else
 				printf("\nDevice %d: %s\n", nand_curr_device,
-				       nand_info[nand_curr_device].name);
+				       nand_info[nand_curr_device].name + gd->reloc_off);
 			return 0;
 		}
 		dev = (int)simple_strtoul(argv[2], NULL, 10);
@@ -215,7 +216,7 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 			puts("No such device\n");
 			return 1;
 		}
-		printf("Device %d: %s", dev, nand_info[dev].name);
+		printf("Device %d: %s", dev, nand_info[dev].name + gd->reloc_off);
 		puts("... is now current device\n");
 		nand_curr_device = dev;
 
@@ -993,8 +994,8 @@ int do_nandboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	show_boot_progress (55);
 
 	printf ("\nLoading from device %d: %s at 0x%lx (offset 0x%lx)\n",
-	    dev, nand_dev_desc[dev].name, nand_dev_desc[dev].IO_ADDR,
-	    offset);
+	    dev, nand_dev_desc[dev].name + gd->reloc_off,
+	    nand_dev_desc[dev].IO_ADDR, offset);
 
 	if (nand_legacy_rw (nand_dev_desc + dev, NANDRW_READ, offset,
 			    SECTORSIZE, NULL, (u_char *)addr)) {
Signature · 1 line
1.5.2.5
#1 lore raw

PATCH 1/1 NAND: cmd_nand.c: fix invalid pointers to static relocated chip names

Dear Valeriy Glushkov,

Quoted 3 lines · In message <[email protected]> you wrote:

When U-boot starting from NAND the pointers to chip names are set before relocation. If the original memory block is overwritten after relocation that led to invalid string data in the nand utility.

This means that the pointers need to be manually relocated.

common/cmd_nand.c int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) · line 197

Quoted 2 lines
common/cmd_nand.c +1 -1
-				       i, nand_info[i].name,
+				       i, nand_info[i].name + gd->reloc_off,

Such relocation shouldbe done exactly once, right after relocation.

Doing this everywhere where the pointers are references is error prone, ugly and wastes memory.

Please change your patch to fix the pointers. Thanks.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"We all agree on the necessity of compromise. We just can't agree  on
when it's necessary to compromise."
                - Larry Wall in  <[email protected]>
#2 lore raw

PATCH v2 1/1 nand: Fixed invalid pointers to static relocated chip names

Dear Wolfgang,

You are right, the patch was ugly.
The new one seems to be better.

---

drivers/mtd/nand/nand.c +4 -0
index 700d21d..8ac53e0 100644
@@ -28,6 +28,8 @@
 #define CFG_NAND_BASE_LIST { CFG_NAND_BASE }
 #endif
 
+DECLARE_GLOBAL_DATA_PTR;
+
 int nand_curr_device = -1;
 nand_info_t nand_info[CFG_MAX_NAND_DEVICE];
 
@@ -48,6 +50,8 @@ static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,
 		if (nand_scan(mtd, 1) == 0) {
 			if (!mtd->name)
 				mtd->name = (char *)default_nand_name;
+			else
+				mtd->name += gd->reloc_off;
 		} else
 			mtd->name = NULL;
 	} else {
Signature · 1 line
1.5.2.5
#3 lore raw

PATCH v2 1/1 nand: Fixed invalid pointers to static relocated chip names

Quoted 6 lines · Valeriy Glushkov

Dear Wolfgang,

You are right, the patch was ugly.
The new one seems to be better.

Applied to u-boot-nand-flash.

-Scott