Skip to contentSkip to conversation

Add support for 4KB page flash devices

PATCH In review AYYANARPONNUSAMY GANGHEYAMOORTHY 4 participants 6 messages Sep 19, 2008 – Sep 26, 2008 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add support for 4KB page flash devices

We can now use these utilities on 4KB devices.

---

flash_otp_write.c +1 -1
@@ -18,7 +18,7 @@ int main(int argc,char *argv[])
 	int fd, val, ret, size, wrote, len;
 	mtd_info_t mtdInfo;
 	off_t offset;
-	char *p, buf[2048];
+	char *p, buf[4096];
 
 	if (argc != 4 || strcmp(argv[1], "-u")) {
 		fprintf(stderr, "Usage: %s -u <device> <offset>\n", argv[0]);
include/mtd/mtd-abi.h +2 -2
@@ -104,7 +104,7 @@ struct nand_oobinfo {
 	uint32_t useecc;
 	uint32_t eccbytes;
 	uint32_t oobfree[8][2];
-	uint32_t eccpos[32];
+	uint32_t eccpos[128];
 };
 
 struct nand_oobfree {
@@ -119,7 +119,7 @@ struct nand_oobfree {
  */
 struct nand_ecclayout {
 	uint32_t eccbytes;
-	uint32_t eccpos[64];
+	uint32_t eccpos[128];
 	uint32_t oobavail;
 	struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES];
 };
flashcp.c +1 -1
@@ -61,7 +62,7 @@ typedef int bool;
 #define PERCENTAGE(x,total) (((x) * 100) / (total))
 
 /* size of read/write buffer */
-#define BUFSIZE (10 * 1024)
+#define BUFSIZE (10 * 4096)
 
 /* cmd-line flags */
 #define FLAG_NONE		0x00
#1 lore raw

Hi,

flash_otp_write.c 2008-07-01 16:04:12.000000000 +0530 int main(int argc,char *argv[]) · line 22

Quoted 13 lines · AYYANARPONNUSAMY GANGHEYAMOORTHY

We can now use these utilities on 4KB devices.

---

flash_otp_write.c 2008-07-01 16:04:12.000000000 +0530 renamed from flash_otp_write.c 2008-06-27 21:51:28.000000000 +0530 +1 -1
@@ -18,7 +18,7 @@ int main(int argc,char *argv[])
       int fd, val, ret, size, wrote, len;
       mtd_info_t mtdInfo;
       off_t offset;
-       char *p, buf[2048];
+       char *p, buf[4096];
 

Is it no problem the stack overflow in application? How about to use malloc & free?

Thank you,
Kyungmin Park

#2 lore raw

Hello.

Quoted 18 lines · Kyungmin Park
Quoted 7 lines

We can now use these utilities on 4KB devices.

---

flash_otp_write.c 2008-07-01 16:04:12.000000000 +0530 int main(int argc,char *argv[]) · line 23

Quoted 7 lines
flash_otp_write.c 2008-07-01 16:04:12.000000000 +0530 renamed from flash_otp_write.c 2008-06-27 21:51:28.000000000 +0530 +1 -1
@@ -18,7 +18,7 @@ int main(int argc,char *argv[])
       int fd, val, ret, size, wrote, len;
       mtd_info_t mtdInfo;
       off_t offset;
-       char *p, buf[2048];
+       char *p, buf[4096];
 
 

Is it no problem the stack overflow in application? How about to use malloc & free?

Come on, it's only an extra page of stack for a non-recursive
function -- this shouldn't pose any danger.

WBR, Sergei

author
#3 lore raw
In reply to Kyungmin Park

Hi,

I find not much issue with that, but still as a fair practice , I'll
absorb your comment in the patch. Have done the memory allocation later in the function to avoid unnecessary freeing code.
And malloced with mtdInfo.writesize instead of constants , let us know
your comments.

We can now use these utilities on 4KB devices.

---

flashcp.c +1 -1
@@ -61,7 +61,7 @@ typedef int bool;
 #define PERCENTAGE(x,total) (((x) * 100) / (total))
 
 /* size of read/write buffer */
-#define BUFSIZE (10 * 1024)
+#define BUFSIZE (10 * 4096)
 
 /* cmd-line flags */
 #define FLAG_NONE		0x00
flash_otp_write.c +1 -1
@@ -18,7 +18,7 @@ int main(int argc,char *argv[])
 	int fd, val, ret, size, wrote, len;
 	mtd_info_t mtdInfo;
 	off_t offset;
-	char *p, buf[2048];
+	char *p, *buf;
 
 	if (argc != 4 || strcmp(argv[1], "-u")) {
 		fprintf(stderr, "Usage: %s -u <device> <offset>\n",

argv[0]);
@@ -64,9 +64,16 @@ int main(int argc,char *argv[])
len = 256;

wrote = 0;
+
+ buf = (char *)malloc(mtdInfo.writesize);
+ if (!buf) {
+ return -ENOMEM;
+ }
+
while ((size = read(0, buf, len))) {
if (size < 0) {
perror("read()");
+ free(buf);
return errno;
}
p = buf;
@@ -79,10 +86,12 @@ int main(int argc,char *argv[])
ret = write(fd, p, size);
if (ret < 0) {
perror("write()");
+ free(buf);
return errno;
}
if (ret == 0) {
printf("write() returned 0 after writing %d
bytes\n", wrote);
+ free(buf);
return 0;
}
p += ret;
@@ -92,5 +101,6 @@ int main(int argc,char *argv[])
}

printf("Wrote %d bytes of OTP user data\n", wrote);
+ free(buf);
return 0;
}

include/mtd/mtd-abi.h +2 -2
@@ -104,7 +104,7 @@ struct nand_oobinfo {
 	uint32_t useecc;
 	uint32_t eccbytes;
 	uint32_t oobfree[8][2];
-	uint32_t eccpos[32];
+	uint32_t eccpos[128];
 };
 
 struct nand_oobfree {
@@ -119,7 +119,7 @@ struct nand_oobfree {
  */
 struct nand_ecclayout {
 	uint32_t eccbytes;
-	uint32_t eccpos[64];
+	uint32_t eccpos[128];
 	uint32_t oobavail;
 	struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES];
 };

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Kyungmin Park
Sent: Monday, September 22, 2008 11:53 AM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] [MTD-UTILS] Add support for 4KB page flash devices

Hi,

flash_otp_write.c 2008-07-01 16:04:12.000000000 +0530 int main(int argc,char *argv[]) · line 22

Quoted 13 lines · AYYANARPONNUSAMY GANGHEYAMOORTHY

We can now use these utilities on 4KB devices.

---

flash_otp_write.c 2008-07-01 16:04:12.000000000 +0530 renamed from flash_otp_write.c 2008-06-27 21:51:28.000000000 +0530 +1 -1
@@ -18,7 +18,7 @@ int main(int argc,char *argv[])
       int fd, val, ret, size, wrote, len;
       mtd_info_t mtdInfo;
       off_t offset;
-       char *p, buf[2048];
+       char *p, buf[4096];
 

Is it no problem the stack overflow in application? How about to use malloc & free?

Thank you,
Kyungmin Park

Acked-by
#4 lore raw
Quoted 10 lines

I find not much issue with that, but still as a fair practice , I'll
absorb your comment in the patch. Have done the memory allocation later in the function to avoid unnecessary freeing code.
And malloced with mtdInfo.writesize instead of constants , let us know
your comments.

We can now use these utilities on 4KB devices.

---

Quoted 59 lines

}

include/mtd/mtd-abi.h 2008-09-23 15:48:48.000000000 +0530 renamed from include/mtd/mtd-abi.h 2008-09-23 15:36:26.000000000 +0530 +2 -3
@@ -104,7 +104,7 @@ struct nand_oobinfo {
       uint32_t useecc;
       uint32_t eccbytes;
       uint32_t oobfree[8][2];
-       uint32_t eccpos[32];
+       uint32_t eccpos[128];
 };
 
 struct nand_oobfree {
@@ -119,7 +119,7 @@ struct nand_oobfree {
 */
 struct nand_ecclayout {
       uint32_t eccbytes;
-       uint32_t eccpos[64];
+       uint32_t eccpos[128];
       uint32_t oobavail;
       struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES];
 };
 
 
 
 
 
-----Original Message-----

From: [email protected] [mailto:[email protected]] On Behalf Of Kyungmin Park
Sent: Monday, September 22, 2008 11:53 AM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] [MTD-UTILS] Add support for 4KB page flash devices

Hi,

flash_otp_write.c 2008-07-01 16:04:12.000000000 +0530 int main(int argc,char *argv[]) · line 22

Quoted 13 lines · AYYANARPONNUSAMY GANGHEYAMOORTHY

We can now use these utilities on 4KB devices.

---

flash_otp_write.c 2008-07-01 16:04:12.000000000 +0530 renamed from flash_otp_write.c 2008-06-27 21:51:28.000000000 +0530 +1 -1
@@ -18,7 +18,7 @@ int main(int argc,char *argv[])
       int fd, val, ret, size, wrote, len;
       mtd_info_t mtdInfo;
       off_t offset;
-       char *p, buf[2048];
+       char *p, buf[4096];
 

Is it no problem the stack overflow in application? How about to use malloc & free?

Thank you,
Kyungmin Park

#5 lore raw

Hi,

Quoted 6 lines · Kyungmin Park
Quoted 4 lines

We can now use these utilities on 4KB devices.

---

Err, isn't this ABI change which is going to break backward compatibility and is NO-NO in Linux?

Quoted 10 lines

include/mtd/mtd-abi.h 2008-09-23 15:48:48.000000000 +0530 struct nand_oobinfo { · line 108

Quoted 10 lines

}

include/mtd/mtd-abi.h 2008-09-23 15:48:48.000000000 +0530 renamed from include/mtd/mtd-abi.h 2008-09-23 15:36:26.000000000 +0530 +1 -1
@@ -104,7 +104,7 @@ struct nand_oobinfo {
       uint32_t useecc;
       uint32_t eccbytes;
       uint32_t oobfree[8][2];
-       uint32_t eccpos[32];
+       uint32_t eccpos[128];
 };

Err, isn't this ABI change which is going to break backward compatibility and is NO-NO in Linux?

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)