mtd/util flash_otp_dump.c, NONE, 1.1 flash_otp_info.c, NONE,
1.1 Makefile, 1.54, 1.55
Nicolas Pitre
nico at infradead.org
Tue Feb 8 12:45:55 EST 2005
Update of /home/cvs/mtd/util
In directory phoenix.infradead.org:/tmp/cvs-serv22416/util
Modified Files:
Makefile
Added Files:
flash_otp_dump.c flash_otp_info.c
Log Message:
user interface to Protection Registers
This is implemented using a ioctl to switch the MTD char device into
one of the different OTP "modes", at which point read/write/seek can
operate on the selected OTP area. Also some extra ioctls to query
for size and lock protection segments or groups. Some example user
space utilities are provided.
Signed-off-by: Nicolas Pitre <nico at cam.org>
--- NEW FILE flash_otp_dump.c ---
/*
* flash_otp_dump.c -- display One-Time-Programm data
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <mtd/mtd-user.h>
int main(int argc,char *argv[])
{
int fd, val, i, offset, ret;
unsigned char buf[16];
if (argc != 3 || (strcmp(argv[1], "-f") && strcmp(argv[1], "-u"))) {
fprintf(stderr,"Usage: %s [ -f | -u ] <device>\n", argv[0]);
return EINVAL;
}
fd = open(argv[2], O_RDONLY);
if (fd < 0) {
perror(argv[2]);
return errno;
}
val = argv[1][1] == 'f' ? MTD_OTP_FACTORY : MTD_OTP_USER;
ret = ioctl(fd, OTPSELECT, &val);
if (ret < 0) {
perror("OTPSELECT");
return errno;
}
printf("OTP %s data for %s\n",
argv[1][1] == 'f' ? "factory" : "user", argv[2]);
offset = 0;
while ((ret = read(fd, buf, sizeof(buf)))) {
if (ret < 0) {
perror("read()");
return errno;
}
printf("0x%04x:", offset);
for (i = 0; i < ret; i++)
printf(" %02x", buf[i]);
printf("\n");
offset += ret;
}
close(fd);
return 0;
}
--- NEW FILE flash_otp_info.c ---
/*
* flash_otp_info.c -- print info about One-Time-Programm data
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <mtd/mtd-user.h>
int main(int argc,char *argv[])
{
int fd, val, i, ret;
if (argc != 3 || (strcmp(argv[1], "-f") && strcmp(argv[1], "-u"))) {
fprintf(stderr,"Usage: %s [ -f | -u ] <device>\n", argv[0]);
return EINVAL;
}
fd = open(argv[2], O_RDONLY);
if (fd < 0) {
perror(argv[2]);
return errno;
}
val = argv[1][1] == 'f' ? MTD_OTP_FACTORY : MTD_OTP_USER;
ret = ioctl(fd, OTPSELECT, &val);
if (ret < 0) {
perror("OTPSELECT");
return errno;
}
ret = ioctl(fd, OTPGETREGIONCOUNT, &val);
if (ret < 0) {
perror("OTPGETREGIONCOUNT");
return errno;
}
printf("Number of OTP %s blocks on %s: %d\n",
argv[1][1] == 'f' ? "factory" : "user", argv[2], val);
if (val > 0) {
struct otp_info info[val];
ret = ioctl(fd, OTPGETREGIONINFO, &info);
if (ret < 0) {
perror("OTPGETREGIONCOUNT");
return errno;
}
for (i = 0; i < val; i++)
printf("block %2d: offset = 0x%04x "
"size = %2d bytes %s\n",
i, info[i].start, info[i].length,
info[i].locked ? "[locked]" : "[unlocked]");
}
close(fd);
return 0;
}
Index: Makefile
===================================================================
RCS file: /home/cvs/mtd/util/Makefile,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- Makefile 21 Jan 2005 11:52:22 -0000 1.54
+++ Makefile 8 Feb 2005 17:45:52 -0000 1.55
@@ -11,8 +11,9 @@
CFLAGS := -I../include -O2 -Wall
TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \
- mkfs.jffs ftl_check mkfs.jffs2 flash_lock flash_unlock \
- flash_info mtd_debug flashcp nandwrite jffs2dump jffs3dump \
+ mkfs.jffs ftl_check mkfs.jffs2 flash_lock flash_unlock flash_info \
+ flash_otp_info flash_otp_dump mtd_debug flashcp nandwrite \
+ jffs2dump jffs3dump \
nftldump nftl_format docfdisk \
sumtool #jffs2reader
More information about the linux-mtd-cvs
mailing list