include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=mtd
-PKG_RELEASE:=26
+PKG_RELEASE:=27
PKG_BUILD_DIR := $(KERNEL_BUILD_DIR)/$(PKG_NAME)
STAMP_PREPARED := $(STAMP_PREPARED)_$(call confvar,CONFIG_MTD_REDBOOT_PARTS)
if (fis_fd >= 0)
fis_close();
- fis_fd = mtd_check_open("FIS directory");
+ fis_fd = mtd_check_open("FIS directory", true);
if (fis_fd < 0)
goto error;
close(fis_fd);
- fis_fd = mtd_open("FIS directory", true);
+ fis_fd = mtd_open("FIS directory", true, true);
if (fis_fd < 0)
goto error;
goto err;
}
- bfd = mtd_open(name, true);
+ bfd = mtd_open(name, true, true);
ptr = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, bfd, 0);
if (!ptr || (ptr == (void *) -1)) {
perror("mmap");
}
/* check if image fits to mtd device */
- fd = mtd_check_open(mtd);
+ fd = mtd_check_open(mtd, true);
if(fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
exit(1);
block_offset = offset & ~(erasesize - 1);
offset -= block_offset;
- fd = mtd_check_open(mtd);
+ fd = mtd_check_open(mtd, true);
if(fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
exit(1);
{
int err = -1, fdeof = 0;
- outfd = mtd_check_open(mtd);
+ outfd = mtd_check_open(mtd, true);
if (outfd < 0)
return -1;
DLOG_OPEN();
- fd = mtd_check_open(mtd);
+ fd = mtd_check_open(mtd, true);
if (ioctl(fd, MEMGETINFO, &mtd_info) < 0) {
DLOG_ERR("Unable to obtain mtd_info for given partition name.");
int mtdtype = 0;
uint32_t opt_trxmagic = TRX_MAGIC;
-int mtd_open(const char *mtd, bool block)
+int mtd_open(const char *mtd, bool block, bool write_mode)
{
FILE *fp;
char dev[PATH_MAX];
int i;
int ret;
- int flags = O_RDWR | O_SYNC;
+ int flags = O_RDONLY;
char name[PATH_MAX];
+ if(write_mode) {
+ flags = O_RDWR | O_SYNC;
+ }
+
snprintf(name, sizeof(name), "\"%s\"", mtd);
if ((fp = fopen("/proc/mtd", "r"))) {
while (fgets(dev, sizeof(dev), fp)) {
return open(mtd, flags);
}
-int mtd_check_open(const char *mtd)
+int mtd_check_open(const char *mtd, bool write_mode)
{
struct mtd_info_user mtdInfo;
int fd;
- fd = mtd_open(mtd, false);
+ fd = mtd_open(mtd, false, write_mode);
if(fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
return -1;
next++;
}
- fd = mtd_check_open(mtd);
+ fd = mtd_check_open(mtd, true);
if (fd < 0)
return 0;
next++;
}
- fd = mtd_check_open(mtd);
+ fd = mtd_check_open(mtd, true);
if(fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
exit(1);
if (quiet < 2)
fprintf(stderr, "Erasing %s ...\n", mtd);
- fd = mtd_check_open(mtd);
+ fd = mtd_check_open(mtd, true);
if(fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
exit(1);
if (quiet < 2)
fprintf(stderr, "Dumping %s ...\n", mtd);
- fd = mtd_check_open(mtd);
+ fd = mtd_check_open(mtd, false);
if(fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
return -1;
return -1;
}
- fd = mtd_check_open(mtd);
+ fd = mtd_check_open(mtd, false);
if(fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
return -1;
next++;
}
- fd = mtd_check_open(mtd);
+ fd = mtd_check_open(mtd, true);
if(fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
exit(1);
extern int erasesize;
extern uint32_t opt_trxmagic;
-extern int mtd_open(const char *mtd, bool block);
-extern int mtd_check_open(const char *mtd);
+extern int mtd_open(const char *mtd, bool block, bool write_mode);
+extern int mtd_check_open(const char *mtd, bool write_mode);
extern int mtd_block_is_bad(int fd, int offset);
extern int mtd_erase_block(int fd, int offset);
extern int mtd_write_buffer(int fd, const char *buf, int offset, int length);
block_offset = offset & ~(erasesize - 1);
offset -= block_offset;
- fd = mtd_check_open(mtd);
+ fd = mtd_check_open(mtd, true);
if(fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
exit(1);
return -1;
}
- fd = mtd_check_open(mtd);
+ fd = mtd_check_open(mtd, true);
if (fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
ret = -1;
goto err;
}
- bfd = mtd_open(name, true);
+ bfd = mtd_open(name, true, true);
ptr = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, bfd, 0);
if (!ptr || (ptr == (void *) -1)) {
perror("mmap");
}
/* check if image fits to mtd device */
- fd = mtd_check_open(mtd);
+ fd = mtd_check_open(mtd, true);
if(fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
exit(1);
if (quiet < 2)
fprintf(stderr, "Trying to fix trx header in %s at 0x%zx...\n", mtd, offset);
- fd = mtd_check_open(mtd);
+ fd = mtd_check_open(mtd, true);
if(fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
exit(1);
block_offset = offset & ~(erasesize - 1);
offset -= block_offset;
- fd = mtd_check_open(mtd);
+ fd = mtd_check_open(mtd, true);
if(fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
exit(1);
block_offset = offset & ~(erasesize - 1);
offset -= block_offset;
- fd = mtd_check_open(mtd);
+ fd = mtd_check_open(mtd, true);
if(fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
exit(1);