[HD2 Android Q&A, Help & Troubleshooting and Genera] Franck78:
Hello All,

How many of you users with hd2 will be able to compile a custom kernel with a patched htcleo_nand.c ?

This is to validate my guess of finding two unique macadress writed in block 505 of the NAND.

To definitly get rid of this problem.

Franck

diff --git a/drivers/mtd/devices/htcleo_nand.c b/drivers/mtd/devices/htcleo_nand.c
index 2150bcc..bfbcbad 100755
--- a/drivers/mtd/devices/htcleo_nand.c
+++ b/drivers/mtd/devices/htcleo_nand.c
@@ -1827,6 +1827,116 @@ static int param_get_page_size(char *buffer, struct kernel_param *kp)
}
module_param_call(pagesize, NULL, param_get_page_size, NULL, S_IRUGO);

+int is_htc_mac (int pattern)
+{
+	/* HTC blocks to find :
+	00:09:2D
+	00:23:76
+	18:87:76
+	1C:B0:94
+	38:E7:D8
+	64:A7:69
+	7C:61:93
+	90:21:55
+	A0:F4:50
+	A8:26:D9
+	D4:20:6D
+	D8:B3:77
+	E8:99:C4
+	F8:DB:F7 */
+ static int nums[] = {
+ 0x00092D,0x2D0900,
+ 0x002376,0x762300,
+ 0x188776,0x768718,
+ 0x1CB094,0x94B01C,
+ 0x38E7D8,0xD8E738,
+ 0x64A769,0x69A764,
+ 0x7C6193,0x93617C,
+ 0x902155,0x552190,
+ 0xA0F450,0x50F4A0,
+ 0xA826D9,0xD926A8,
+ 0xD4206D,0x6D20D4,
+ 0xD8B377,0x77B3D8,
+ 0xE899C4,0xC499E8,
+ 0xF8DBF7,0xF7DBF8};
+ int i;
+ for (i=0; i< (sizeof(nums)/sizeof(nums[0])); i++)
+ {
+	if (nums[i] == pattern) return 1;
+ }
+ return 0;
+}
+void scanmac(struct mtd_info *mtd)
+{
+	unsigned char *iobuf;
+	int ret;
+	loff_t addr;
+	struct mtd_oob_ops ops;
+	int i,j,k;
+
+	iobuf = kmalloc(2048/*mtd->erasesize*/, GFP_KERNEL);
+	if (!iobuf) {
+	/*ret = -ENOMEM;*/
+	printk("%s: error: cannot allocate memory\n",__func__);
+	return;
+	}
+
+	ops.mode = MTD_OOB_PLACE;
+	ops.len = 2048;
+	ops.datbuf = iobuf;
+	ops.ooblen = 0;
+	ops.oobbuf = NULL;
+	ops.retlen = 0;
+
+	/* bloc 505 page 6 contains as good candidate */
+	addr = ((loff_t) 505*0x20000 + 6*2048);
+	ret = msm_nand_read_oob(mtd, addr, &ops);
+
+	if (ret == -EUCLEAN)
+	ret = 0;
+	if (ret || ops.retlen != 2048 ) {
+	printk("%s: error: read(%d) failed at %#llx\n",__func__,ops.retlen, addr);
+	goto out;
+	}
+
+	printk("%s: Prefered candidate mac=%02x:%02x:%02x:%02x:%02x:%02x\n",__func__,
+	iobuf[5],iobuf[4],iobuf[3],iobuf[2],iobuf[1],iobuf[0]);
+
+	/* now lets walk looking for HTC mac in the first reserved blocks of NAND */
+	/* NUM_PROTECTED_BLOCKS=0x212 but Parttiontable starts at 0x219 */
+	/* I think 400 is ok, I have already eliminated 0 - 157 with false positive */
+	/* If my guess is correct, only 505 will match ;-) */
+	for (i=158; i<0x219; i++) {
+	for (j=0; j<64; j++) {
+	addr = ((loff_t) i*0x20000 + j*2048);
+	ret = msm_nand_read_oob(mtd, addr, &ops);
+
+	if (ret == -EUCLEAN)
+	ret = 0;
+	if (ret || ops.retlen != 2048 ) {
+	printk("%s: error: read(%d) failed at %#llx\n",__func__,ops.retlen, addr);
+	break;
+	}
+	/* check */
+	for (k=0; k<2045; k++) {
+	if (is_htc_mac( (iobuf[k+0]<<16) + (iobuf[k+1]<<8) + iobuf[k+2])) {
+	printk("Mac candidate at block:%d page:%d offset:%d:\n",i,j,k);
+	k >>= 4;
+	k <<= 4;
+	print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, &iobuf[k], 16);
+	k += 16;
+	}
+	}
+	}/*j*/
+	}/*i*/
+	ret = 0;
+out:
+	kfree(iobuf);
+	if (ret)
+	printk("Find MAc Error %d occurred\n", ret);
+	return;
+}
+
/**
* msm_nand_scan - [msm_nand Interface] Scan for the msm_nand device
* @param mtd	MTD device structure
@@ -1992,6 +2102,8 @@ int msm_nand_scan(struct mtd_info *mtd, int maxchips)
/* msm_nand_unlock_all(mtd); */

/* return this->scan_bbt(mtd); */
+	scanmac(mtd);
+

#if VERBOSE
for (i=0;i<nand_info->block_count;i++)

my findings are on five HD2 are:

Frk

Mac candidate at block:505 page:0 offset:40:

00000000: 00 00 00 00 30 00 00 00 38 e7 d8 e6 38 fc 00 00 ....0...8...8...

Mac candidate at block:505 page:6 offset:3:

00000000: 80 1c e2 d8 e7 38 ff ff ff ff ff ff ff ff ff ff .....8..........

wifi mac 38 e7 d8 e6 38 fcunder WIMO

Bad

Mac candidate at block:505 page:0 offset:40:

00000000: 00 00 00 00 30 00 00 00 00 23 76 5d fb 08 00 00 ....0....#v]....

Mac candidate at block:505 page:6 offset:3:

00000000: df 20 74 76 23 00 ff ff ff ff ff ff ff ff ff ff . tv#...........

Frk2

Mac candidate at block:505 page:0 offset:40:

00000000: 00 00 00 00 30 00 00 00 00 23 76 d7 ea 13 00 00 ....0....#v.....

Mac candidate at block:505 page:6 offset:3:

00000000: 80 5b e5 76 23 00 ff ff ff ff ff ff ff ff ff ff .[.v#...........

Val

Mac candidate at block:505 page:0 offset:40:

00000000: 00 00 00 00 30 00 00 00 00 23 76 89 09 c0 00 00 ....0....#v.....

Mac candidate at block:505 page:6 offset:3:

00000000: 46 da 6d 76 23 00 ff ff ff ff ff ff ff ff ff ff F.mv#...........

Flo

Mac candidate at block:505 page:0 offset:40:

00000000: 00 00 00 00 30 00 00 00 00 23 76 8c a4 a6 00 00 ....0....#v.....

Mac candidate at block:505 page:6 offset:3:

00000000: 3d 48 6f 76 23 00 ff ff ff ff ff ff ff ff ff ff =Hov#...........

Flo after full task29+reinstall

Mac candidate at block:505 page:0 offset:40:

00000000: 00 00 00 00 30 00 00 00 00 23 76 8c a4 a6 00 00 ....0....#v.....

Mac candidate at block:505 page:6 offset:3:

00000000: 3d 48 6f 76 23 00 ff ff ff ff ff ff ff ff ff ff =Hov#...........