aboutsummaryrefslogtreecommitdiffstats
path: root/bmlutils
diff options
context:
space:
mode:
authorKoushik Dutta <koushd@gmail.com>2010-12-12 12:24:02 -0800
committerKoushik Dutta <koushd@gmail.com>2010-12-12 12:24:02 -0800
commit03a4f5ba0d42d1fdae90eaf70039d905318dd208 (patch)
tree36d4d8d93839e5a2ab06cef2e96dafc417d59dc0 /bmlutils
parentcd8af06d645334634dd7c9af15e6545184b4d82f (diff)
downloadbootable_recovery-03a4f5ba0d42d1fdae90eaf70039d905318dd208.zip
bootable_recovery-03a4f5ba0d42d1fdae90eaf70039d905318dd208.tar.gz
bootable_recovery-03a4f5ba0d42d1fdae90eaf70039d905318dd208.tar.bz2
supprot backup and restore of samsung kernels
Change-Id: I6deb5918f97ca5c5466b1d78369454b3452b89c0
Diffstat (limited to 'bmlutils')
-rw-r--r--bmlutils/bmlutils.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/bmlutils/bmlutils.c b/bmlutils/bmlutils.c
index 5ac08b7..6062ac9 100644
--- a/bmlutils/bmlutils.c
+++ b/bmlutils/bmlutils.c
@@ -25,13 +25,37 @@ extern int __system(const char *command);
int cmd_bml_restore_raw_partition(const char *partition, const char *filename)
{
- printf("bml restore\n");
- int fd = open("/dev/block/bml7", O_RDWR | O_LARGEFILE);
- ioctl(fd, BML_UNLOCK_ALL, 0);
-
- char tmp[PATH_MAX];
- sprintf("dd if=%s of=/dev/block/bml7 bs=4096", filename);
- return __system(tmp);
+ char *bml;
+ if (strcmp(partition, "boot") == 0 || strcmp(partition, "recovery") == 0)
+ bml = "/dev/block/bml7";
+ else
+ return 6;
+
+ char buf[4096];
+ int dstfd, srcfd, bytes_read, bytes_written, total_read = 0;
+ if (filename == NULL)
+ srcfd = 0;
+ else {
+ srcfd = open(filename, O_RDONLY | O_LARGEFILE);
+ if (srcfd < 0)
+ return 2;
+ }
+ dstfd = open(bml, O_RDWR | O_LARGEFILE);
+ if (dstfd < 0)
+ return 3;
+ if (ioctl(dstfd, BML_UNLOCK_ALL, 0))
+ return 4;
+ do {
+ total_read += bytes_read = read(srcfd, buf, 4096);
+ if (!bytes_read)
+ break;
+ if (bytes_read < 4096)
+ memset(&buf[bytes_read], 0, 4096 - bytes_read);
+ if (write(dstfd, buf, 4096) < 4096)
+ return 5;
+ } while(bytes_read == 4096);
+
+ return 0;
}
int cmd_bml_backup_raw_partition(const char *partition, const char *filename)